AnsweredAssumed Answered

How to Enable GPIO External Interrupts STM32F30x_StdPeriph_Driver

Question asked by Palaima.Emmett on Jan 29, 2017
Latest reply on Nov 24, 2017 by Randy Nelson

Hi I'm working on a project where I need to enable external GPIO interrupts on the STM32F303 discovery board. I've looked up several examples online, but can't seem to get in to work. I'm using the STM32F30x_StdPeriph_Driver. I see in several examples that GPIO_MODE_IT_RISING is used as the GPIO pin mode for interrupts, but this is a HAL library thing and not present in the StdPeriph. 


I am using EXTI_LINE12 with GPIO PB12 in input pullup mode with trigger on the rising edge, vector is EXTI15_10_IRQn. Please let me know if you see anything I am doing wrong, I am at a loss at this point. Code is included below, thanks!


Function where I instantiate GPIO and interrupt (called in main):

static void GPIO_InputInit(void){
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15 | GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOE, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_10 | GPIO_Pin_11 | GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15; //GPIO_Pin_12
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
EXTI_InitTypeDef EXTI_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
/* Tell system that you will use PB12 for EXTI_Line12 */
SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOB, EXTI_PinSource12);
/* PB12 is connected to EXTI_Line12 */
EXTI_InitStruct.EXTI_Line = EXTI_Line12;
/* Enable interrupt */
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
/* Interrupt mode */
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
/* Triggers on rising and falling edge */
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
/* Add to EXTI */
/* Add IRQ vector to NVIC */
/* PB12 is connected to EXTI_Line12, which has EXTI15_10_IRQn vector */
NVIC_InitStruct.NVIC_IRQChannel = EXTI15_10_IRQn;
/* Set priority */
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0x00;
/* Set sub priority */
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0x01;
/* Enable interrupt */
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
/* Add to NVIC */


Interrupt Function:

void EXTI15_10_IRQHandler(void) {
interruptFlag = 1;
if (EXTI_GetITStatus(EXTI_Line12) != RESET) {
envStage = 1;