2025-08-21 4:51 AM
I am currently experimenting with STM32F030RCTX and STM32F030CCTX devices.
My goal is to use RS485 with auto-baudrate detection, since I have modules that operate either at 115200 baud or 500k baud.
On STM32F030RCTX, I use USART1.
On STM32F030CCTX, I use USART3.
The UART init functions are identical, except for the instance selection.
Example init function:
void mcu_UART3_Init(void)
{
huart3.Instance = USART3;
huart3.Init.BaudRate = 115200;
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_AUTOBAUDRATE_INIT;
huart3.AdvancedInit.AutoBaudRateEnable = UART_ADVFEATURE_AUTOBAUDRATE_ENABLE;
huart3.AdvancedInit.AutoBaudRateMode = UART_ADVFEATURE_AUTOBAUDRATE_ON0X55FRAME;
if (HAL_RS485Ex_Init(&huart3, UART_DE_POLARITY_HIGH, 16, 16) != HAL_OK)
{
Error_Handler();
}
}
With STM32F030RCTX (USART1):
As soon as the device receives a 0x55 frame on any time, the auto-baudrate detection automatically starts. I don’t need to trigger anything manually (no explicit “autobaudrate request”).
With STM32F030CCTX (USART3):
I see different behavior. It does not automatically start the auto-baudrate detection in the same way on any time. It starts only beggining, but my first message is not 0x55, so auto baudrate detection is going off untill i activate again.
I have a module that must communicate with different products:
One product works at 115200 baud.
Another product works at 500k baud, and it is able to send the required 0x55 sync character.
Because of this:
I always start the UART at 115200.
If the connected product is the 115200 one → no issue.
If the connected product is the 500k one → it should send a 0x55 to let my MCU perform auto-baudrate and switch correctly.
The issue:
If the very first byte received is 0x55, then auto-baudrate works as expected.
But if the first byte is not 0x55, then I need a way to re-trigger auto-baudrate later.
On STM32F030RCTX, this seems to “just work”.
On STM32F030CCTX, it does not behave the same way.
// Frame Error
if((__HAL_UART_GET_IT(huart, UART_IT_FE) != RESET))
{
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_FEF);
if(huart->Instance == RS485_UART_MODULE)
{
if(++fe_streak > 4)
{
fe_streak = 0;
huart->Instance->CR2 &= ~(USART_CR2_ABREN);
huart->Instance->CR2 |= USART_CR2_ABREN;
}
}
}
else
{
fe_streak = 0;
}
One possible workaround is to re-trigger auto-baudrate when a Frame Error is detected.
However, this creates a new problem:
If the system is communicating with the 115200-baud product (which does not have the ability to send a 0x55 sync character), then any spurious frame error would cause the MCU to restart auto-baudrate detection. In this case the USART would be left waiting for a 0x55 that will never arrive, effectively blocking communication with the 115200-baud device.
Thanks :)
2025-08-21 7:48 AM
Hi @FSS1 ,
I can help answering the first question:
Is there any documented difference between USART1 (on STM32F030RCTX) and USART3 (on STM32F030CCTX) regarding auto-baudrate hardware behavior?
Based on the following table from the product reference manual RM0360, both USART1 and USART3 have the same features implementation:
-Amel
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.