Skip to main content
Explorer
January 2, 2025
Solved

STM32H7 HAL: possible bug in HAL_RCC_GetPCLK1Freq()? Incorrect UART baudrate generation

  • January 2, 2025
  • 3 replies
  • 1542 views

Software Versions

  • CubeMX 6.13.0 (used H7 MCU package v1.12.0)

Issue:

Hello everyone, we are encountering an issue that might be related to the HAL (although we think this is unlikely as it is a rather fundamental function of the HAL).

We're developing software on a STM32H753BIT6 MCU on a custom PCB. We're making use of CubeMX and the STM32H7 HAL (provided by CubeMX). Currently we are measuring the baud rate of the UART4 that we are using to be half of the expected baud rate (115200). Upon code inspection is found that the uart prescaler is incorrectly calculated. It assumes a peripheral clock speed of 240MHz instead of the configured 120Mhz.

See our CubeMX clock configuration:

jellemeijer_0-1735814103480.png

When inspecting the HAL implementation of the uart we see that the baud rate prescaler is calculated using the HAL_RCC_GetPCLK1Freq() function. You would expect the function to return 120000000, but instead it return 240000000.

We've narrowed the issue down to the way that the PCLK1 frequency is calculated in the STM32Cube HAL.

 return (HAL_RCC_GetHCLKFreq() >> ((D1CorePrescTable[(RCC->D2CFGR & RCC_D2CFGR_D2PPRE1) >> RCC_D2CFGR_D2PPRE1_Pos]) & 0x1FU));

 HAL_RCC_GetHCLKFreq correctly return 240MHz and the D2PPRE1 is correctly read as 0x04, which corresponds to a division of 2. Which is in line with our CubeMX configuration. However the D1CorePrescTable returns 0 instead of a shift 1. Are we linking against the wrong CMSIS file.

Since this is such a fundamental function we are surprised that we are running into such a low-level issue.

    This topic has been closed for replies.
    Best answer by mƎALLEm

    Hello @jellemeijer and welcome to the community,

    Please check this thread.

    3 replies

    mƎALLEmAnswer
    Technical Moderator
    January 2, 2025

    Hello @jellemeijer and welcome to the community,

    Please check this thread.

    Technical Moderator
    January 2, 2025
    Visitor II
    February 10, 2025

    hello, Jellemeijer, have you solved it? the same problem came to me. 

    Visitor II
    February 10, 2025

    I have found the solution, thanks.