Skip to main content
whitehorsesoft
Associate III
January 17, 2026
Solved

TIM output compare driving LED on GPIO

  • January 17, 2026
  • 2 replies
  • 314 views

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:

whitehorsesoft_0-1768651511770.png

whitehorsesoft_1-1768651576913.png

whitehorsesoft_3-1768652538825.png

My understanding from the datasheet is that TIM5 is on APB1:

whitehorsesoft_4-1768652772848.png

APB1 timer clocks set to 10.5MHz:

whitehorsesoft_2-1768651691643.png

...so TIM_CLK/CKD/((PSC + 1)*(ARR + 1))

= 10500000 / 4 / ((43749 + 1) * (59 + 1))

= 1 Hz (should be blinking once per second)

Best answer by gbm

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.

2 replies

whitehorsesoft
Associate III
January 17, 2026

...one more detail, the device errata sheet doesn't list anything for this, unless I'm missing something.

gbm
gbmBest answer
Principal
January 17, 2026

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.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
whitehorsesoft
Associate III
January 17, 2026

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.

TDK
Super User
January 17, 2026

Did you start the timer using HAL_TIM_PWM_Start or similar? Show your user code.

"If you feel a post has answered your question, please click ""Accept as Solution""."