SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: What are the operating modes of the Arm Cortex-M4?
SUBSCRIBE
SoCSoC
Font ResizerAa
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Search
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
Have an existing account? Sign In
Follow US
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
© S-O-C.ORG, All Rights Reserved.
Arm

What are the operating modes of the Arm Cortex-M4?

Holly Lindsey
Last updated: October 5, 2023 9:56 am
Holly Lindsey 6 Min Read
Share
SHARE

The Arm Cortex-M4 processor has multiple operating modes to provide different levels of access and control over system resources. The main operating modes are Thread mode, Handler mode, and Privileged mode. Additionally, the Cortex-M4 implements the Fault exceptions model which allows fast exception handling for common fault conditions.

Contents
Thread ModeHandler ModePrivileged ModeFault Exceptions ModelContext SwitchingInter-mode CommunicationPrivileged Access ControlSummary

Thread Mode

Thread mode is the primary operating mode where most application code executes. In Thread mode, the processor has limited access to system resources and peripherals. Thread mode provides unprivileged access and is mainly used to execute non-privileged background tasks and applications.

The key features of Thread mode are:

  • Used to execute non-privileged background tasks and applications
  • Provides unprivileged access to system resources
  • Cannot access system control registers directly
  • Can only execute unprivileged instructions
  • Uses MSP (main stack pointer) for function calls and returns

When executing in Thread mode, the processor cannot access protected system resources directly. Any attempt to execute a privileged instruction will trigger a fault exception and switch to Handler mode.

Handler Mode

Handler mode is used to handle exceptions and interrupts. When an exception occurs, like an access violation or divide by zero, the processor switches from Thread mode to Handler mode to quickly handle the exception.

The key features of Handler mode are:

  • Used to handle exceptions and interrupts
  • Automatically entered on exceptions
  • Can access full Cortex-M4 resources
  • Uses MSP (main stack pointer) for function calls
  • Returns to original context on completion

In Handler mode, the processor has full access to the Cortex-M4 resources to handle the exception condition. This includes system control registers and privileged instructions. Once the exception is handled, the processor returns to the original context in Thread mode.

Privileged Mode

Privileged mode provides full unrestricted access to all Cortex-M4 resources. This mode is reserved for privileged system level code like the OS kernel.

The key features of Privileged mode are:

  • Provides full unrestricted access to all resources
  • Used for privileged system level code
  • Accessed using privileged instructions
  • Uses PSP (process stack pointer) for function calls
  • Often requires context switch on entry/exit

Since Privileged mode provides complete access, switching to this mode usually requires a context switch to change stack pointers and registers. This mode allows privileged code to access protected system resources for implementing OS functionality.

Fault Exceptions Model

The Cortex-M4 implements the Fault exceptions model to provide fast exception handling for common fault conditions. This allows frequently occurring exceptions like access violations to be handled efficiently.

The key fault exceptions are:

  • HardFault – For undefined instructions and more serious faults
  • MemManage – On MPU memory access violations
  • BusFault – On bus errors during memory or peripheral access
  • UsageFault – On illegal use of instructions
  • DebugMonitor – When debug is enabled, allows debugger to gain control

These fault exceptions have priority over normal interrupts. When a fault occurs, the processor immediately enters Handler mode, pushes registers to the stack, and executes the fault exception handler. This simplifies and speeds up handling common fault conditions.

Context Switching

Switching between different operating modes requires context switching to change stack pointers and save processor state information. This is done using special exception entry and return mechanisms.

On an exception entry:

  • Processor pushes registers to stack
  • Changes to Handler mode and MSP stack
  • Jumps to exception handler

On exception return:

  • Stack and registers restored
  • Returns to previous Thread mode context

These mechanisms allow fast switching between Thread mode and Handler mode on exceptions. Switching to Privileged mode requires more complex context switching to change stack pointers and save additional state.

Inter-mode Communication

The Cortex-M4 provides mechanisms for communication between different modes using SVCall and PendSV exceptions.

  • SVCall – Allows switching from Thread to Handler mode on SW request
  • PendSV – Triggers context switch from Handler to Thread mode

This allows Thread mode code to make OS service calls using SVCall, which results in a context switch to Handler mode. The OS can then perform inter-thread communication and use PendSV to return to Thread mode.

Privileged Access Control

The Memory Protection Unit (MPU) and Protected Register Access (PRAc) controls provide configurable privileged access control to resources.

Key features include:

  • MPU – To control access permissions for up to 16 memory regions
  • PRAc – To configure privileged access to peripherals and registers
  • Different privilege levels for unprivileged Thread mode and privileged Handler/Privileged modes

This allows system designers to implement schemes for protecting and partitioning resources between different execution contexts based on privilege levels.

Summary

The Cortex-M4 operating modes provide a layered privilege architecture to securely separate application and system level code. Thread mode executes non-privileged code with limited access. Handler mode enables fast exception handling. Privileged mode runs fully trusted system code. The MPU and PRAC add further access control capabilities.

Overall, these features allow system designers to implement complex mixed-criticality applications with both security and real-time performance.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article How many different priority levels are there for the Cortex-M4?
Next Article Can ARM Cortex Run Linux?
Leave a comment Leave a comment

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

2k Followers Like
3k Followers Follow
10.1k Followers Pin
- Sponsored-
Ad image

You Might Also Like

Cortex-M1 integration into Pynq overlay and Python

The Cortex-M1 is an ARM processor designed for embedded and…

6 Min Read

When was ARM microcontroller invented?

The ARM microcontroller was first invented in the mid 1980s…

8 Min Read

Demystifying Arm’s Branch and Link Instructions (BL and BLX)

The Arm architecture includes two important branch and link instructions…

9 Min Read

How Instructions are Fetched in Cortex M Processors?

Overview of Instruction Fetch in Cortex M The IFU fetches…

7 Min Read
SoCSoC
  • Looking for Something?
  • Privacy Policy
  • About Us
  • Sitemap
  • Contact Us
Welcome Back!

Sign in to your account