Function to return value of APB1 & APB2 timer clocks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-30 3:48 PM
Is there a way to retrieve the value APBx timer clocks are set to?
I have found functions to get the PCLK1 and PCLK2 frequencies but there is a multiplier that can change the final timer clock so that is not reliable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-30 4:42 PM
You'd need to look at the source for HAL_RCC_GetPCLK1() and read the RCC registers to determine if you are the DIV1 case, or not. In the other cases the TIMCLK is 2X
uint32_t PCLK1TIM(void) // F4 Example
{
/* Get PCLK1 frequency */
uint32 pclk1 = HAL_RCC_GetPCLK1Freq();
/* Get PCLK1 prescaler */
if((RCC->CFGR & RCC_CFGR_PPRE1) == 0)
{
/* PCLK1 prescaler equal to 1 => TIMCLK = PCLK1 */
return (pclk1);
}
else
{
/* PCLK1 prescaler different from 1 => TIMCLK = 2 * PCLK1 */
return(2 * pclk1);
}
}
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-09-30 5:33 PM
Very odd there is not a function for this, seems like it would be wanted since you need that value to calculate the period and prescaler for timer functions.
Thanks Clive.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2018-10-01 6:28 AM
People often use constants because they set up the frequency plan to being with.
Although given the proliferation of STM32 parts, and now some using other clock sources, it might be a good idea to have a function, haven't dug into the API or macros that deeply recently.
Up vote any posts that you find helpful, it shows what's working..
