极海APM32F103系列的MCU有中断优先级组的概念。通过查看代码可以看到极海官方定义了5个优先级。查看apm32f10x_misc.c/.h源文件,如下:
/** * @brief nvic priority group */ typedef enum { NVIC_PRIORITY_GROUP_0 = 0x700, /*!< 0 bits for pre-emption priority,4 bits for subpriority */ NVIC_PRIORITY_GROUP_1 = 0x600, /*!< 1 bits for pre-emption priority,3 bits for subpriority */ NVIC_PRIORITY_GROUP_2 = 0x500, /*!< 2 bits for pre-emption priority,2 bits for subpriority */ NVIC_PRIORITY_GROUP_3 = 0x400, /*!< 3 bits for pre-emption priority,1 bits for subpriority */ NVIC_PRIORITY_GROUP_4 = 0x300 /*!< 4 bits for pre-emption priority,0 bits for subpriority */ } NVIC_PRIORITY_GROUP_T; /*! * @brief Configures the priority grouping: pre-emption priority and subpriority. * * @param priorityGroup : specifies the priority grouping bits length. * This parameter can be one of the following values: * @arg NVIC_PRIORITY_GROUP_0 * @arg NVIC_PRIORITY_GROUP_1 * @arg NVIC_PRIORITY_GROUP_2 * @arg NVIC_PRIORITY_GROUP_3 * @arg NVIC_PRIORITY_GROUP_4 * * @retval None */ void NVIC_ConfigPriorityGroup(NVIC_PRIORITY_GROUP_T priorityGroup) { SCB->AIRCR = AIRCR_VECTKEY_MASK | priorityGroup; }
我看极海官方示例里面,有用优先级2的,也有用优先级4的!所以问题来了,大家在项目中都使用哪个优先级组?