2018-01-19 04:38 AM
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?
2018-01-19 05:24 AM
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
2018-01-19 06:45 AM
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)?
2018-01-19 08:56 AM
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.
2023-10-27 04:18 AM
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;
}
}
2023-10-28 02:41 AM
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