AnsweredAssumed Answered

stm32f407 EXTI interruption freeze

Question asked by Alexander on Mar 1, 2016
Latest reply on Mar 2, 2016 by Alexander
Hi all,

Trying to implement a basic external interruption on the stm32f407 discovery board, the microcontroller allways freeze after receiving external interrupt. After some test i discover interrupt cause a call to the Hard Fault Interrupt and the CPU enter infinite loop. (The infinite loop is defined by default in the Startup ASM file)

The code is verified several time and i don't understand the problem. I add some code to verify that the CPU go into the Hard_Fault_Handler. Here it is:

#include "stm32f4xx.h"
#include <stdint.h>
#include "stm32f4xx_rcc.h"


GPIO_InitTypeDef g1,g2;
EXTI_InitTypeDef i;
NVIC_InitTypeDef nvic_i;
uint32_t j;


void On(void);
void delay(void);
void Off(void);
void delay2(void);


int main(void)
{
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);


     g1.GPIO_Pin= GPIO_Pin_12;
     g1.GPIO_Mode= GPIO_Mode_OUT;
     g1.GPIO_OType=GPIO_OType_PP ;
     g1.GPIO_PuPd= GPIO_PuPd_NOPULL;
     g1.GPIO_Speed= GPIO_Speed_100MHz;


     g2.GPIO_Pin=GPIO_Pin_0;
     g2.GPIO_Mode= GPIO_Mode_IN;
     g2.GPIO_OType=GPIO_OType_PP ;
     g2.GPIO_PuPd= GPIO_PuPd_DOWN;
     g2.GPIO_Speed= GPIO_Speed_2MHz;


     GPIO_Init(GPIOD, &g1);
     GPIO_Init(GPIOA, &g2);


     SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
     i.EXTI_Line= EXTI_Line0;
     i.EXTI_LineCmd= ENABLE;
     i.EXTI_Mode= EXTI_Mode_Interrupt;
     i.EXTI_Trigger= EXTI_Trigger_Rising;
     EXTI_Init(&i);


     nvic_i.NVIC_IRQChannel= EXTI0_IRQn;
     nvic_i.NVIC_IRQChannelCmd= ENABLE;
     nvic_i.NVIC_IRQChannelPreemptionPriority= 0x06;
     nvic_i.NVIC_IRQChannelSubPriority= 0x06;
     NVIC_Init(&nvic_i);






     while(1){
          On();
          delay();
          Off();
          delay();
     }
}


void On(){
     GPIO_SetBits(GPIOD, GPIO_Pin_12);
}


void Off(){
     GPIO_ResetBits(GPIOD, GPIO_Pin_12);
}


void delay(){
     for(j=0;j<0xffffff;j++);
}


void delay2(){
     for(j=0;j<0x0fffff;j++);
}


void EXTI0_IRQHandler(void){
     // Make sure that interrupt flag is set
     if (EXTI_GetITStatus(EXTI_Line0) != RESET) {
          // Do your stuff when PA0 is changed
          //pause();
          GPIO_ToggleBits(GPIOD, GPIO_Pin_12);
          // Clear interrupt flag
          EXTI_ClearITPendingBit(EXTI_Line0);
     }
}


void HardFault_Handler(void){
     while(1){
          On();
          delay2();
          Off();
          delay2();
     }
}


Does someone know what i do wrong ?

Alexander

Outcomes