2022-02-04 09:42 AM
2022-02-04 10:54 AM
Same
2022-02-04 05:48 PM
It depends on the bus it's on. It's certainly outlined in the timer section of the reference manual. CubeMX clock tree gives a nice visualization.
It's more complicated than just "(Microcontroller frequency / (prescalar Value+1))" even on the G0. I don't see the statement you're referencing in the datasheet.
2022-02-05 02:24 AM
I wrote this:
//----------------------------------------------------------------------
// Some utility functions to get clocks frequencies
uint32_t rccGetSystemClockFreq (void)
{
// SYSTEM clock frequency
return SystemCoreClock ;
}
uint32_t rccGetHCLKClockFreq (void)
{
// HCLK clock frequency
return __LL_RCC_CALC_HCLK_FREQ (SystemCoreClock, LL_RCC_GetAHBPrescaler());
}
uint32_t rccGetPCLK1ClockFreq (void)
{
// PCLK1 clock frequency
return __LL_RCC_CALC_PCLK1_FREQ (rccGetHCLKClockFreq (), LL_RCC_GetAPB1Prescaler());
}
#if defined __LL_RCC_CALC_PCLK2_FREQ
uint32_t rccGetPCLK2ClockFreq (void)
{
// PCLK2 clock frequency
return __LL_RCC_CALC_PCLK2_FREQ (rccGetHCLKClockFreq (), LL_RCC_GetAPB2Prescaler());
}
#endif
//----------------------------------------------------------------------
// Get TIMER and LPTIMER clock frequency
// Timer clock depends on APB bus prescaler value
// Timer clock may be APBx peripherals frequency x2
uint32_t rccGetTimerClockFrequency (void * deviceAddress)
{
uint32_t prescaler ;
uint32_t timClock ;
(void) deviceAddress ; // Some MCUs have all timers on PCLK1
#if (defined LPTIM1)
if (deviceAddress == LPTIM1)
{
timClock = LL_RCC_GetLPTIMClockFreq (LL_RCC_LPTIM1_CLKSOURCE) ;
}
else
#endif
#if (defined LPTIM2)
if (deviceAddress == LPTIM2)
{
timClock = LL_RCC_GetLPTIMClockFreq (LL_RCC_LPTIM2_CLKSOURCE) ;
}
else
#endif
#if (defined RCC_CCIPR_TIM1SEL)
if (deviceAddress == TIM1)
{
timClock = LL_RCC_GetTIMClockFreq (LL_RCC_TIM1_CLKSOURCE) ;
}
else
#endif
#if (defined RCC_CCIPR_TIM15SEL)
if (deviceAddress == TIM15)
{
timClock = LL_RCC_GetTIMClockFreq (LL_RCC_TIM15_CLKSOURCE) ;
}
else
#endif
{
// All other timers are on PCLK1
timClock = rccGetPCLK1ClockFreq () ; // timClock is PCLK1
prescaler = LL_RCC_GetAPB1Prescaler () ;
if (prescaler != 0u)
{
timClock *= 2u ;
}
}
AA_ASSERT (timClock != 0u) ; // Clock source not started
return timClock ;
}
Now you can apply the formula:
rccGetTimerClockFrequency(TIMx) / (prescalar Value+1))
If you don't want to use LL, study the LL code to know how to compute the timer frequency and write your own code.