Skip to main content
jon239955_stm1_st
Associate II
November 11, 2015
Question

STM32L0 UART HAL driver issue

  • November 11, 2015
  • 1 reply
  • 716 views
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
This topic has been closed for replies.

1 reply

Amel NASRI
Technical Moderator
November 12, 2015
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.