Skip to main content
Visitor II
January 15, 2025
Solved

HAL_RCC_GetPCLK2Freq() in HAL_InitTick delivers half the frequency

  • January 15, 2025
  • 4 replies
  • 1075 views

Dear all, 

I just came across something strange. 

I debugged into the function HAL_InitTick() to better understand how the OS tick (SysTick) is managed if FreeRTOS is used. I'm using TIM16 for the SysTick of the OS. At the beginning of HAL_InitTick() the function HAL_RCC_GetPCLK2Freq() is called. The return value is used to set the systick timer (in my case TIM16 on a STM32L432 device). 

My clock configuration for my device is set for PCLK2 = 80MHz. However, the function HAL_RCC_GetPCLK2Freq() returns 40.000.000. So half of the actual frequency. In the following the prescaler is set to 3 and the period to 999. So for my understanding the timer period until it will reset to 0 and raise an interrupt will be ((40.000.000/3)*1000) *(1/40.000.000). So this gives me a totally wrong value that certainly is not the case (I'm actually sure for other reasons that my device runs at 80MHz instead of 40MHz). Here is how it looks like just before entering HAL_TIM_Base_Init().

mkrug_0-1736963263542.png

Any idea bout my misunderstanding?

Best Regards
Markus

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

    Sorry for being late in answering. 
    This is the screenshot of my clock configuration. In my understanding all timers should run at 80MHz. And guess what - I just did an additional test it magically works. So it seems that I did something wrong the other day.

    thanks for all your support and suggestions
    Markus

    mkrug_0-1738768993674.png

     

     

    4 replies

    Graduate
    January 15, 2025

    Is your SystemCoreClock value correct?

    Do you call SystemCoreClockUpdate() after changing clock dividers?

    mkrugAuthor
    Visitor II
    January 18, 2025

    Hi Chris, 

    thanks for you reply.

    Well, I work 100% with the STM32CubeIDE generated software for this part of my application and not changing anything in the HAL manually. So I guess the SystemCoreClock value is correct. I will try to double check that later.

    Best Regards

    Markus

    Graduate
    January 18, 2025

    If PCLK is obtained by dividing HCLK, then timer clock frequency is 2xPCLK - it's written in the RefMan.

    Technical Moderator
    January 21, 2025

    Hello @mkrug 

    Could please share with us your system clock config?

    mkrugAuthorAnswer
    Visitor II
    February 5, 2025

    Sorry for being late in answering. 
    This is the screenshot of my clock configuration. In my understanding all timers should run at 80MHz. And guess what - I just did an additional test it magically works. So it seems that I did something wrong the other day.

    thanks for all your support and suggestions
    Markus

    mkrug_0-1738768993674.png