2026-01-17 4:27 AM
Attempting to blink an LED using output compare function of a timer, but I've not been able to get signal or toggling to happen on the pin.
I'm using TIM5 channel 3, because I'm planning on using SPI1 eventually (I need to use a clock source separate from SPI1, which is on APB2) and the TIM5 associated alternate function GPIO on PA2 is in a convenient location.
Meter on the pin indicates a floating pin signal (not going high or low), and LED visually indicates same (no dim light or other visual indication of rapid toggling).
The pin itself is fine as normal GPIO: setting same pin as GPIO (not alternate function for TIM5), I'm able to blink "manually" via software. It seems to just be using that pin as TIM5 that causes problems.
Here's the CubeMX setup:
My understanding from the datasheet is that TIM5 is on APB1:
APB1 timer clocks set to 10.5MHz:
...so TIM_CLK/CKD/((PSC + 1)*(ARR + 1))
= 10500000 / 4 / ((43749 + 1) * (59 + 1))
= 1 Hz (should be blinking once per second)
Solved! Go to Solution.
2026-01-17 6:12 AM
Have you put the magic call
HAL_TIM_PWM_Start()
in your code?
Also, if APB clock divider is > 1, TIMCLK is 2 x APBCLK.
2026-01-17 4:37 AM
...one more detail, the device errata sheet doesn't list anything for this, unless I'm missing something.
2026-01-17 6:12 AM
Have you put the magic call
HAL_TIM_PWM_Start()
in your code?
Also, if APB clock divider is > 1, TIMCLK is 2 x APBCLK.
2026-01-17 6:13 AM
Did you start the timer using HAL_TIM_PWM_Start or similar? Show your user code.
2026-01-17 10:18 AM
Ah that must be it. No I am missing the magic call.
I guess I assumed the auto-generated code would be doing that during the various init() boilerplate that's injected.
2026-01-17 1:05 PM
For future info, in this case the code needed was:
HAL_TIM_OC_Start(&htim5, TIM_CHANNEL_3);