cancel
Showing results for 
Search instead for 
Did you mean: 

How do I get the frequency of a timer in STM32F769I?

arnold_w
Senior
Posted on January 19, 2018 at 13:38

I am working with the STM32F7691I-EVAL board and I would like to determine the frequency of any given timer:

GET_TIMER_FREQ(TIMx)

The macro/function should be able to determine the frequency regardless of which clock the microcontroller is running from. Of course it is fully acceptable to do it 2 steps, first determine the clock source and then determine the resulting frequency for a particular timer. I have gone through the HAL-files, but I am unable to find such macros/functions. Can someone please help me?

5 REPLIES 5
Posted on January 19, 2018 at 14:24

The macro (or function) would need to know which APB a particular timer is on, and then check the divisor. I all except the DIV1 case the TIMCLK is source one divider tap earlier (ie *2)

printf('APB1=%d\n', HAL_RCC_GetPCLK1Freq());

printf('APB2=%d\n', HAL_RCC_GetPCLK2Freq());

Review code in these functions

For systems you know the configuration the computation for TIMxCLK can use SystemCoreClock

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on January 19, 2018 at 14:45

Where do I find out which timers are connected to which PCLKx? Is the same as STM32F4 (2: TIM1

TIM8

TIM9

TIM10

TIM11, and the rest are 1)?

Posted on January 19, 2018 at 16:56

There is a bus diagram in the Data Sheet, APBxENR registers in the Reference Manual, and the ♯ include should associate the APB1 and APB2 clock enables for the various timers.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
LVan .31
Associate III

The address of the timer determines which Bus it is on. I created below code which does the trick:

 

RCC_ClkInitTypeDef clkConfig;

uint32_t latency;

uint32_t clockHz;

 

::HAL_RCC_GetClockConfig(&clkConfig, &latency);

 

//= The address of the timer register determines which bus it is located on

if ((uint32_t)peripheralReg >= APB2PERIPH_BASE)

{

clockHz = ::HAL_RCC_GetPCLK2Freq();

 

if (clkConfig.APB2CLKDivider != RCC_HCLK_DIV1)

{

clockHz *= 2;

}

}

else if ((uint32_t)peripheralReg >= APB1PERIPH_BASE)

{

clockHz = ::HAL_RCC_GetPCLK1Freq();

 

if (clkConfig.APB1CLKDivider != RCC_HCLK_DIV1)

{

clockHz *= 2;

}

}

LVan .31
Associate III

Additional to my previous post. What I forget to mention is that (uint32_t)peripheralReg is part of my extensive C++ library built on top of the HAL layer.

This code is a reference to the Timer instance (TIM_TypeDef* Instance) in TIM_HandleTypeDef