# SMT32 HAL UART crash on possible overrun

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.

• 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. May 24, 2018 at 10:44
• @smajli but STM32 UART has "oversampling mode". May 24, 2018 at 15:48
• The ErrorCode eraser should look like this: huart->ErrorCode &= ~HAL_UART_ERROR_ORE; Feb 23, 2021 at 22:47

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) )
{
__HAL_UART_CLEAR_IT(huart, UART_CLEAR_OREF);
huart->ErrorCode |= HAL_UART_ERROR_ORE;
return;
}


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