I saw an explanation about stm32 nvic, which used the concepts of class and stratum. It was very vivid and easy to understand.
Link: http://blog.sina.com.cn/s/blog_5f17618501012rpp.html
NVIC——Nested Vectored Interrupt Controller
STM32 has 43 channel settable interrupt sources: AIRC (Application Interrupt and Reset Register) register has 4 bits for specifying priority. These 4 bits are used to assign pre-emption priority and sub priority, and are defined in the STM32 firmware library as follows:
//----------------------------------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 figurative understanding is: if you are God, you created 43 people, so many people need to be divided into social classes and social strata; because "class" has a stronger part of speech, and "stratum" is more neutral, so pre-emption priority -> class; within each class, there are some strata, sub priority -> stratum;
If we divide it according to NVIC_PriorityGroup_4, it will be divided into 16 classes, each class has 0 levels; people with higher classes can interrupt people with lower classes who are doing things (nesting), and can complete 1 interruption and 15 levels of nesting at most. For each class, you specify who among the 43 people enters the class;
A person is called EXTI0_IRQChannel, and you specify him to enter "class 8", then
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 8; //Specify preemptive priority level 1, can be 0-15
Within the same class, when one person is doing something, another person cannot interrupt him; (there is no nesting relationship between interrupt sources with the same pre-emption priority level). Also, if two of them want to do something at the same time, because there is no hierarchy, then according to the physical order in the Vector table, the person with the higher ranking will do it.
There is another SPI1_IRQChannel, set as follows
NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; //Specify preemptive priority level 1, can be 0-15
SPI1_IRQChannel is of a higher class, and EXTI0_IRQChannel can be interrupted (nested) while doing something.
If divided according to NVIC_PriorityGroup_3, it is divided into 8 classes (1 class is 1 preemption priority), and each class has 2 levels (sub-priority); people in the higher class can interrupt people in the lower class who are doing something (nesting), and can complete 1 interruption and 7 levels of nesting at most. For each class (each preemption priority), you specify who among the 43 people enters the class;
A person is called EXTI0_IRQChannel, and you specify that he enters "Class 3", then:
NVIC_InitStructure.NVIC_IRQChannel = EXTI0_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //Specify preemptive priority level 1, can be 0-7
You also need to specify his level:
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //Specify the response priority level 0, which can be 0-1
There is another person named EXTI9_5_IRQChannel, whose class and level are set as follows
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 3; //Specify preemptive priority level 0, can be 0-7
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //Specify response priority level 1
Then these two people are brothers of the same class. When one is doing something, the other cannot interrupt him (there is no nesting relationship between interrupt sources with the same preemption priority level). If they both want to do something at the same time, the former will take precedence because he is at a higher class.
There is another one called USART1_IRQChannel, whose class and hierarchy settings are as follows
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; //Specify preemptive priority level 0, can be 0-7
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; //Specify response priority level 1
USART1_IRQChannel has the highest priority. When the two people in front are doing something, it can interrupt (nest).
And so on: if it is divided according to NVIC_PriorityGroup_0, then there is no class, only 16 levels. Each person needs to be assigned a level number. The sub priority range is 0-15. When one person is doing something, others cannot interrupt him (no nesting); when multiple people want to do something at the same time, they will be sorted according to the level number, and the one with the higher ranking will do it first. If people with the same level number want to do something at the same time, they will be sorted according to the Vector Table hardware, and the one with the higher ranking will do it first.
Previous article:Use of stm32 serial port usart
Next article:Configuration of stm32 NVIC
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- Installation and sound source localization algorithm of a diamond microphone array
- How to start the design of adjustable voltage regulated power supply application
- Has anyone used the AT32F403 microcontroller? Is there any example program or something?
- A detail of MSP430 interrupt
- The upper limit for each mobile phone is US$2.5. How much 5G patent fees can Huawei collect?
- Schematic diagram of one-input and eight-output terminal block
- IEEE Top Programming Language Rankings 2021
- Tell us what information you need and we will serve you
- Why do we need to add an external EEPROM when using some MCUs?
- Tony teacher perfectly supports esp32-c3