cancel
Showing results for 
Search instead for 
Did you mean: 

Interrupt handling with STM32F4xx_DSP_StdPeriph_Lib (EXTI0)

simo zz
Senior
Posted on October 30, 2017 at 13:38

Hello,

I am studying the STM32F4xx_DSP_StdPeriph_Lib and I am trying to understand how to handleEXTI0 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(EXTI_GetITStatus(EXTI_Line0))
{
EXTI_ClearITPendingBit(EXTI_Line0);
gpioDIndex++;
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_t.GPIO_PuPd = GPIO_PuPd_NOPULL;
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_t.GPIO_PuPd = GPIO_PuPd_NOPULL;
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;
EXTI_Init(&EXTI_t);
// 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;
NVIC_Init(&NVIC_t);
gpioDIndex = 1;
uint16_t gpioDValue[4] = {GPIO_Pin_12, GPIO_Pin_13, GPIO_Pin_14, GPIO_Pin_15};
while(1)
{
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,

Simon

23 REPLIES 23
Posted on October 30, 2017 at 18:19

Yes, I am opening a question on openstm32 forum about this. That thread is old without replies.

:(

Simon

Posted on October 30, 2017 at 18:57

Check the .MAP file

Check the linkage that actually occurs with vector table

Check the vector table names for the interrupt handlers

If your tools/code don't connect the dots properly the CPU isn't going to deliver the IRQ to you. Some debugging and sanity checking should bring resolution.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 30, 2017 at 19:08

Simo,

Does it works now after replacing with correct startup_stm32f40xx.s file ?

Regards

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Posted on October 30, 2017 at 23:17

Hello

reicher.romain

‌ , yes it works. Right now I can substitute manually the file each time, it's not a big problem, so I can go on with my work.

I advised the openstm32's stuff of my issue.

Thank you all for your support.

Regards,

Simo