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)
相关推荐
Romantic_love_2 小时前
USART串口初始化源码解析
stm32·单片机·嵌入式硬件·学习
oshan20122 小时前
零基础STM32入门教程--11-USART/UART 串行通迅
stm32·单片机·嵌入式硬件
恒锐丰小瑞3 小时前
率能SS6285M 33V/5.5A/单通道直流电机驱动IC,低待机功耗与多重保护,用于电子锁/玩具/机器人
stm32·单片机·嵌入式硬件·机器人
意法半导体STM324 小时前
【官方原创】LAT1695转换STM32CubeIDE工程到STM32CubeIDE for Visual Studio Code
vscode·stm32·单片机·嵌入式硬件
Zhang.Yi5 小时前
STM32-DMA
stm32·单片机·嵌入式硬件
小鱼儿电子6 小时前
62-基于STM32的多功能水壶控制系统设计
stm32·单片机·嵌入式硬件·多功能水壶·智能水壶
wuyk5558 小时前
9.冒泡排序:像鱼缸泡泡一样的简单排序算法
开发语言·stm32·单片机·算法·排序算法
单片机仿真设计16 小时前
【proteus仿真】基于STM32单片机直流电机控制设计(仿真图+程序)
stm32·单片机·嵌入式硬件·proteus·毕设
736c17 小时前
STM32-看门狗 10
stm32·单片机
虎王物联17 小时前
工业Modbus TCP协议深度实战:STM32 HAL库实现从机通信与数据上云
stm32·物联网·网络协议·tcp/ip·嵌入式