我是stm32的新手,我尝试过使用stm32F407VG的user按钮实现一个中断。我在中断函数中添加了一个HAL_Delay()。按下按钮后,中断服务例程开始执行,但永远不会返回到main()函数。
这是代码中负责中断的部分:
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);
}
}发布于 2021-07-20 15:48:48
我找到了处理它的方法,我的中断优先级默认是0。并且HAL_Delay()的优先级也是0。因此,我降低了外部中断的优先级,并将其设置为1。
发布于 2021-07-20 15:50:58
注意:如果使用ST提供的默认HAL设置,则在调用HAL_Init()时,SysTick IRQ的优先级设置为15。
因此,您必须在stm32f7xx_hal_conf.h文件中或使用HAL_InitTick(TickPriority)函数对其进行更改。
另请参阅用户手动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.https://stackoverflow.com/questions/68450952
复制相似问题