
Group 0: All 4 bits used for response priority:16 interrupt vectors have different response priorities. Group 1: Highest 1 bit for preemptive priority, lowest 3 bits for response priority.This means there are 2 levels of preemptive priority (level 0, level 1), and 8 response priorities: there are 8 interrupts with preemptive priority level 0, with response priorities from 0 to 7; the remaining 8 interrupt vectors have preemptive priority level 1, with response priorities also from 0 to 7. Group 2: 2 bits for preemptive priority, 2 bits for response priority:4 levels of preemptive priority and 4 levels of response priority. Group 3: Highest 3 bits for preemptive priority, lowest 1 bit for response priority:8 levels of preemptive priority and 2 levels of response priority. Group 4: All 4 bits used for preemptive priority:16 interrupt vectors only have preemptive attributes, with no response attributes.
To configure these priority groups, you can use the library function NVIC_PriorityGroupConfig(), with input parameters ranging from NVIC_PriorityGroup_0 to NVIC_PriorityGroup_4, corresponding to the above 5 allocation groups.
void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup);
void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct);// Configuration processNVIC_InitTypeDef NVIC_InitStructure;NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;// USART1 interrupt, can be changed to any module with interrupt functionality like timers, external interrupts, etc.NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;// Preemptive priority set to 1NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;// Sub-priority set to 2NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;// Enable IRQ channelNVIC_Init(&NVIC_InitStructure); // Initialize NVIC register with specified parameters
void NVIC_PriorityGroup(); // Written in the main program;NVIC_Init(); // Written in the initialization configuration
{// Enable EXTI0 interruptNVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; // Set preemptive priority to level 1NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; // Set response priority to level 0NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);// Enable EXTI9_5 interruptNVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel;NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // Set preemptive priority to level 0NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // Set response priority to level 1NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;NVIC_Init(&NVIC_InitStructure);// TIM3 interruptNVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn; // TIM3 interruptNVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // Highest preemptive priority level 0NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3; // Sub-priority level 3NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; // IRQ channel enabledNVIC_Init(&NVIC_InitStructure); TIM_Cmd(TIM3, ENABLE); // Enable TIMx peripheral}