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:
// Enable timer 1 clock
RCC->APB2ENR |= BIT0;

// Set output mode for PWM
TIM1->CCMR1 |= BIT5 | BIT6;

// Set period
TIM1->ARR = 0x0000FFFF;

// Set duty cycle
TIM1->CCR1 = 0x00007FFF;

// Enable preload
TIM1->CCMR1 |= BIT3;
TIM1->CR1 |= BIT7;

// Enable CC1 output
TIM1->CCER |= BIT0;

// Enable timer
TIM1->CR1 |= BIT0;

// Enable GPIOE clock
RCC->AHB1ENR |= BIT4;

// Configure PE_9 as alternate function
GPIOE->MODER |= BIT19;
GPIOE->AFR[1] |= BIT4;
// Enable timer 1 clock
RCC->APB2ENR |= BIT0;

// Set output mode for PWM
TIM1->CCMR1 |= BIT5 | BIT6;

// Set period
TIM1->ARR = 0x0000FFFF;

// Set duty cycle
TIM1->CCR1 = 0x00007FFF;

// Enable preload
TIM1->CCMR1 |= BIT3;
TIM1->CR1 |= BIT7;

// Enable CC1 output
TIM1->CCER |= BIT0;

// Enable timer
TIM1->CR1 |= BIT0;

// Enable GPIOE clock
RCC->AHB1ENR |= BIT4;

// Configure PE_9 as alternate function
GPIOE->MODER |= BIT19;
GPIOE->AFR[1] |= BIT4;
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
Enthernet Code
Enthernet Code2mo ago
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. @Sterling
Sterling
Sterling2mo ago
Thanks 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?
Enthernet Code
Enthernet Code2mo ago
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;).
Want results from more Discord servers?
Add your server