Skip to main content
Fnx_QT
Associate II
January 11, 2023
Solved

EXTI15_10 not triggered by user button on NUCLEO-F429ZI

  • January 11, 2023
  • 7 replies
  • 7210 views

Hello,

I'm trying to setup interrupts using the user push button (B1) on the Nucleo-F429ZI board. The push button is connected to the microcontroller through the I/O line PC13.

What I did is that I mapped the PC13 to the GPIO_EXTI15 in STM32CubeMX and enabled the NVIC interrupt for EXTI15_10. Then I regenerated the code which gave me the following function in main:

static void MX_GPIO_Init(void)
{
 GPIO_InitTypeDef GPIO_InitStruct = {0};
 
 /* GPIO Ports Clock Enable */
 __HAL_RCC_GPIOC_CLK_ENABLE();
 
 /*Configure GPIO pin : PC13 */
 GPIO_InitStruct.Pin = GPIO_PIN_13;
 GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
 GPIO_InitStruct.Pull = GPIO_NOPULL;
 HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
 
 /* EXTI interrupt init*/
 HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
 HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
 
}

I call it in the main after initializing the clocks. However, after the function has been executed, pressing the button does not trigger an interrupt. I enabled interrupt tracing and I can see that the interrupt is never triggered and my callback is therefor never called.

Did I do something wrong ? Thank you.

This topic has been closed for replies.
Best answer by Fnx_QT

I finally found the problem... All the configuration was good, the only thing that broke my system was a preprocessor symbol define that was included in my example project : CMSIS_NVIC_VIRTUAL HSE_VALUE=8000000. I still don't know what purpose it serves.

In addition, the cmsis_nvic_virtual.h was used and some NVIC functions were redefined:

#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
#define NVIC_EnableIRQ(IRQn) svcNVIC_func(2U, IRQn)
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
#define NVIC_DisableIRQ(IRQn) svcNVIC_func(4U, IRQn)
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
#define NVIC_ClearPendingIRQ(IRQn) svcNVIC_func(7U, IRQn)
#define NVIC_GetActive __NVIC_GetActive
#define NVIC_SetPriority __NVIC_SetPriority
#define NVIC_GetPriority __NVIC_GetPriority
#define NVIC_SystemReset __NVIC_SystemReset

Upon removing these two modifications, the button interrupt is now working correctly.

Thank you all for your help.

7 replies

Karl Yamashita
Lead III
January 11, 2023

Besides enabling NVIC, did you enable for External Interrupt Mode?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Fnx_QT
Fnx_QTAuthor
Associate II
January 11, 2023

If by enabling External Interrupt Mode you mean enable EXTI line[15:10] interrupts in the NVIC Interrupt Table, then yes.

If you mean another thing, then I don't what it is and I'm interested.

Karl Yamashita
Lead III
January 11, 2023

Enabling EXTI line[15:10] is 1 of 2 things that needs to be enabled. I believe by default External Event Mode is enabled but you want External Interrupt Mode.

0693W00000Y7zRmQAJ.png

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
Fnx_QT
Fnx_QTAuthor
Associate II
January 11, 2023

Oh and if you meant setting the GPIO mode to External Interrupt Mode with Rising/Falling edge trigger detection, also yes. I tried both with Rising and Falling edge, and both failed.

Karl Yamashita
Lead III
January 11, 2023

I posted before I saw this post, but yeah that is what I was talking about.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
ST Employee
January 11, 2023

Hello @Fnx_QT​ 

You should create a function to handle the EXTI interrupt : void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

in which you write the code that you want to be executed when the interrupt occurs.

This Wiki can guide you through it step by step

Thank you for your contribution!

Sarra

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.
Fnx_QT
Fnx_QTAuthor
Associate II
January 11, 2023

Hello @Sarra.S​ ,

Yes I did create and implement the function, the thing is that it's never called as the interrupt is never triggered. In exceptions tracing I always see EXTI15_10 with a count of 0.

MM..1
Chief III
January 11, 2023

Place breakpoint into callback and show how you implement callback.

Simple mistake is change in it file and dont clear flags...

Fnx_QT
Fnx_QTAuthor
Associate II
January 11, 2023

Yes I use the latest update. No the main is not optimized out cause I can place breakpoints inside the GPIO initialization methods. That's really strange.

waclawek.jan
Super User
January 11, 2023

Read out and check/post EXTI and relevant GPIO registers content.

In debugger, check that the respective bit in GPIO_IDR changes when button is pressed.

Here are some general steps when interrupts not fire.

JW

Fnx_QT
Fnx_QTAuthor
Associate II
January 12, 2023

Using the debugger I can see that the bit IDR13 in GPIOC is set everytime I press the button and unset as soon as I release it.

In the EXTI registers I can also see that the IMR (Interrupt Mask Register) is set to 1 for line 13, thus not masking interrupt from line 13.

The RTSR (Rising Trigger Selection Register) is set to 1 for line 13, so rising trigger exception are enabled.

The FTSR (Falling Trigger) is set to 0 for line 13.

Software Interrupt Event Register (SWIER) is set to 0 for line 13.

The Pending Register (PR) is set to 1, it's interesting cause I cannot disable it, it reenables itself directly if I uncheck it.

Pavel A.
Super User
January 12, 2023

Are interrupts enabled at all? Call HAL_Delay(10) before MX_GPIO_Init.

ST Employee
January 12, 2023

Did you try with other interrupts ? not with the push button but with another pin that you can set and reset

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.
Fnx_QT
Fnx_QTAuthorBest answer
Associate II
January 12, 2023

I finally found the problem... All the configuration was good, the only thing that broke my system was a preprocessor symbol define that was included in my example project : CMSIS_NVIC_VIRTUAL HSE_VALUE=8000000. I still don't know what purpose it serves.

In addition, the cmsis_nvic_virtual.h was used and some NVIC functions were redefined:

#define NVIC_SetPriorityGrouping __NVIC_SetPriorityGrouping
#define NVIC_GetPriorityGrouping __NVIC_GetPriorityGrouping
#define NVIC_EnableIRQ(IRQn) svcNVIC_func(2U, IRQn)
#define NVIC_GetEnableIRQ __NVIC_GetEnableIRQ
#define NVIC_DisableIRQ(IRQn) svcNVIC_func(4U, IRQn)
#define NVIC_GetPendingIRQ __NVIC_GetPendingIRQ
#define NVIC_SetPendingIRQ __NVIC_SetPendingIRQ
#define NVIC_ClearPendingIRQ(IRQn) svcNVIC_func(7U, IRQn)
#define NVIC_GetActive __NVIC_GetActive
#define NVIC_SetPriority __NVIC_SetPriority
#define NVIC_GetPriority __NVIC_GetPriority
#define NVIC_SystemReset __NVIC_SystemReset

Upon removing these two modifications, the button interrupt is now working correctly.

Thank you all for your help.