STM32 NVIC中断优先级管理通过结构图快速理解

STM32 NVIC中断优先级管理通过结构图快速理解


📑抢占优先级和响应优先级基本常识

  • 🌿抢占优先级的级别高于响应优先级。
  • 🌿抢占优先级数值编号越小,所代表的优先级就越高;同理,响应优先级也是如此。
  • 🔖HAL优先组函数:
c 复制代码
/**
  * @brief  Sets the priority grouping field (preemption priority and subpriority)
  *         using the required unlock sequence.
  * @param  PriorityGroup: The priority grouping bits length. 
  *         This parameter can be one of the following values:
  *         @arg NVIC_PRIORITYGROUP_0: 0 bits for preemption priority
  *                                    4 bits for subpriority
  *         @arg NVIC_PRIORITYGROUP_1: 1 bits for preemption priority
  *                                    3 bits for subpriority
  *         @arg NVIC_PRIORITYGROUP_2: 2 bits for preemption priority
  *                                    2 bits for subpriority
  *         @arg NVIC_PRIORITYGROUP_3: 3 bits for preemption priority
  *                                    1 bits for subpriority
  *         @arg NVIC_PRIORITYGROUP_4: 4 bits for preemption priority
  *                                    0 bits for subpriority
  * @note   When the NVIC_PriorityGroup_0 is selected, IRQ preemption is no more possible. 
  *         The pending IRQ priority will be managed only by the subpriority. 
  * @retval None
  */
void HAL_NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
{
  /* Check the parameters */
  assert_param(IS_NVIC_PRIORITY_GROUP(PriorityGroup));
  
  /* Set the PRIGROUP[10:8] bits according to the PriorityGroup parameter value */
  NVIC_SetPriorityGrouping(PriorityGroup);
}
  • 🌿对于STM32f1系列,可分配有4组:
    • 🍁NVIC_PRIORITYGROUP_0
c 复制代码
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
HAL_NVIC_SetPriority(TIM5_IRQn, 0, 15);//中断号,抢占优先级(0),子优先级(0-15)
    • 🍁NVIC_PRIORITYGROUP_1
c 复制代码
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
HAL_NVIC_SetPriority(TIM5_IRQn, 1, 7);//中断号,抢占优先级(0-1),子优先级(0-7)
    • 🍁NVIC_PRIORITYGROUP_2
c 复制代码
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2);
HAL_NVIC_SetPriority(TIM5_IRQn, 3, 3);//中断号,抢占优先级(0-3),子优先级(0-3)
    • 🍁NVIC_PRIORITYGROUP_3
c 复制代码
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
HAL_NVIC_SetPriority(TIM5_IRQn, 7, 1);//中断号,抢占优先级(0-7),子优先级(0-1)
    • 🍁NVIC_PRIORITYGROUP_4
c 复制代码
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
HAL_NVIC_SetPriority(TIM5_IRQn, 15, 0);//中断号,抢占优先级(0-15),子优先级(0)
相关推荐
polarislove02141 小时前
9.6 [定时器]超声波测距实验-嵌入式铁头山羊STM32笔记
笔记·stm32·嵌入式硬件
一路往蓝-Anbo2 小时前
C语言从句柄到对象 (六) —— 继承与 HAL:父类指针访问子类数据
c语言·开发语言·stm32·嵌入式硬件·物联网
一路往蓝-Anbo4 小时前
C语言从句柄到对象 (七) —— 给对象加把锁:RTOS 环境下的并发安全
java·c语言·开发语言·stm32·单片机·嵌入式硬件·算法
一路往蓝-Anbo5 小时前
C语言从句柄到对象 (八) —— 当对象会说话:观察者模式与事件链表
c语言·开发语言·数据结构·stm32·单片机·观察者模式·链表
polarislove02145 小时前
9.5 [定时器]输入捕获-嵌入式铁头山羊STM32笔记
笔记·stm32·嵌入式硬件
IT阳晨。7 小时前
【STM32】采集温湿度数据上传至OneNET平台项目
stm32·单片机·嵌入式硬件
FL16238631297 小时前
flash_attn windows whl下载安装教程
windows·stm32·单片机
d111111111d7 小时前
配置STM32F411CEU6的系统时钟-避免芯片内核锁死
笔记·stm32·单片机·嵌入式硬件·学习
小李做物联网8 小时前
【单片机毕设】77.2基于单片机stm32智能大棚环境监控-语音
stm32·单片机·嵌入式硬件·物联网
d111111111d8 小时前
STM32内核锁死补救方法-STM32F411CEU6
笔记·stm32·单片机·嵌入式硬件·学习