Trouble Generating PWM Signal on STM32 NUCLEO-F207ZG Using Low-Level Register Programming
I'm programming an STM32 NUCLEO-F207ZG board and trying to output a PWM signal on pin PE_9 (D6) to drive an LED. I'm using low-level register programming (no HAL/LL drivers). However, the LED is not responding, and I don't see a PWM signal on the pin.
Here's the code I'm using:
I’ve reviewed the STM32 reference manual, datasheet, and application notes. Timer 1 and GPIOE clocks seem to be enabled, and PE_9 is in alternate function mode, though I’m unsure if AF1 (TIM1_CH1) is correctly set. The timer is configured for PWM output, but the prescaler is not set, and I’m uncertain if the timer clock is correct. I haven't verified pin speed, output type, or pull-up/down resistors. Despite adjusting duty cycle and period, the LED remains unresponsive.
Am I missing any key register settings for Timer 1 or GPIOE? How can I confirm the correct alternate function for PE_9? Should I adjust the prescaler or check the timer clock frequency? Could GPIO configuration be affecting the LED? Any debugging tips, such as checking timer flags or using an oscilloscope, to verify the signal?
3 Replies
To get your PWM signal working on the
STM32 NUCLEO-F207ZG
board, there are a few key things to check:
- Set the Timer Prescaler
- Correct Alternate Function for PE_9.
- Re-check the GPIO settings for speed, output type (push-pull), and ensure there’s no pull-up/down resistor interfering with the signal.
- Make sure the timer clock is correctly enabled and that you're using the right PWM mode. Also, check if preload is enabled properly.
@SterlingThanks for the tips @Enthernet Code .
I’ll review the prescaler, PE_9 alternate function, and GPIO settings. Just to confirm, could a missing prescaler be causing the issue? Additionally, do my preload settings appear correct?
You're welcome @Sterling
Yes, the missing prescaler could indeed be contributing to the issue. Without setting the prescaler, the timer may be running too fast for the desired
PWM
frequency, resulting in no visible effect on the LED
. Try setting an appropriate prescaler based on the system clock and the desired PWM
frequency.
As for the preload settings, you’ve enabled the preload for TIM1
with the line TIM1->CCMR1 |= BIT3;
. This looks correct, but ensure that you also enable the auto-reload preload if you want the ARR
to be updated smoothly without glitches during operation. You can do this by setting the ARPE
bit in TIM1->CR1
( TIM1->CR1 |= BIT7;
).