cancel
Showing results for 
Search instead for 
Did you mean: 

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

jellemeijer
Associate

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.

1 ACCEPTED SOLUTION

Accepted Solutions
SofLit
ST Employee

Hello @jellemeijer and welcome to the community,

Please check this thread.

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.

View solution in original post

2 REPLIES 2
SofLit
ST Employee

Hello @jellemeijer and welcome to the community,

Please check this thread.

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.
SofLit
ST Employee

@jellemeijer 

FYI: the issue has been already fixed with the patch 1.12.1

+

https://github.com/STMicroelectronics/STM32CubeH7/issues/301

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.