How to get a PWM signal on port D6 (PE_9) on a STM board?

0

I'm programming a board and want a PWM signal to appear on a pin to drive a LED. I'm using a STM32 NUCLEO-F207ZG board, and only low-level register programming. It is not working.

I've looked into the manual, datasheet and application note. Also some Google searches have been done.

//Enable timer 1 clock: RCC->APB2ENR |= BIT0;

//Output mode on PWM
TIM1->CCMR1 |= BIT5 | BIT6;

//Period:
TIM1->ARR = 0x0000FFFF;

//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;

//Alternate function mode voor pin PE_9
GPIOE->MODER |= BIT19;
GPIOE->AFR[1] |= BIT4;

I expect a PWM signal on pin D6 (PE_9), to drive a LED. But the LED doesn't seem to do anything.

c
timer
stm32
pwm
nucleo
asked on Stack Overflow Nov 8, 2019 by user3279848

1 Answer

0

I didn't check your code bit by bit, but it seems OK in general. But I suspect a possible cause of the problem: Normally you should wait a few clock cycles before accessing any peripheral just after enabling its clock. I may be wrong, but it's possible that these 2 lines of code are ignored by the peripherals, as they are executed just after enabling the clocks:

TIM1->CCMR1 |= BIT5 | BIT6;
GPIOE->MODER |= BIT19;

I suggest using a debugger to check if all the peripheral registers are loaded with the correct values.

I also suggest trying other PWM channels. There may be some conflicts with the pin you're using because of the board hardware configuration.

answered on Stack Overflow Nov 8, 2019 by Tagli

User contributions licensed under CC BY-SA 3.0