Question
How to start PWM using the registers.
What am I doing wrong?
Why is PWM don't work on the STM32F767ZI?
RCC->APB2ENR |= 1; // Enable clock for TIM1 on APB2.
RCC->AHB1ENR |= RCC_AHB1ENR_GPIOEEN; // Enable clock for GPIOE port on AHB1.
GPIOE->MODER &= ~(1 << 18); // Clear/reset PE9 mode.
GPIOE->MODER |= (2 << 18); // Set PE9 mode.
// Enable alternative function AFIO. Connect TIM to the pin accordingly!
GPIOE->AFR[1] &= ~(0xF << 4); // Clear bits 4 to 7.
GPIOE->AFR[1] |= (1 << 4); // Set bit 9.
TIM1->PSC = 216 - 1; // Set prescaler for > 10KHz.
TIM1->ARR = 100 - 1; // Set auto-reload value for 1Hz.
TIM1->CCR1 = 50; // Set initial comparison value (PWM duty cycle).
TIM1->CNT = 0; // Reset the current count.
TIM1->CCMR1 |= (0x6UL << TIM_CCMR1_OC1M_Pos ); // Set PWM mode 1.
TIM1->CCMR1 |= (0x68 << 0);
TIM1->CCER = 1; // Enable PWM Channel 1.
TIM1->CR1 = 1; // Enable timer.



