Dual Stack mechanism of Cortex-M3

Source: Internet
Author: User

Dual Stack mechanism of Cortex-M3

The CM3 stack is divided into two types: the master stack and the process stack.

So, under what circumstances are these two stacks used?

At this time, let's take a look at the CONTROL register (CONTROL) of CM3: the CONTROL register is used to define the privileged level and to select the stack pointer currently used.

CONTROL [1]

In handler mode of Cortex-M3, CONTROL [1] is always 0. In thread mode, it can be 0 or 1.

This bit can be written only in privileged thread mode, and cannot be written in other cases. Change the Processor Model

Method: When an exception is returned, you can change the LR bit 2 to implement mode switching.

In the uC/OS-II is the LR bit 2 to switch the stack mode, in fact we also mentioned in the previous article, is the PendSV_Handler_Nosave in this command orr lr, LR, #0x04 assigns a bit of 2 to 1. In this way, the PSP is switched back when an exception is exited. Then, the task can be switched over.

The first action to respond to an exception is to automatically save the necessary part of the site: In turn, xPSR, PC, LR, R12, and R3-R0 are automatically pushed into the appropriate stack by the hardware: if the current code is using PSP when an exception is returned, press PSP to use the thread stack. Otherwise, press MSP to use the master stack.

Remember that the CPU will always use the primary stack (MSP) once the service is interrupted ).

UC/OS-II task, also known as its thread, using the stack is PSP, low-priority task to high-priority task switching is also completed by PSP.

When the developed program is relatively simple (CM3 does not run the system), only MSP can be used from start to end. At this time, you only need to ensure that a stack with a large capacity is opened, and then initialize the MSP to its top-this is also the most common practice of Single Chip Microcomputer Development.

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.