2023-01-11 12:03 AM
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.
Solved! Go to Solution.
2023-01-11 04:24 AM
I verified the stm32f4xx_hal_gpio.c and exti.c and they are exactly the same. the hal configuration is also the same.
2023-01-11 04:37 AM
You use latest MX and FW ?
How optimize level.
Your code in main can be optimized out and MCU halt...
2023-01-11 04:47 AM
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.
2023-01-11 04:49 AM
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.
2023-01-11 04:56 AM
while is optimized not all main.
Open example code for your nucleo from repository and try learn exti from it.
Projects/STM32F429ZI-Nucleo/Examples/GPIO/GPIO_EXTI/
2023-01-11 05:16 AM
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
2023-01-11 08:15 AM
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.
2023-01-11 08:19 AM
I posted before I saw this post, but yeah that is what I was talking about.
2023-01-11 10:58 PM
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.
2023-01-12 12:02 AM
Are interrupts enabled at all? Call HAL_Delay(10) before MX_GPIO_Init.