About the priority of stm32

Publisher:阳关三迭Latest update time:2015-06-12 Source: 51heiKeywords:stm32  priority Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I. Overview

STM32 currently supports a total of 84 interrupts (16 cores + 68 external), 16 levels
of programmable interrupt priority settings (only the upper 4 bits of the 8-bit interrupt priority setting) and 16 preemption priorities (because the preemption priority can be up to four digits).
First of all, the priority grouping is mainly to set the number of preemption priorities and response priorities.
Preemptive priority 0-15 is set according to the grouping (0 group 0) (1 group 0-1) (2 groups 0-3) (3 groups 0-7) (4 groups 0-15)
Response priority 0-15 is set according to the grouping (0 group 0-15) (1 group 0-7) (2 groups 0-3) (3 groups 0-1) (4 groups 0)
If it is preemption priority, it means the interrupt is not powerful. The response priority is for when two interrupts arrive at the same time, the higher one will be responded to first. If the two interrupt response priorities are the same, the one with the higher interrupt number will be responded to first 
.

2. Priority Judgment

There are two concepts of priority in STM32 (Cortex-M3) - preemptive priority and response priority. Some people call response priority "sub-priority" or "sub-priority". Each interrupt source needs to be assigned these two priorities.

An interrupt with a high preemptive priority can be responded to during the interrupt processing with a low preemptive priority, that is, interrupt nesting, or an interrupt with a high preemptive priority can nest an interrupt with a low preemptive priority.

When the preemptive priority of two interrupt sources is the same, there will be no nesting relationship between the two interrupts. When an interrupt arrives, if another interrupt is being processed, the later interrupt will have to wait until the previous interrupt is processed before it can be processed. If the two interrupts arrive at the same time, the interrupt controller decides which one to process first based on their response priority; if their preemptive priority and response priority are equal, it decides which one to process first based on their ranking order in the interrupt table.
3: Priority Grouping
Since each interrupt source needs to be assigned these two priorities, there needs to be a corresponding register bit to record the priority of each interrupt; in Cortex-M3, 8 bits are defined for setting the priority of the interrupt source. These 8 bits can be allocated in 8 ways in the interrupt priority grouping field of the NVIC Application Interrupt and Reset Control Register (AIRCR), as follows:

All 8 bits are used to specify the response priority
The highest 1 bit is used to specify the preemptive priority, and the lowest 7 bits are used to specify the response priority
The highest 2 bits are used to specify the preemptive priority, and the lowest 6 bits are used to specify the response priority
The highest 3 bits are used to specify the preemptive priority, and the lowest 5 bits are used to specify the response priority
The highest 4 bits are used to specify the preemptive priority, and the lowest 4 bits are used to specify the response priority
The highest 5 bits are used to specify the preemptive priority, and the lowest 3 bits are used to specify the response priority
The highest 6 bits are used to specify the preemptive priority, and the lowest 2 bits are used to specify the response priority
The highest 7 bits are used to specify the preemptive priority, and the lowest 1 bit is used to specify the response priority

This is the concept of priority grouping.

Cortex-M3 allows fewer interrupt sources to use fewer register bits to specify the priority of the interrupt source, so the STM32 reduces the register bits for specifying interrupt priority to 4 bits (the upper four bits of AIRCR). The grouping of these 4 register bits is as follows:

Group 0: All 4 bits are used to specify the response priority
Group 1: The highest 1 bit is used to specify the preemptive priority, and the lowest 3 bits are used to specify the response priority
Group 2: The highest 2 bits are used to specify the preemptive priority, and the lowest 2 bits are used to specify the response priority
Group 3: The highest 3 bits are used to specify the preemptive priority, and the lowest 1 bit is used to specify the response priority
Group 4: All 4 bits are used to specify the preemptive priority

You can choose which priority grouping method to use by calling the function NVIC_PriorityGroupConfig() in the STM32 firmware library. This function has the following five parameters:

NVIC_PriorityGroup_0 => Select Group 0
NVIC_PriorityGroup_1 => Select Group 1
NVIC_PriorityGroup_2 => Select Group 2
NVIC_PriorityGroup_3 => Select Group 3
NVIC_PriorityGroup_4 => Select Group 4

The interrupt priority grouping is to allocate the number of bits occupied by each priority number in the upper four bits of the interrupt priority register to the preemptive priority and response priority. It can only be set once in a program.

4: Interrupt source priority

The next step is to specify the priority of the interrupt source. The interrupt source priority is set in the interrupt priority register . Only the upper four bits can be set. The corresponding value must be set in the register according to the number of bits set in the interrupt priority group. If you choose the third group of the interrupt priority group: the highest 3 bits are used to specify the preemptive priority, and the lowest 1 bit is used to specify the response priority, then the preemptive priority has eight data options from 000-111, that is, there are eight interrupt nests, and the response priority has two types of 0 and 1, a total of 8*2=16 priorities.

The interrupt source priority specifically sets the priority level of the interrupt source.

Multiple (up to 16) priorities can be set in one program, but only one can be set for each interrupt source.

Every interrupt priority program must include the following two functions:

 

(1) void NVIC_PriorityGroupConfig(u32 NVIC_PriorityGroup) interrupt group setting

(2) void NVIC_Init(NVIC_InitTypeDef* NVIC_InitStruct) interrupt priority setting

Keywords:stm32  priority Reference address:About the priority of stm32

Previous article:Resistance frequency response test experiment
Next article:About the concept of stm32 timer master-slave mode

Recommended ReadingLatest update time:2024-11-16 13:56

stm32 variable type
During the stm32 programming process, variable types are often defined, and there is often a worry that the data will exceed the variable type range during the data operation. Because different CPUs have different meanings of data types during the programming process, you must pay attention to the definition and conve
[Microcontroller]
The real culprit of STM32 hardware error HardFault_Handler
There are two main reasons why the HardFault_Handler fault occurs in STM32: 1. Memory overflow or out-of-bounds access. 2. Stack overflow. The problem I encountered recently is stack overflow. The situation is as follows. Let me give you an example: static char data ; void fun1(unsigned char *buf) { int i=0; for(i=0
[Microcontroller]
STM32 standard project establishment
I have come across many STM32 projects, whether they come with the development board, from experts online, or from the official ones. To be honest, their project layouts are actually quite good, but after all, they are other people's projects, and I always feel a little unfamiliar when using them, and they always give
[Microcontroller]
STM32 standard project establishment
Getting Started with STM32 Function Library External Interrupts
      Without further ado, let me first take a look at the button schematic on my Alienware development board.         The board is lazy, or it is called making full use of the pull-up function of the IO port, and no common pull-up resistor is added here. When programming, just enable the pull-up of the IO~ Look a
[Microcontroller]
Getting Started with STM32 Function Library External Interrupts
Several implementation methods of STM32 running lights
#include “stm32f10x.h” void RCC_Configuration(void);//2 void GPIO_Configuration(void);//GPIO void Delay(u32 count) { u32 i=0; for(;i count;i++); } int main(void) { RCC_Configuration();//3 LED_Heat(); while(1) { GPIO_SetBits(GPIOA,GPIO_Pin_0); //The first light is on Delay(800000); //Delay GPIO_ResetBits(GPIO
[Microcontroller]
STM32 external interrupt and timer programming example
/*========================================================================================  *Name: main.c  *Function:   *Entry Parameters:  *illustrate:    *Example:    *Editor Time:      *========================================================================================*/ #include "stm32f10x.h" #include "1286
[Microcontroller]
Detailed explanation of stm32TIM output channel configuration
1. Enable TIM clock    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM*,ENABLE); 2. Basic settings    TIM_TimeBaseStructure.TIM_Period count value      TIM_TimeBaseStructure.TIM_Prescaler pre-division, this value + 1 is the divisor of the division    TIM_TimeBaseStructure.TIM_ClockDivision = 0 clock factor to be further des
[Microcontroller]
STM32 SPI receiving stuck problem
When calling the following SPI function during debugging, the following two problems were found: 1. If you set a breakpoint at the third line while (SPI_I2S_GetFlagStatus(SPI2, SPI_I2S_FLAG_RXNE) == RESET);, it will get stuck in this while statement and cause the watchdog to reset; 2. Running at full speed will tr
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号