1. Preemption priority and response priority
The interrupt vector of STM32 has two attributes, one is the preemption attribute and the other is the response attribute.
The smaller the value, the higher its priority.
Preemption refers to the property of interrupting other interrupts. That is, because of this property, nested interrupts will occur (
interrupt B interrupts the execution of interrupt service function A, and then continues to execute interrupt service function B after executing interrupt service function A).
A), the preemption properties are configured by the NVIC_IRQChannelPreemptionPriority parameter.
The response attribute is applied when the preemption attribute is the same. When the preemption priority of two interrupt vectors is the same,
if the two interrupts arrive at the same time, the interrupt with higher response priority will be processed first. The response attribute is
configured by the NVIC_IRQChannelSubPriority parameter. For example, there are three interrupt vectors, as shown in the following table.
If the kernel is executing the interrupt service function of C, it can be interrupted by interrupt A with higher preemption priority. Since B
and C have the same preemption priority, C cannot be interrupted by B. But if B and C arrive at the same time, the kernel
will first respond to interrupt B with higher response priority.
2. NVIC priority group
When configuring the priority, we must pay attention to an important issue, that is, the number of interrupt types. NVIC
can configure 16 interrupt vector priorities, that is, the number of preemption priorities and response priorities
is determined by a 4-bit number, and the bits of this 4-bit number are allocated to the preemption priority part and the response priority part. There are 5 groups of
allocation methods:
Group 0: All 4 bits are used to configure the response priority. That is, the 16 interrupt vectors have different response priorities
.
Group 1: The highest bit is used to configure the preemption priority, and the lower 3 bits are used to configure the response priority. It means that there are 2
levels of preemption priority (level 0, level 1) and 8 response priorities. That is, among the 16 interrupt vectors, there are
8 interrupts whose preemption priority is level 0, and their response priorities are 0~7 respectively. The preemption priority of the remaining 8 interrupt
vectors is level 1, and the response priority level is 0~7 respectively.
Group 2: 2 bits are used to configure the preemption priority, and 2 bits are used to configure the response priority. That is, there are 4 preemption priorities
and 4 response priorities.
Group 3: The upper 3 bits are used to configure the preemption priority, and the lowest bit is used to configure the response priority. That is, there are 8 preemption
priorities and 2 response priorities.
Group 4: All 4 bits are used to configure the preemption priority, that is, the 16 interrupt vectors configured by NVIC have only
Preemptive attribute, no response attribute.
To configure these priority groups, you can use the library function NVIC_PriorityGroupConfig(), and the input parameters are NVIC_PriorityGroup_0 ~ NVIC_PriorityGroup_4, which are the 5 allocation groups introduced above.
So, some readers feel confused. For such a powerful STM32, all GPIOs can be configured as external interrupts, and peripherals such as USART and ADC also have interrupts, but NVIC can only configure 16 interrupt vectors. What should I do if more than 16 interrupts are used in a project? Note that NVIC can configure 16 interrupt vectors, not 16. When there are more than 16 interrupt vectors in a project, there must be more than two interrupt vectors that use the same interrupt type, and interrupt vectors with the same interrupt type cannot be nested with each other.
Previous article:Understanding interrupt priorities in STM32
Next article:STM32 library function learning chapter --- NVIC and external interrupt
- 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
- 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
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- There is a reason why the price of ceramic circuit board PCB substrate is high.
- ASML claims Chinese companies may infringe copyright, Chinese companies respond: key technologies are completely self-developed
- AD20 Select PCB Components cannot be used?
- Newly purchased MicroPython development board
- STM32F 7508DK I2C BH1570 driver development and I2C usage
- C2000 MCU, Vienna Rectifier-Based Three-Phase Power Factor Correction Reference Design
- The 5G era has arrived. This is a rare opportunity. What ideas do you have to share?
- General method of displaying pictures and texts on TFT color screen
- Motor inductance problem
- I need a simulation diagram of a car reversing radar system (paid)