cancel
Showing results for 
Search instead for 
Did you mean: 

Getting bus speed of timer

sincoon
Associate II
Posted on November 24, 2015 at 21:09

I work in CubeMX. I want to trigger my timer interrupt (period elapsed) on some speed. To fill up proper prescaler and period I need to know bus speed, on which this timer is. Is there quick way to get it, without datasheet on controller?

#timer #use-the-source-luke
3 REPLIES 3
Posted on November 25, 2015 at 00:47

Well you could just define a constant if that's easier and more convenient?

Pay attention to how you're configuring the PLL and APB/AHB dividers. Read the Code instead of the Manual.

Use SystemCoreClock variable.

In the SPL there's a GetClocks type function that pulls the current settings out of the chip, and computes the speed. The TIMCLK is typically 2x faster than the APB to which it is attached, except in the DIV1 case, and this is achieved by pulling the clock out of the divider chain one stage earlier (ie it's not actually multiplying). You could do this by indexing into an array like array[] = { 1, 1, 2, 4, 8, ... }; and using TIMCLK = APBxCLK / array[index-1];

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
sincoon
Associate II
Posted on December 04, 2015 at 18:27

Actually, my question is about ''how to know'' or ''where to find'' (including, in code) information about bus frequency of specific timer. As I understood, it could be on AHB/APB bus - how to know, on what bus is my timer, if I had only source code? And what frequency have this bus(or, at least, prescalers of them). Maybe there are some standard macros to get them(because, I think, problem is standard and must be some standard way to achieve frequency of timer tick. Maybe I'm wrong of course:)

Posted on December 04, 2015 at 22:48

It's going to depend on the APB that the TIM resides on, typically TIM1 and TIM8 are on APB2, the faster bus, and the 32-bit ones typically on the APB1

You'd look at the clock tree in the reference manual for the specific STM32 family you are using, and the enable bits in the APBxENR registers therein.

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