Skip to main content
PKM
Associate
July 29, 2020
Question

MCU STM32L562: With initialising the UART using HAL_UART_Init() the UART-communication is not working. Calculating the BRR like shown in the reference manual gives a working BRR-Value. Is the HAL_UART_Init() not intended for setting the BRR ?

  • July 29, 2020
  • 5 replies
  • 1606 views

The Project was migrated from STM32L4 to STM32L5. The Baudrate setting with HAL_UART_Init() works fine with L4 MCU. With L5 MCU it returns with an HAL_UART_ERROR_NONE too.

    This topic has been closed for replies.

    5 replies

    Tesla DeLorean
    Guru
    July 29, 2020

    It should set BRR based on the current clocking options. Here it would typically unpack the RCC and PLL settings for clocks and buses.

    You could debug or validate it is checking all the right bit​s, and using the right values.

    The define for HSE_VALUE can be particularly problematic if wrong.

    New STM32 also have more complex peripheral clock sourcing options, check those are being unpacked properly. Library source is available and can be inspected.​

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    TDK
    Super User
    July 29, 2020

    HAL_UART_ERROR_NONE = 0 = HAL_OK.

    This indicates there is no error.

    What issue are you running into? HAL_UART_Init does indeed calculate BRR based on your current clock settings.

    "If you feel a post has answered your question, please click ""Accept as Solution""."
    PKM
    PKMAuthor
    Associate
    July 29, 2020

    Thanks for the quick and good comments,

    @TDK

    The issue is that the UART just did not recognize the incomming Data with a BRR setting of 0x42 (Set by HAL_UART_Init() Call)

    Using the Formulaes I got a BRR=0x73 and the UART recognizes incoming Data correct. In this case the BRR ist overwritten after

    call of HAL_UART_Init().

    @Community member​ 

    HSE_VALUE seems to be the problem. I found a wrong define for this. The problem is not solved yet, but I think I'm on good way.

    I was not aware that the calculations could depend on a user define.

    Best regards

    PKM

    Tesla DeLorean
    Guru
    July 29, 2020

    Well it is how the software knows what external hardware you've added, it doesn't know if you built a system with an 8 MHz clock or a 24 MHz one. It knows what the HSI / MSI are.

    Typically in stm32l5xx_hal_conf.h

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    S.Ma
    Principal
    July 29, 2020

    If the HAL function would get as passing parameter the incoming USART clock frequency in Hz would make backtracking simpler.

    PKM
    PKMAuthor
    Associate
    July 30, 2020

    Hi,

    Problem is solved.

    The wrong Definition of the "HSE_VALU"E was as mentionend by clive1  in "stm32l5xx_hal_conf.h", but the file "system_stm32l5xx.c" had to be changed in the same way.

    Thanks very much.

    Tesla DeLorean
    Guru
    July 30, 2020

    PLL settings would need to reflect board/design

    HSE_VALUE you be used here too, but the math/best-fit is more difficult due to the limited options and integers

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..