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)
相关推荐
12.=0.11 小时前
【stm32_2.2】【快速入门】对GPIO解析、外设的初始化和配置、细节分析GPIO
stm32·单片机·嵌入式硬件
心语星愿1111 小时前
STM32单片机高级篇-物联网通信之CAN通讯(学习笔记)
stm32·单片机·物联网
爱喝纯牛奶的柠檬14 小时前
【已验证】STM32+MPU6050 姿态解算 + 运动状态识别 + 四阶段摔倒检测
stm32·单片机·嵌入式硬件
戏舟的嵌入式开源笔记14 小时前
STM32 RS485读取SHT20
stm32·单片机·嵌入式硬件
LCG元15 小时前
噪声检测系统:STM32F4驱动MEMS麦克风,FFT频谱分析实战
stm32·单片机·嵌入式硬件
charlie11451419116 小时前
嵌入式C++教程实战之Linux下的单片机编程:从零搭建 STM32 开发工具链(2) —— HAL 库获取、启动文件坑位与目录搭建
linux·开发语言·c++·stm32·单片机·学习·嵌入式
爱喝纯牛奶的柠檬16 小时前
【已验证】基于STM32F103的土壤湿度传感器驱动
stm32·单片机·嵌入式硬件
电源海盗船16 小时前
第一讲 单相逆变器原理与硬件设计
stm32·单片机·嵌入式硬件·开源·dsp开发
Truffle7电子18 小时前
STM32理论 —— FreeRTOS:中断管理、列表
stm32·单片机·嵌入式硬件·rtos
Hello_Embed18 小时前
嵌入式上位机开发入门(二):常用 API
笔记·stm32·嵌入式·信息与通信