AnsweredAssumed Answered

Interrupt handling with STM32F4xx_DSP_StdPeriph_Lib (EXTI0)

Question asked by simo zz on Oct 30, 2017
Latest reply on Oct 30, 2017 by simo zz



I am studying the STM32F4xx_DSP_StdPeriph_Lib and I am trying to understand how to handle EXTI0 interrupts using the STM32F4xx Discovery Board.

The firmware should execute the interrupt when the GPIOA0 is triggered (in this case with the User button) and sequentially toggle the GPIOD[12:15] pins.


The code I wrote is the following:


#include <stm32f4xx.h>
#include <stm32f4xx_rcc.h>
#include <stm32f4xx_gpio.h>
#include <stm32f4xx_exti.h>

uint8_t gpioDIndex;

// ISR
void EXTI0_IRQHandler(void)

          if(gpioDIndex > 3)
               gpioDIndex = 0;

int main(void)
     // GPIO, NVIC and EXTI declarations
     GPIO_InitTypeDef GPIO_t;
     NVIC_InitTypeDef NVIC_t;
     EXTI_InitTypeDef EXTI_t;

     // SYCFG and GPIOA GPIOD Clock enable
     RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
     RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOD, ENABLE);

     // configure GPIOA0 as input
     GPIO_t.GPIO_Pin = GPIO_Pin_0;
     GPIO_t.GPIO_Mode = GPIO_Mode_IN;
     //GPIO_t.GPIO_OType = GPIO_OType_PP;
     GPIO_t.GPIO_Speed = GPIO_Speed_100MHz;
     GPIO_Init(GPIOA, &GPIO_t);

     // Configure GPIOD[12:15] as output
     GPIO_t.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
     GPIO_t.GPIO_Mode = GPIO_Mode_OUT;
     GPIO_t.GPIO_OType = GPIO_OType_PP;
     GPIO_t.GPIO_Speed = GPIO_Speed_100MHz;
     GPIO_Init(GPIOD, &GPIO_t);

     // Configure external interrupt for PA0
     SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource0);
     EXTI_t.EXTI_Line = EXTI_Line0;
     EXTI_t.EXTI_Mode = EXTI_Mode_Interrupt;
     EXTI_t.EXTI_Trigger = EXTI_Trigger_Rising;
     EXTI_t.EXTI_LineCmd = ENABLE;

     // enable EXTI0 interrupt for NVIC
     NVIC_t.NVIC_IRQChannel = EXTI0_IRQn;
     NVIC_t.NVIC_IRQChannelPreemptionPriority = 0;
     NVIC_t.NVIC_IRQChannelSubPriority = 0;
     NVIC_t.NVIC_IRQChannelCmd = ENABLE;

     gpioDIndex = 1;
     uint16_t gpioDValue[4] = {GPIO_Pin_12, GPIO_Pin_13, GPIO_Pin_14, GPIO_Pin_15};

          GPIO_SetBits(GPIOD, gpioDValue[gpioDIndex]);

     return 0;

However, it seems the interrupt is never executed since the GPIOD[12:15] state is not changing.


What's wrong with my code on interrupt handling ?


Thank you in advance,