Solved
PWM no signal
I've wrote a code without using Hal to produce a signal on the scope but i'm not getting any signal on my pin.
This is on a NUCLEO F401RE. Using TIMER3_CHANNEL1 and GPIOB for my Alternate function.
#include <stdint.h>
#include "stm32f4xx.h"
#include "stm32f401xe.h"
#define CMS_6 (1U<<6)
#define CMS_5 (1U<<5)
int main(void)
{
//Enable clock access to TIMER3/PWM
RCC->AHB1ENR |= (1U<<1); //GPIO Port B enable
RCC->APB1ENR |= (1U<<1); //Timer clock enable
//Set alternate function mode PB4(D5)
GPIOB->MODER |= (1U<<9);
GPIOB->MODER&=~ (1U<<8);
GPIOB->AFR[0]|= (1U<<18);
//Enable Timer
TIM3->CR1 |= (1U<<0)|(1U<<7); // Counter Enable ,
TIM3->CR1 &=~CMS_6 ;/*Edge aligned mode
TIM3->CR1 &=~CMS_5; */
TIM3->CR1 &=~ (1U<<4);// Direction Enable used as upconter
//Setting PWM mode 1 (OC1M),(OC1PE)
TIM3->CCMR1 |=((1U<<6)|(1U<<5))| (1U<<3);
//Event Generation register
TIM3->EGR |= (1<<0);
//Capture Compare enable register/Enabled Channel 1
TIM3->CCER |= (1U<<1);
//PWM frequency = Frequency clock/PSC/ARR 42Mhz/1000
//PWM Duty cycle = CCR1/ARR = 50% Duty cycle.
TIM3->PSC =42;
TIM3->ARR = 1000;
TIM3->CCR1 = 500; //Duty cycle 50% , counting from 0 to a 1000;
for(;;);
}
