Skip to main content
RGari
Associate II
June 20, 2020
Solved

Am I blind or did ST forget to write the function HAL_RCCEx_GetD2PCLK1Freq() into the STM32H7 HAL? They have them for the other PCLK frequencies but not this specific one. I could write my own, but I'd rather not reinvent the wheel unless necessary..

  • June 20, 2020
  • 3 replies
  • 1806 views

..

This topic has been closed for replies.
Best answer by TDK

Domain 2 has 2 different peripheral clock prescalers, D2PPRE1 (for APB1) and D2PPRE2 (for APB2). You can use HAL_RCC_GetPCLK1Freq and HAL_RCC_GetPCLK2Freq to get these. These are both domain 2 clocks.

I think they chose the naming scheme based on previous chip series where the clock scheme was not so complex. One could make a case for calling them HAL_RCCEx_GetD2PCLK1Freq/HAL_RCCEx_GetD2PCLK2Freq here, but it is what it is.

The "Clock Configuration" screen in CubeMX really helps me understand the clock scheme on the H7. Might help.

3 replies

TDK
TDKBest answer
June 20, 2020

Domain 2 has 2 different peripheral clock prescalers, D2PPRE1 (for APB1) and D2PPRE2 (for APB2). You can use HAL_RCC_GetPCLK1Freq and HAL_RCC_GetPCLK2Freq to get these. These are both domain 2 clocks.

I think they chose the naming scheme based on previous chip series where the clock scheme was not so complex. One could make a case for calling them HAL_RCCEx_GetD2PCLK1Freq/HAL_RCCEx_GetD2PCLK2Freq here, but it is what it is.

The "Clock Configuration" screen in CubeMX really helps me understand the clock scheme on the H7. Might help.

"If you feel a post has answered your question, please click ""Accept as Solution""."
RGari
RGariAuthor
Associate II
June 20, 2020

Thanks for the info! I've been working with the H7 for a while now, but the complexity of the clock tree still gets me sometimes! I was looking at it in CubeMX and found the 2 Prescalers (I'm looking for the I2C123 clock source in this case), but didn't notice the GetPCLKnFreq functions.

Piranha
Principal III
June 20, 2020

If HAL would be high-level library, then there would be...

uint32_t HAL_RCC_GetPeriphBusFreq(const void *pAddr);

...which knows peripheral address ranges for a specific MCU and returns it's respective bus frequency. The code is trivial and takes only few lines, but hey - to come up with this, ST would have to hire developers with a brain!

MBabu.1
Visitor II
December 2, 2021

You are not blind. The closest thing you can get is HAL_RCCEx_GetPeriphCLKFreq which is mostly bad implemented, but continues to improve for newer controllers. Here is an example of a good implementation for the STM32G4: https://github.com/STMicroelectronics/STM32CubeG4/blob/master/Drivers/STM32G4xx_HAL_Driver/Src/stm32g4xx_hal_rcc_ex.c#L650

Would be really nice if this level of detail is implemented for other controllers as well. Same holds for a high level API providing the clock speed of a certain timer instance which is a little rocket science to figure out (Different Peripheral Clocks for different timers, Timer Prescaler, TIMPRE, HCLK).