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


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


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

    • 🌿抢占优先级的级别高于响应优先级。
    • 🌿抢占优先级数值编号越小,所代表的优先级就越高;同理,响应优先级也是如此。
    • 🔖HAL优先组函数:
    /**
      * @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);
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 🌿对于STM32f1系列,可分配有4组:
      在这里插入图片描述
      • 🍁NVIC_PRIORITYGROUP_0
        在这里插入图片描述
    HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
    HAL_NVIC_SetPriority(TIM5_IRQn, 0, 15);//中断号,抢占优先级(0),子优先级(0-15)
    
    • 1
    • 2
      • 🍁NVIC_PRIORITYGROUP_1
        在这里插入图片描述
    HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_1);
    HAL_NVIC_SetPriority(TIM5_IRQn, 1, 7);//中断号,抢占优先级(0-1),子优先级(0-7)
    
    • 1
    • 2
      • 🍁NVIC_PRIORITYGROUP_2

    在这里插入图片描述

    HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2);
    HAL_NVIC_SetPriority(TIM5_IRQn, 3, 3);//中断号,抢占优先级(0-3),子优先级(0-3)
    
    • 1
    • 2
      • 🍁NVIC_PRIORITYGROUP_3

    在这里插入图片描述

    HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_3);
    HAL_NVIC_SetPriority(TIM5_IRQn, 7, 1);//中断号,抢占优先级(0-7),子优先级(0-1)
    
    • 1
    • 2
      • 🍁NVIC_PRIORITYGROUP_4
        在这里插入图片描述
    HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_4);
    HAL_NVIC_SetPriority(TIM5_IRQn, 15, 0);//中断号,抢占优先级(0-15),子优先级(0)
    
    • 1
    • 2
  • 相关阅读:
    Linux—系统基础一
    【智能优化算法】从蚁群到动物园
    【前端】Vue+Element UI案例:通用后台管理系统-登陆页面功能:登录权限跳转、路由守卫、退出
    【Java初阶】Array详解
    RK3568平台开发系列讲解(LCD篇)DRM 显示框架
    Mac下好用的日记、电子书阅读器、RSS订阅软件​
    unity - Blend Shape - 变形器 - 实践
    项目实战:一个由多线程引起的线程安全问题(附:解决方案)
    Hadoop3教程(三十三):(生产调优篇)慢磁盘监控与小文件归档
    工具精灵--超级好用的在线工具网站
  • 原文地址:https://blog.csdn.net/weixin_42880082/article/details/133131170