LL_RCC_GetTIMClockFreq doesn't account for the APB Prescaler - is this correct?
I'm writing an application which uses a timer (TIM2 in this case) to track communication timeouts. So the timer period changes periodically, it might be an inter-byte gap timeout at one point and an inter-packet timeout the next.
I'm using LL_RCC_GetTIMClockFreq to get the timer frequency, a fixed prescaler, and a quick calculation to work out the timer count value to the timeout I want (or as near as I can get).
The CPU clock is about 66MHz, and I have an APB1 divider active (APB1 = HCLK / 2).
According to RM0316 (STM32F303 Reference Manual) Rev 8, page 133: "9.2.10 Timers (TIMx) clock" -- If the APB1 prescaler is not 1:1, the APB1 timer clock is twice the APB1 peripheral clock.
This means my APB1 timer clock should be 66MHz, but my APB1 Peripheral clock should be 33MHz.
When I run LL_RCC_GetTIMClockFreq() for TIM2, it returns a timer frequency of 33MHz, which doesn't account for the APB1 timer clock being doubled when a prescaler is in effect.
To get the expected timeouts I'm having to do this:
uint32_t TimerFrequency = 0;
TimerFrequency = LL_RCC_GetTIMClockFreq(LL_RCC_TIM2_CLKSOURCE);
if (LL_RCC_GetAPB1Prescaler() != LL_RCC_APB1_DIV_1) {
TimerFrequency *= 2;
}Is this expected behaviour?
