cancel
Showing results for 
Search instead for 
Did you mean: 

EXTI0_IRQHandler

baev_al
Associate II
Posted on August 15, 2014 at 18:56

Dear friends. Show me please my mistake. When I debug the following program I even cannot get to ISR... I stay in infinite loop...

Thanks!

void EXTI0_IRQHandler (void);

int main(void)

{

  /*!< At this stage the microcontroller clock setting is already configured,

       this is done through SystemInit() function which is called from startup

       files (startup_stm32f429_439xx.s) before to branch to application main.

       To reconfigure the default setting of SystemInit() function, refer to

       system_stm32f4xx.c file

     */  

 

  /* Add your application code here */

    

  /* Infinite loop */

 

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOG, ENABLE); //Clck to GPIOG

  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);

  RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);

  SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);

 

 

  GPIO_InitTypeDef PortG_init, PortA_init;

 

  PortG_init.GPIO_Mode = GPIO_Mode_OUT;

  PortG_init.GPIO_OType = GPIO_OType_PP;

  PortG_init.GPIO_Pin = GPIO_Pin_13;

  PortG_init.GPIO_PuPd = GPIO_PuPd_NOPULL;

  PortG_init.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_Init(GPIOG, &PortG_init);

 

  PortA_init.GPIO_Mode = GPIO_Mode_IN;

  PortA_init.GPIO_OType = GPIO_OType_PP;

  PortA_init.GPIO_Pin = GPIO_Pin_0;

  PortA_init.GPIO_PuPd = GPIO_PuPd_NOPULL;

  PortA_init.GPIO_Speed = GPIO_Low_Speed;

  GPIO_Init(GPIOA, &PortA_init); //GPIOA_Pin_0 as input

 

 

 

  EXTI_InitTypeDef PortA_Pin0;

 

  PortA_Pin0.EXTI_Line = EXTI_Line0;

  PortA_Pin0.EXTI_Mode = EXTI_Mode_Interrupt;

  PortA_Pin0.EXTI_Trigger = EXTI_Trigger_Rising;

  PortA_Pin0.EXTI_LineCmd = ENABLE;

  EXTI_Init(&PortA_Pin0);

 

  NVIC_InitTypeDef NVIC_PortA;

 

  NVIC_PortA.NVIC_IRQChannel = EXTI0_IRQn;

  NVIC_PortA.NVIC_IRQChannelPreemptionPriority = 0x01;

  NVIC_PortA.NVIC_IRQChannelSubPriority = 0x01;

  NVIC_PortA.NVIC_IRQChannelCmd = ENABLE;

 

  NVIC_Init(&NVIC_PortA);

 

   

 

  while (1)

  {

    

  }     

}

void EXTI0_IRQHandler (void)

{

  GPIO_ToggleBits(GPIOG, GPIO_Pin_13);

//  delay(1000000);

  EXTI_ClearITPendingBit(EXTI_Line0);

}

Interesting thing...I'm working in IAR.

When I was debugging watching locals in this part:

PortA_Pin0.EXTI_Line = EXTI_Line0;

  PortA_Pin0.EXTI_Mode = EXTI_Mode_Interrupt;

  PortA_Pin0.EXTI_Trigger = EXTI_Trigger_Rising;

  PortA_Pin0.EXTI_LineCmd = ENABLE;

  EXTI_Init(&PortA_Pin0);

PortA_Pin0.EXTI_LineCmd = ENABLE stayed DISABLED until I didn't changed compiler optimization from high to medium....

What didn't I take into account?

Watching for other bugs....

3 REPLIES 3
Posted on August 17, 2014 at 05:40

C++, or you're not actually generating an interrupt?

Does the pin have/need a pull up/down? Are you looking at the right edge?

Can you print the state of the pin, via GPIO, in the while(1) loop?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
baev_al
Associate II
Posted on August 17, 2014 at 18:14

It was some sort of compiler behavior. When I checked low optimization compilation - everything started to work... One of the following steps is to understand the optimization.

''Can you print the state of the pin, via GPIO, in the while(1) loop?''

I saw the change in the IDR register - and that was very confusing.

Thanks for the support, Clive1.
Posted on August 19, 2014 at 06:37

You really should test/qualify your interrupt source, but your issue here probably is the race condition in the NVIC/EXTI. You should clear the interrupt early, not as the last thing.

void EXTI0_IRQHandler (void)
{
EXTI_ClearITPendingBit(EXTI_Line0); // Do this first to stop reentry, ideally you'd qualify the source
GPIO_ToggleBits(GPIOG, GPIO_Pin_13); // before toggling
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..