Sterling
Sterling
DIIDevHeads IoT Integration Server
Created by Sterling on 10/2/2024 in #firmware-and-baremetal
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?
4 replies