# STM32 interrupt does not fire

I'm using an STM32F103C8T6 (aka blue pill).

GPIO Init and interrupt handler:

static void MX_GPIO_Init(void)
{

GPIO_InitTypeDef GPIO_InitStruct;

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOA_CLK_ENABLE();

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_SET);

/*Configure GPIO pin Output Level */
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET);

/*Configure GPIO pins : PC13 PC15 */
GPIO_InitStruct.Pin = GPIO_PIN_13|GPIO_PIN_15;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

/*Configure GPIO pin : PA0 */
GPIO_InitStruct.Pin = GPIO_PIN_0;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

HAL_NVIC_EnableIRQ(EXTI0_IRQn);

while(1);

}

void EXTI0_IRQHandler(void)
{
__HAL_GPIO_EXTI_CLEAR_IT(GPIO_PIN_0);
HAL_GPIO_TogglePin(GPIOC, GPIO_PIN_14);
}


The problem is that the interrupt handler (EXTI0_IRQHandler) is never called. I tried also with other pins (e.g. using EXTI15_10_IRQHandler). I checked the switch and LED separately (in the main function) and those work. I also tried with PULLUP and PULLDOWN (which makes no difference).

Is there more needed to trigger the interrupt function?

• not sure, but is it maybe necessary to globally enable interrupts, or assign a priority to your specific interrupt? Is EXTI0_IRQn a constant or should it be something like EXTI0_IRQ0? – Marcus Müller Aug 21 '17 at 21:04
• @MarcusMüller It is a constant and I will check for setting a priority, thanks for the remark. – Michel Keijzers Aug 21 '17 at 21:28
• @PeterJ Thanks ... I will check, __HAL_RCC_GPIOA_CLK_ENABLE(); I already did (also for GPIOC and GPIOD. – Michel Keijzers Aug 22 '17 at 8:43
• @Marcus Müller - did you ever have any contact with those micros? I think you did not – P__J__ Aug 22 '17 at 8:50
• @PeterJ I don't know why you're being so rude, I explicitly uttered a vague suspicion. Yes, I've been working with stm32f1 before, but without the clunky HAL lib. Excuse me if I don't have the docs to all the microcontrollers I've worked with in my head. – Marcus Müller Aug 22 '17 at 9:44

Do the steps from my comment, Here is the sample code. I had a different hardware connections so I used a different pins.

int main(void) {
RCC->APB2ENR = RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_AFIOEN;

//confure PB2  PC13 as inputs, PB0 output

AFIO->EXTICR[0] = AFIO_EXTICR1_EXTI2_PB;
AFIO->EXTICR[3] = AFIO_EXTICR4_EXTI13_PC;
EXTI->IMR = EXTI_IMR_MR2 | EXTI_IMR_MR13;
EXTI->RTSR = EXTI_RTSR_TR2;
EXTI->FTSR = EXTI_FTSR_TR13;
NVIC_EnableIRQ(EXTI2_IRQn);
NVIC_EnableIRQ(EXTI15_10_IRQn);
while (1);
}
void EXTI2_IRQHandler(void) {
if (EXTI->PR & EXTI_PR_PR2) {
EXTI->PR = EXTI_PR_PR2;
GPIOB -> ODR |= GPIO_ODR_0;
}
}

void EXTI15_10_IRQHandler(void) {
if (EXTI->PR & EXTI_PR_PR13) {
EXTI->PR = EXTI_PR_PR13;
GPIOB -> ODR &= ~GPIO_ODR_0;
}
}


one pin turns led on another turns off

• Thanks for this comment, I use HAL so I first need to find out what all those numbers mean (good exercise for me). Btw, is there a reason you use PC13 as input since for my board PC13 is connected to an output (builtin LED)? – Michel Keijzers Aug 22 '17 at 8:57
• I havw only one board with 103 as it is an obsolete family of micros. And on this board I have different connections than the "bluepil". Just change to the one you have. I just wanted to give you the working example - so I have tested it on my actual hardware – P__J__ Aug 22 '17 at 9:55
• When I came home it suddenly worked (only change: I took the breadboard including stm32 by car) ... so maybe it was some electronic problem (loose wire). But I will study your example to see the difference between Hal and 'direct calls'. – Michel Keijzers Aug 22 '17 at 19:55
• I honestly advise the bare registers way. – P__J__ Aug 22 '17 at 19:57
• No SPL is dead and unsupported for years. Just include CMSIS headers, download the Reference Manual and enjoy :) – P__J__ Aug 22 '17 at 20:30