A visual explanation of nvic in stm32

Publisher:JoyfulLifeLatest update time:2017-10-31 Source: eefocusKeywords:STM32  NVIC Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.


Keywords:STM32  NVIC Reference address:A visual explanation of nvic in stm32

Previous article:Use of stm32 serial port usart
Next article:Configuration of stm32 NVIC

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号