cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, For the controller stm32G071RB, formula for "Timer clock frequency = (Microcontroller frequency / (prescalar Value+1))" is available in datasheet. I need similar type of formula (Timer clock frequency) for stm32F030CC controller.

Umar
Associate II
 
3 REPLIES 3
MM..1
Chief II

Same

TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
Nikita91
Lead II

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.