Is the LED off if you comment out BSP_ledOn()? Your code only turns the LED on, not off. If it's on to begin with, pressing the button won't do anything.
Need to set port C in EXTI_EXTICRx register.
in the interrupt, you should check for and clear the EXTI flag for pin 13 in EXTI_FPR1, and only turn on the LED if it's set. Don't need to do anything with NVIC functions or register.
Thank you TDK, I should've clarified, the interrupt is always on, when I set a breakpoint at the interrupt, it breaks all the time, hence the LED is always on.
I added code for FPR1 to clear that bit and the LED now blinks very fast that it is barely on, looks like d flicker.
I haven't figured out how to use EXTI_EXTICRx yet. Looks aweful convoluted and will take more time.
void EXTI4_15_IRQHandler(void) {
if(EXTI->FPR1 & EXTI_FPR1_FPIF8) {
// do something
EXTI->FPR1 |= EXTI_FPR1_FPIF8; // clear pending bit
}
}
// make PA8 EXTI interrupt
void init_EXTI() {
RCC->IOPENR |= RCC_IOPENR_GPIOAEN; // enable peripheral clock
(void)RCC->IOPENR; // read back to make sure that clock is on
GPIOA->MODER = (GPIOA->MODER & ~GPIO_MODER_MODE8_Msk) | (0 << GPIO_MODER_MODE8_Pos); // input mode
EXTI->FTSR1 |= EXTI_FTSR1_FT8; // enable falling edge of Px8 (x=any port), we use it for PA8
EXTI->EXTICR[3] |= 0 << EXTI_EXTICR3_EXTI8_Pos; // set port to A for PA8
EXTI->IMR1 |= EXTI_IMR1_IM8; // EXTI CPU wakeup with interrupt mask register
//EXTI->EMR1 |= EXTI_EMR1_EM8; // EXTI CPU wakeup with event mask register
NVIC_EnableIRQ(EXTI4_15_IRQn);
}
What you have found (12.5.6 EXTI external interrupt) plus Table 47. EXTI controller register register map and reset values explains it. Yes, each 8-bit block in a EXTI_EXTICRx is a bitmap of the enableds ports.