I'm using B-L4S5I-IOT01A board (STM32L4S5VIT6) and I'm following bare-metal course, but I'm not able to force my LED to blink when timer expire.
In my board configuration, LED is connected on PB14, and also in documentation I've seen PB14 has TIM1_CH2N uder Alternate Function 1.
void initTimerTim1()
{
RCC->APB2ENR |= RCC_APB2ENR_TIM1EN;
(void)RCC->APB2ENR;
GPIOB->MODER &= ~(1U << 28);
GPIOB->MODER |= 1U << 29;
GPIOB->AFR[1] |= 1U << 24;
GPIOB->AFR[1] &= ~(1U << 25);
GPIOB->AFR[1] &= ~(1U << 26);
GPIOB->AFR[1] &= ~(1U << 27);
TIM1->PSC = 400 - 1;
TIM1->ARR = 20000 - 1;
TIM1->CNT = 0;
TIM1->CCMR1|=TIM_CCMR1_OC2M_0|TIM_CCMR1_OC2M_1;
TIM1->CCER|=TIM_CCER_CC2E;
TIM1->BDTR |= TIM_BDTR_MOE;
TIM1->CR1 |= TIM_CR1_CEN;
}
int main()
{
RCC->AHB2ENR |= 1U << 1;
RCC->AHB2ENR |= 1U << 2;
initTimerTim1();
while (1){}
}
I've checked also some registers and it seems to be configured properly (at least according to my understanding).
GPIOB->MODER MODER14 = 0b10 (10: Alternate function mode)
GPIOB->AFRH PIN14 = 0b0001 (0001: AF1)
TIM1->CR1 CEN = 0b1
TIM1->CCER CC2E = 0b1
TIM1->CCMR1_Output O2CM=0b011
Is it possible to even achieve this with TIM1 (my course uses TIM2).
TIM1_CH2N is enabled by TIMx_ENR.CC2NE.