Skip to main content
Aman Kumar
Associate
March 7, 2018
Question

STM32L0xx UART overrun error

  • March 7, 2018
  • 4 replies
  • 3418 views
Posted on March 07, 2018 at 13:04

We are using the STM32L0 HAL implementation of the UART driver. The UART (115200,8-N-1) is used in interrupt mode and we have configured the interrupt to occur for every character. This is done so that we can implement a CLI at the application level. The target controller is STM32L071KB (32 MHz). 

The issue is that we run into a UART overrun error if the CLI is used by an automated test script such as TeraTerms TTL running at the set baud rate i.e. 115200. The only way to get it to work properly is by adding a 10 ms inter-character delay on the sender side.

We confirmed the error by looking at the UART ISR register where the ORE bit gets set. 

We have tried different baud rates , Oscillator clock frequencies as well but to no avail.

Interestingly running the same code on an STM32F4xx (180 MHz) series controller has no issues at all.

We have patched the HAL_UART_IRQ_Handler() routine with the latest updates from STM32 HAL V1.10.0. The HAL driver package we are using is V1.8.1. The implementation of the interrupt based driver in our software  is as per the reference application :UART_TwoBoards_ComIT

#uart-overrun-error #uart-interrupt #stm32l0xx #ore-bit
This topic has been closed for replies.

4 replies

AvaTar
Senior III
March 7, 2018
Posted on March 07, 2018 at 13:54

How long is the runtime of your interrupt routine ?   (Rhetorical question)

If it takes longer then the inter-character time, you will never get happy.

Beating it with brute force (faster MCU with higher core clock) is the second-best solution, better rework the code that runs in the interrupt context.

Tesla DeLorean
Guru
March 7, 2018
Posted on March 07, 2018 at 14:10

Sounds like you'll need to code a better interrupt/buffering scheme.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Pavel A.
March 7, 2018
Posted on March 07, 2018 at 14:18

We are using the STM32L0 HAL implementation of the UART driver.

The HAL drivers for UARTs has been discussed here recently. A short answer... drop the HAL and use the LL API instead - yes, with RX interrupt for every char. In this way, the code is flexible and easy to understand (at least not more cryptic than the HAL).

HAL library can be considered for very high rates ( > 115200)  and large amount of data, which is not your case.

We have converted UARTs from HAL to LL in our projects and are happy. Can share the recipe.

Regards,

-- pa

Aman Kumar
Associate
March 7, 2018
Posted on March 07, 2018 at 14:25

Yes we had a doubt on our ISR implementation as well so we tried doing the same test with the reference application mentioned above. We made it enter the 'Receiver' where it waits in a while(1) loop to receive a character and then print a character on UART. The ISR for such an application is very simple as shown below:

/**

* @brief Tx Transfer completed callback

* @param UartHandle: UART handle.

* @note This example shows a simple way to report end of IT Tx transfer, and

* you can add your own implementation.

* @retval None

*/

void HAL_UART_TxCpltCallback(UART_HandleTypeDef *UartHandle)

{

/* Set transmission flag: trasfer complete*/

UartReady = SET;

}

/**

* @brief Rx Transfer completed callback

* @param UartHandle: UART handle

* @note This example shows a simple way to report end of IT Rx transfer, and

* you can add your own implementation.

* @retval None

*/

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *UartHandle)

{

/* Set transmission flag: trasfer complete*/

UartReady = SET;

}

Even in this application we are able to create the ORE error at 115200 baud.

AvaTar
Senior III
March 7, 2018
Posted on March 07, 2018 at 14:52

Interrupts can be preempted by other interrupts with higher priority.

I would suggest the following:

Toggle one GPIO on UART interrupt entry and exit, and another GPIO when the ORE flag is set.

View both GPIOs, together with the UART RX line, with a scope.

Set the scope trigger on the ORE flag toggle.

You might add a visualization of other events in your system with additional GPIOs.