2017-09-18 07:07 AM
I see that this has been asked a few times with no real resolution or workaround, so I'll ask again please?
I have USART3 configured at 9600 Baud. I test this with a terminal program also set at 9600 and it works fine.
I then execute the following 2 line to try and change the baud rate on the fly
MX_USART3_UART_DeInit();
MX_USART3_UART_Init_Custom(19200);and then set my terminal program to 19200 baud but uart on processor just stops receiving....
MX_USART3_UART_Init_Custom is a copy the standard MX_USART3_UART
function with a configurable baud rate:-
void MX_USART3_UART_Init_Custom(unsigned int baud)
{huart3.Instance = USART3;
huart3.Init.BaudRate = baud; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; huart3.Init.Parity = UART_PARITY_NONE; huart3.Init.Mode = UART_MODE_TX_RX; huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE; huart3.Init.OverSampling = UART_OVERSAMPLING_16; huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE; huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT; if (HAL_UART_Init(&huart3) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); }}Any ideas?
2017-09-18 07:47 AM
>>I see that this has been asked a few times with no real resolution or workaround, so I'll ask again please?
But what is the actual issue? Do the functions report an error, does the USART have some pending status? Provide some analysis.
Does the USART have a framing error you need to clear? Does it transition baud rate mid-transmission?
You can use the HAL, or frankly just disable the USART, change the BRR and re-enable.
There isn't some inherent flaw in the USART or software, got several parts here where I negotiate to higher baud rates.
2017-09-18 10:08 AM
The issue is that nothing else get received. Software just carired on running (no had faults)
I added the following
MX_USART3_UART_DeInit();
MX_USART3_UART_Init_Custom(19200);if( HAL_UART_GetError(&huart3) )
{ // __HAL_UART_CLEAR_FLAG diag_log( _EV_VERBOSE, DIAG_FMT( 'Error' )); // stuck a break point here too }and stuck a break point on diag_log line for good measure. errors reported back, 0.
what pending status do you refer to?
2017-09-18 10:21 AM
>>what pending status do you refer to?
USART3->SR
USART3->ISR
Depends on the specific STM32 we're talking about, but start with those, and a review of the relevant RM
2017-09-18 10:32 AM
Sorry, yeah, Processor is STM32F779. Will keep digging..
2017-09-19 05:04 AM
ok, not sure why, but its now working with no changes, so this is what I have :-
MX_USART3_UART_DeInit();
MX_USART3_UART_Init_Custom(19200);MX_USART3_UART_Init_Custom
is a copy the standard MX_USART3_UART function with a configurable baud rate:-
void
MX_USART3_UART_Init_Custom(unsigned int baud){huart3.Instance = USART3;
huart3.Init.BaudRate = baud;huart3.Init.WordLength = UART_WORDLENGTH_8B;huart3.Init.StopBits = UART_STOPBITS_1;huart3.Init.Parity = UART_PARITY_NONE;huart3.Init.Mode = UART_MODE_TX_RX;huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;huart3.Init.OverSampling = UART_OVERSAMPLING_16;huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;if (HAL_UART_Init(&huart3) != HAL_OK){_Error_Handler(__FILE__, __LINE__);}}?????
2018-09-02 07:21 PM
Try this might be easier
MX_USART3_UART_Init
if(cond)
{Cubesets}
else
{custom}
Or
Switch
if (HAL_UART_Init(huarthandle) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
Main
MX_USARThadle_UART_Init();
Your code....
cond=false;// this moves into the else statement as defacto
MX_USARThadle_UART_deInit();
MX_USARThadle_UART_Init(); // custom baud should work.
Might be cleaner and less issues as u keeping the standard cude init function and will make things easier moving forward on the fly.
2018-09-02 07:28 PM
i tried this once by trying creating a new handle with the same setting. DeInit the cube settings and then tried to used my own handle Init wouldn't work. I think the method you have and the one I am suggesting might be the only way( if I remember the stm32 autobaud function gets trigged by a conditional statement aswell( something to do with the receive start byte).
Please feel free to correct me if I am wrong.
2023-03-10 12:52 AM
i need to increase the speed of the uart for a Bluetooth-UART module, first 115200bauds for AT commands and then 1Mbps for data mode.
In my head the code would be like this, but reading your comments i realiced it might not work
void changeUARTbaudrate(){
HAL_UART_DeInit(&huart4);
huart4.Init.BaudRate = 1000000;
HAL_UART_Init(&huart4);
}