STM32 preemption priority and response priority

Publisher:电子艺术大师Latest update time:2018-05-30 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Keywords:STM32 Reference address:STM32 preemption priority and response priority

Previous article:Understanding interrupt priorities in STM32
Next article:STM32 library function learning chapter --- NVIC and external interrupt

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号