2.2.1 设置优先级寄存器组的C代码 1: /** 2: * @brief Set the Priority Grouping in NVIC Interrupt Controller 3: * 4: * @param PriorityGroup is priority grouping field 5: * 6: * Set the priority grouping field using the required unlock sequence. 7: * The parameter priority_grouping is assigned to the field 8: * SCB->AIRCR [10:8] PRIGROUP field. Only values from 0..7 are used. 9: * In case of a conflict between priority grouping and available 10: * priority bits (__NVIC_PRIO_BITS) the smallest possible priority group is set. 11: */ 12: static __INLINE void NVIC_SetPriorityGrouping(uint32_t PriorityGroup) 13: { 14: uint32_t reg_value; 15: /* only values 0..7 are used */ 16: uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); 17: 18: reg_value = SCB->AIRCR; /* read old register configuration */ 19: /* clear bits to change */ 20: reg_value &= ~(SCB_AIRCR_VECTKEY_Msk | SCB_AIRCR_PRIGROUP_Msk); 21: /* Insert write key and priorty group */ 22: reg_value = (reg_value | 23: (0x5FA << SCB_AIRCR_VECTKEY_Pos) | 24: (PriorityGroupTmp << 8)); 25: SCB->AIRCR = reg_value; 26: }