Recently in the study of STM32 interrupted nesting problem, finally found a good understanding of the method, perhaps I was too stupid to record!
The STM32 has 43 channel settable interrupt sources, and the AIRC (application Interrupt and Reset Register) registers have 4 bits for the specified priority. These 4 bits are used to assign preemption priority and sub priority, as defined in the STM32 firmware library
/* preemption Priority Group-------------------------------------------------*/
#define NVIC_PRIORITYGROUP_0 ((u32) 0x700)/* 0 bits for pre-emption priority
4 bits for subpriority */
#define NVIC_PRIORITYGROUP_1 ((u32) 0x600)/* 1 bits for pre-emption priority
3 bits for Subpriority */
#define NVIC_PRIORITYGROUP_2 ((u32) 0x500)/* 2 bits for pre-emption priority
2 bits for subpriority */
#define NVIC_PRIORITYGROUP_3 ((u32) 0x400)/* 3 bits for pre-emption priority
1 bits for subpriority */
#define NVIC_PRIORITYGROUP_4 ((u32) 0x300)/* 4 bits for pre-emption priority
0 bits for Subpriority */
The visual comprehension is:
You are God,
The creation of 43 people, so many people to divide the social class and social class;
Because the "class" of the part of the word is more serious, "stratum" more neutral,
So preemption priority-class; Within each class, there are classes, sub-priorities, and classes;
If according to nvic_prioritygroup_4 such points, divided into 16 classes (a class is a preemption priority), 0 classes, high-class people can interrupt the low-class are doing things (nested), up to 1 interrupts and 15 levels of nesting.
Each class (each preemption priority), you designate the 43 people who enter the class; a man named Exti0_irqchannel, you designate him to enter "Class 8", then
Nvic_initstructure.nvic_irqchannel = Exti0_irqchannel;
Nvic_initstructure.nvic_irqchannelpreemptionpriority = 8; Specify preemption priority level 1, preferably 0-15
In addition, within the same class, when a person is doing something, another person cannot interrupt him; (preemption no nesting relationship between interrupt sources with the same priority level)
Also, if they both want to do things at the same time, because there is no hierarchy, then according to the physical order of the vector table, so that the top-ranked people to do;
There are 1 other people spi1_irqchannel, set the following
Nvic_initstructure.nvic_irqchannel = Spi1_irqchannel;
nvic_initstructure.nvic_irqchannelpreemptionpriority = 0; Specify preemption priority level 1, preferably 0-15
Spi1_irqchannel class is high, Exti0_irqchannel can interrupt (nest) when doing things.
If Nvic_prioritygroup_3 is divided into 8 classes (1 classes are 1 preemption priorities), there are 2 classes (sub-priorities) within each class, and high-class people can interrupt low-class people who are doing things (nesting), Up to 1 interrupts and 7 levels of nesting can be completed.
Each class (each preemption priority), you designate the 43 people who enter the class; a man named Exti0_irqchannel, you designate him to enter "Class 3", then:
Nvic_initstructure.nvic_irqchannel = Exti0_irqchannel;
nvic_initstructure.nvic_irqchannelpreemptionpriority = 3; Specify preemption priority level 1, preferably 0-7
It is also necessary to designate his class:
nvic_initstructure.nvic_irqchannelsubpriority = 0; Specify the response priority level 0, preferably 0-1
Another 1 were called Exti9_5_irqchannel, and his class and class were set as follows
Nvic_initstructure.nvic_irqchannel = Exti9_5_irqchannel;
nvic_initstructure.nvic_irqchannelpreemptionpriority = 3; Specify preemption priority level 0, preferably 0-7
nvic_initstructure.nvic_irqchannelsubpriority = 1; Specify the response priority level 1
Then these two men are brothers of the same class, and while one is doing things, another cannot interrupt him; (preemption no nesting relationship between interrupt sources with the same priority level)
If they both want to do things at the same time, because the former class is high, so the former priority.
There is also a man named Usart1_irqchannel, whose class and class are set as follows
Nvic_initstructure.nvic_irqchannel = Usart1_irqchannel;
Nvic_initstructure.nvic_irqchannelpreemptionpriority = 2; Specify preemption priority level 0, preferably 0-7
nvic_initstructure.nvic_irqchannelsubpriority = 1; Specify the response priority level 1
Usart1_irqchannel has the highest priority and can break (nest) when the first two people do things.
The following analogy.
Reprint Address: Http://bbs.ednchina.com/BLOG_ARTICLE_3000747.HTM
STM32 NVIC's understanding