cancel
Showing results for 
Search instead for 
Did you mean: 

How to get peripheral clock programmatically?

GregB
Associate II

Hello,

I have a generic function for the timer configuration. The time base address is an input parameter to this function. I'm looking for a way to get the timer clock so that I can set the timer prescaler. How can I do that with HAL?

I guess I need to get first the peripheral (APB1, APB2, ..) on which my timer is connected ? But how?

Thank you for your help,

Greg

3 REPLIES 3

Usually helper routines in the HAL RCC sources (see UART baud for example)

Not sure there is a method to determine which peripheral bus is being used, but the base address/range of the APB is containable, and comparable against the specific TIM instance.

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

Look at the memory map of the device. Each bus has an address range. If HAL would be high level library, it would have a function, which returns bus frequency from peripheral's address. But you can't expect that from ST's team of brainless code monkeys...

S.Ma
Principal

This would be a natural need to be served in an API yielding the clock frequency in Hz (with 32 bit, shouldn't be so hard?)

The clock frequency depends on which clock source and prescalers are selected through the clock tree.

Probably when MX enable you to choose your PWM frequency in Hz and number of duty cycles the timer frequency will be closer to the real world more than a PDF spec.