如何解决我们不能在 stm32 F407VG 的 ISR 中使用 HAL_Delay()
我是stm32的新手,我尝试使用stm32F407VG的用户按钮实现中断。
我在中断函数中添加了一个 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,0);
prev_val = false;
}
HAL_Delay(1000);
}
}
解决方法
我找到了处理方法,我的中断优先级默认为0。而 HAL_Delay()
的优先级也为 0。
所以我降低了外部中断的优先级,设置为1。
现在它工作正常
注意:如果使用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.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。