stm32f407 EXTI interruption freeze
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-01 3:11 AM
Posted on March 01, 2016 at 12:11
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
This discussion is locked. Please start a new topic to ask your question.
4 REPLIES 4
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-01 8:40 AM
Posted on March 01, 2016 at 17:40
What tool chain are you using?
What are the defines passed into the compiler?Which startup file is being used?You have reviewed this with a debugger?C++ or .cpp?I might do this differently, but the code doesn't look unreasonable.Use local variables for the delay iterators, with a volatile definition.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-02 1:38 AM
Posted on March 02, 2016 at 10:38 The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6jR&d=%2Fa%2F0X0000000buA%2FHXK1Sz56uIRkb.4IbH6b5jkDyR5EYTvbhMzHvkomFWY&asPdf=false
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-02 11:33 AM
Posted on March 02, 2016 at 20:33 The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6jD&d=%2Fa%2F0X0000000bu3%2FsUwSX8VCsrFvDtVTnH_LqYjxulo2KAk6UQ9_za8kOBI&asPdf=false
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Up vote any posts that you find helpful, it shows what's working..
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-03-02 12:14 PM
Posted on March 02, 2016 at 21:14 The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6f1&d=%2Fa%2F0X0000000bsd%2FPdciVfuGZcl0C6SHqBIeaXrXm2kz6S0COY.8UacjV28&asPdf=false
