Understanding and use of STM32 interrupt priorities

Publisher:MysticJourneyLatest 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. Classification of interruptions:


   A global interrupt means that interrupt service can be executed immediately in any part of the running program. If an open interrupt instruction is added during the program interrupt, it means that when the conditions for the interrupt are met, the interrupt service can only be executed after the instruction to enable the interrupt is executed.


  External interrupts are maskable interrupts, that is, the interrupt controller can be used to mask the interrupt requests of these external devices.

  Internal interrupts refer to interrupts caused by hardware errors (such as sudden power failure, parity error, etc.) or calculation errors (division by zero, calculation overflow, single-step interrupt, etc.).



Each IO port of STM32F10 can be set as an external interrupt, up to 19 can be set, 16+3=19


When designing the hardware, be careful not to connect external interrupts to PA[1], PB1], PC[1], etc., because then the processor can only choose one as an interrupt source.


in addition: 


        EXTI line 16 is connected to the PVD output


        EXTI line 17 is connected to the RTC alarm event


        EXTI line 18 is connected to the USB wake-up event


        EXTI line 19 is connected to the Ethernet wake-up event



2. Interrupt Priority


The interrupt priority relationship of interrupt sources can be summarized into the following two basic principles:


(1) A low priority level can be interrupted by a high priority level, but a high priority level cannot be interrupted by a low priority level.


(2) Once any interrupt (whether high-level or low-level) is responded to, it will not be interrupted by an interrupt source of the same level.


In STM32, interrupts are configured with priority by group. Each interrupt priority group includes: preemptive priority and responsive priority. The former is the level division of preemptive priority, and the latter is the priority division of the same preemptive priority.

for example:

Interrupt A has a higher preemption priority than B, so A's interrupt can be triggered in B, ignoring the response priority;

If A and B have the same preemption priority, the response priority of A and B determines who responds first;


Let's first look at a picture of ST company:

According to NVIC_PriorityGroup_0, there is one preemption (priority) level, and each preemption (priority) level has only 16 sub-priorities: 0-15;


According to NVIC_PriorityGroup_1, there are 2 preemption (priority) levels, and each preemption (priority) level has only 8 sub-priorities: 0-7;


According to NVIC_PriorityGroup_2, there are 4 preemption (priority) levels, and each preemption (priority) level has only 4 sub-priorities: 0-3;


According to NVIC_PriorityGroup_3, there are 8 preemption (priority) levels, and each preemption (priority) level has only 2 sub-priorities: 0-1;


According to NVIC_PriorityGroup_4, there are 16 preemption (priority) levels, and each preemption (priority) level has only one sub-priority level: 0;

Learn with related programs


        /* Enable the USART1 Interrupt */Configure the driver part of the serial port interrupt

        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;   

        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1; //The preemptive priority is 0,

        NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; The responsive priority under the same preemptive priority cannot interrupt each other

        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; 

        NVIC_Init(&NVIC_InitStructure); 

       


/* SPI1-------------------------------------------------- -------------------------- */  

    NVIC_InitStructure.NVIC_IRQChannel = SPI1_IRQChannel;  

    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;  

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;  

    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;  

    NVIC_Init(&NVIC_InitStructure); 

      EXTI0_IRQChannel is a high-priority group of level 0 group > SPI's level 3 group, which can interrupt the lower-level group that is doing things (nested), so when SPI is working, EXTI0 can interrupt it and enter EXTI0 interrupt;

The configuration of each interrupt priority can be seen in the library file misc.h


When working with two serial ports at the same time, if you don't want them to be interrupted by each other, you can set their preemptive priorities to the same so that they will not affect each other. The same applies to other ports.


Keywords:STM32 Reference address:Understanding and use of STM32 interrupt priorities

Previous article:The concept of STM32F4 interrupt preemption priority and response priority
Next article:STM32 NVIC interrupt priority grouping description

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号