2020-07-03 05:44 AM
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
2020-07-03 05:53 AM
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.
2020-07-04 02:51 PM
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...
2020-07-04 10:47 PM
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.