Understand the interruption of the Cortex-M3 from the second function nvic_prioritygroupconfig ()

Source: Internet
Author: User

In the next line of the first function systeminit (), there will be another common function.Nvic_prioritygroupconfig (nvic_prioritygroup_x)(X indicates numbers 1, 2, 3 ...). This function is related to the interrupt configuration. It configures the interrupt priority, including the preemption priority and subpriority.

Introduction to Objective C (interrupt vector Controller) cannot be found in the stm32 reference manual. Need to seeAuthoritative guide to Cortex-M3This book focuses on the M3 kernel.Nvic is also in it, because it is a very important part of the kernel.

I read this book and have a detailed description of Objective C. I will go straight.

Register description for dealing with Objective C. To operate on Objective C, these registers need to be mastered, especially the four registers that require registration.

Interruption enabling and banning

In this case, the Cortex-M3 usedTwo Register ControlOne is responsible for enabling and disabling functions. Unlike some simple single-chip microcomputer, one bit can handle these two functions. The benefit of this function is security, so you don't have to worry about your misoperation.Because this register is valid for both write 1 and write 0. To enable a register, you need to write 1 to the Enable register, and 1 to the Enable register.

The following describes the suspension and unsuspension registers.


Interrupt priority

Each priority register of an External Interrupt occupies 8 bits,However, a minimum of three digits are allowed.If stm32 is used, a maximum of four bits are used.Four adjacent priority registers are combined into a 32-bit register. The interrupt priority is divided into preemption priority and subpriority. In stm32, the priority register contains fourThe higher two represents the preemption priority, and the lower two represents the subpriority.The preemption priority isInterrupt with low preemptible priority to implement interrupt nesting.

Let's take a look.Priority Distribution.


The following descriptionHow to determine the priority and nesting rules.


About thoseAnd interrupt registers to be mastered, There is also one:



The followingHow is an interruption created?:



Of course, there are some other interrupt-related registers, which are not very common and are not written here.

So nowSpecifically, this priority configuration functionFunction Definition implementation:

/**  * @brief  Configures the priority grouping: pre-emption priority and subpriority.  * @param  NVIC_PriorityGroup: specifies the priority grouping bits length.   *   This parameter can be one of the following values:  *     @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority  *                                4 bits for subpriority  *     @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority  *                                3 bits for subpriority  *     @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority  *                                2 bits for subpriority  *     @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority  *                                1 bits for subpriority  *     @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority  *                                0 bits for subpriority  * @retval None  */void NVIC_PriorityGroupConfig(uint32_t NVIC_PriorityGroup){  /* Check the parameters */  assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));    /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */  SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;}

In the original Misc. c file, this function has only two sentences. Where

assert_param(IS_NVIC_PRIORITY_GROUP(NVIC_PriorityGroup));

Assert_param is a defined macro used to check the correctness of expressions.. If the expression is correct, do nothing. Continue to execute the following statement. If the parameter is incorrect, an error is reported in the current row. This mainly checks whether the input priority of Objective C configuration is valid.

  /* Set the PRIGROUP[10:8] bits according to NVIC_PriorityGroup value */  SCB->AIRCR = AIRCR_VECTKEY_MASK | NVIC_PriorityGroup;

This statement is the key to implementing priority configuration. Aircr_vectkey_mask is equivalent to a key, and is implemented using a macro. Declared at the beginning of the source file. Its value is:

#define AIRCR_VECTKEY_MASK    ((uint32_t)0x05FA0000)

Because Objective C isA key register cannot be configured at will. Therefore, an input flag is required for correct configuration. This flag is equivalent to a key.. Among them, the nvic_prioritygroup value is the macro in the top of the function. There are five cases.

/**  * @brief  Configures the priority grouping: pre-emption priority and subpriority.  * @param  NVIC_PriorityGroup: specifies the priority grouping bits length.   *   This parameter can be one of the following values:  *     @arg NVIC_PriorityGroup_0: 0 bits for pre-emption priority  *                                4 bits for subpriority  *     @arg NVIC_PriorityGroup_1: 1 bits for pre-emption priority  *                                3 bits for subpriority  *     @arg NVIC_PriorityGroup_2: 2 bits for pre-emption priority  *                                2 bits for subpriority  *     @arg NVIC_PriorityGroup_3: 3 bits for pre-emption priority  *                                1 bits for subpriority  *     @arg NVIC_PriorityGroup_4: 4 bits for pre-emption priority  *                                0 bits for subpriority  * @retval None  */

Also found that there are many real-time systems are customized according to the Cortex-M3 kernel, presumably its strong Objective C is one of the reasons.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.