cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0 UART HAL driver issue

jon239955_stm1_st
Associate II
Posted on November 11, 2015 at 22:11

Hi,

I have spotted a potential bug in the HAL driver for the UART on (at least) the STM32L0. The macro for determining the BRR register value__DIV_LPUART is defined as follows:

#define __DIV_LPUART(_PCLK_, _BAUD_) (((_PCLK_)*256)/((_BAUD_)))

Any value passed to this macro for the _PCLK_ token over 16MHz will result in overflow as it is multiplied by 256 before being divided by the required _BAUD_. I noticed this as I tried to use the HAL driver to set my PCLK driven UART (32MHz) to 9600 and saw it come out as 19 Has this been raised before? Note: this is with the latest IAR compiler for ARM (7.1) #hal #uart #cubemx #stm32l0
1 REPLY 1
Amel NASRI
ST Employee
Posted on November 12, 2015 at 10:00

Hijon.gordon,

Please use the last STM32CubeL0 version (1.3.0). This bug is already fixed there:

#define __DIV_LPUART(_PCLK_, _BAUD_) ((uint32_t) (((((uint64_t)_PCLK_)*0))/(((uint64_t)_BAUD_))))

-Mayla-

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.