I increased my baud rate from 56000 to 115200 and my serial communication stops working when pinging continuously after 10-20 seconds. I am running at 16 MHz.

As far as I know HAL driver will handle overrun, among other errors by clearing the flag and calling the error callback function. If that is the case then if I get an overrun due to the increase in speed it should be cleared and my communication should continue working after that.

I have found also that increasing processor speed to 32 MHz "fixes" the issue but I don't want to rely on that. Perhaps it just takes much more time for the error to come.

Is my understanding correct? Are the UART flags cleared automatically by HAL drivers? Do I need to clear them myself or handle them in some manner? Is there something I am missing?

I basically use HAL_UART_Transmit_IT() and call HAL_UART_Receive_IT() after it finishes and do nothing else.

  • \$\begingroup\$ Check for error rate. In some processors 16MHz CLK frequency makes some of UART baud rate error too high, making communication impossible. In google try 'uart and baud error rate' phrase. \$\endgroup\$
    – smajli
    May 24, 2018 at 10:44
  • \$\begingroup\$ @smajli but STM32 UART has "oversampling mode". \$\endgroup\$
    – Long Pham
    May 24, 2018 at 15:48
  • \$\begingroup\$ The ErrorCode eraser should look like this: huart->ErrorCode &= ~HAL_UART_ERROR_ORE; \$\endgroup\$
    – Tobajer
    Feb 23, 2021 at 22:47

1 Answer 1


What happens is that I have the overrun error as my microcontroller cannot keep up with everything. There's a strange combination of overrun and RXNE that is not handled in HAL UART and will just make HAL_UART_IRQHandler() to get stuck being called all over.

I have found a link here explaining a bit.

Here's the code I added (slightly modified for STM32L0 series) under HAL_UART_IRQHandler() right before the /* If some errors occur */ comment:

  if( ((isrflags & USART_ISR_ORE) != RESET) && ((isrflags & USART_ISR_RXNE) == RESET) )
    huart->ErrorCode |= HAL_UART_ERROR_ORE;

And just be sure you modify the HAL_UART.c file you actually compile!


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.