STM32 基于HAL库的延时

HAL_Delay()

  • 原理:基于SysTick ISR中的变量自增,定时精度与滴答定时器的频率有关,一般为ms级;
  • 注意:SysTick的中断优先级必须高于其他任务优先级,否则如果其他中断程序中调用了此延时函数,就睡导致 中断被锁
  • 通过HAL_NVIC_SetPriority设置中断优先级

Attention 尽量不要在中断程序中调用延时函数

官方说明

     Care must be taken when using HAL_Delay(), this function provides accurate
      delay (in milliseconds) based on variable incremented in SysTick ISR. This
      implies that if HAL_Delay() is called from a peripheral ISR process, then 
      the SysTick interrupt must have higher priority (numerically lower)
      than the peripheral interrupt. Otherwise the caller ISR process will be blocked.
      To change the SysTick interrupt priority you have to use HAL_NVIC_SetPriority() function

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容