cancel
Showing results for 
Search instead for 
Did you mean: 

EXTI handler gets stuck

Arno Thiele
Associate III
Posted on January 24, 2018 at 20:27

With my STM32F4 I am trying to use an external interrupt to read aquadrature encoder on PC02 and regular port PC The interrupt on PC02 fires when I move the encoder, but it won’t return to the main loop again and my main routine gets stuck. Here’s the code:

init()
{
GPIO_InitTypeDef gpio_init;
EXTI_InitTypeDef exti_init;
NVIC_InitTypeDef nvic_init;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

gpio_init.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
gpio_init.GPIO_Speed = GPIO_Medium_Speed;
gpio_init.GPIO_Mode = GPIO_Mode_IN;
gpio_init.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &gpio_init);

SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOC, EXTI_PinSource2);
exti_init.EXTI_Line = EXTI_Line2;
exti_init.EXTI_LineCmd = ENABLE;
exti_init.EXTI_Mode = EXTI_Mode_Interrupt;
exti_init.EXTI_Trigger = EXTI_Trigger_Falling;
EXTI_Init(&exti_init);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
nvic_init.NVIC_IRQChannel = EXTI2_IRQn;
nvic_init.NVIC_IRQChannelPreemptionPriority = 0;
nvic_init.NVIC_IRQChannelSubPriority = 0;
nvic_init.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic_init);
}
————————————————————————————————————

void EXTI2_IRQHandler(void) 
{
 if (EXTI_GetITStatus(EXTI_Line2) != RESET) 
 {
 // whatever…
 EXTI_ClearITPendingBit(EXTI_Line2);
 }
}

int main(void)
{
 SystemInit();
 Encoder.init();
while(1)
{}
}
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

In my main loop I am speaking to some periphery over SPI, a DAC, ADC, LED-driver. No matter what I try the IRQHandler gets stuck. Even with no code at all in it. No matter what I remove from my main loop, it’s the same result. It seems like the pending bit of the EXTI line don’t get cleared but it is obviously cleared in the handler in line

I tried calling the interrupt in software to look at it in my debugger but there it just skips back to the main loop with no problems.

I know I can use the encoder function of the timers and I got it to work just fine, but I need 8 encoders in total so they are all taken already.

Any advice would be appreciated!

1 ACCEPTED SOLUTION

Accepted Solutions
Jan Waclawek
Senior II
Posted on January 25, 2018 at 08:54

Is this C++? Isn't the ISR name mangled?

JW

View solution in original post

2 REPLIES 2
Jan Waclawek
Senior II
Posted on January 25, 2018 at 08:54

Is this C++? Isn't the ISR name mangled?

JW

Arno Thiele
Associate III
Posted on January 25, 2018 at 16:30

Thank you Sir, you spotted it correctly! 

I forgot to turn off the name mangling by running the IRQ handler with <extern 'C'> in front.