HAL_RCC_GetPCLK2Freq() in HAL_InitTick delivers half the frequency
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-15 9:50 AM - last edited on ‎2025-01-15 9:55 AM by Andrew Neil
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().
Any idea bout my misunderstanding?
Best Regards
Markus
Solved! Go to Solution.
- Labels:
-
STM32CubeIDE
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-05 7:26 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-15 1:44 PM
Is your SystemCoreClock value correct?
Do you call SystemCoreClockUpdate() after changing clock dividers?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-17 11:40 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-18 12:03 AM
If PCLK is obtained by dividing HCLK, then timer clock frequency is 2xPCLK - it's written in the RefMan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-01-21 6:19 AM
Hello @mkrug
Could please share with us your system clock config?
Thanks
Omar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2025-02-05 7:26 AM
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
