Reputation: 126
I am new to stm32, I tried to implement an interrupt using the user button of stm32F407VG.
I added a HAL_Delay()
inside the interrupt function.
When the button is pressed, the Interrupt service routine start executing but it never comes back to the main()
function.
That's the part of the code which is responsible for the interrupt:
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin==GPIO_PIN_0)
{
if(prev_val==false)
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14, 1);
prev_val=true;
}
else
{
HAL_GPIO_WritePin(GPIOD, GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14, 0);
prev_val = false;
}
HAL_Delay(1000);
}
}
Upvotes: 1
Views: 2590
Reputation: 3912
Take care: If using the default HAL settings provided by ST, the priority for SysTick IRQ is set to 15 when calling HAL_Init().
So you have to change that in the stm32f7xx_hal_conf.h
file or by using the HAL_InitTick(TickPriority) function.
See also Usermanual page 31:
HAL_Delay(). this function implements a delay (expressed in milliseconds) using the SysTick timer.
Care must be taken when using HAL_Delay() since this function provides an accurate delay (expressed in
milliseconds) based on a variable incremented in SysTick ISR. This means that if HAL_Delay() is called from
a peripheral ISR, then the SysTick interrupt must have highest priority (numerically lower) than the
peripheral interrupt, otherwise the caller ISR is blocked.
Upvotes: 2
Reputation: 126
I found the way to deal with it, my interrupt priority was 0 by default. And HAL_Delay()
also has the priority 0.
So I reduced the priority of the external interrupt and set it to 1.
Now its working fine
Upvotes: 0