SoC
  • Home
  • Arm
  • Arm Cortex M0/M0+
  • Arm Cortex M4
  • Arm Cortex M3
  • Contact
Reading: What is a Non-Maskable Interrupt (NMI) in ARM?
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 is a Non-Maskable Interrupt (NMI) in ARM?

Ryan Ryan
Last updated: September 12, 2023 1:35 pm
Ryan Ryan 5 Min Read
Share
SHARE

A non-maskable interrupt (NMI) in ARM is a hardware interrupt that cannot be ignored or disabled by software. It is typically used to signal critical system errors that require immediate attention from the processor. NMIs have the highest priority among all interrupts in ARM systems.

Contents
Overview of Interrupts in ARMKey Characteristics of NMITypical Uses of NMINMI Handling ProcessNMI Handler CodeEnabling NMI on ARM Cortex-MResponding to NMI on ARM Cortex-ASummary

Overview of Interrupts in ARM

Interrupts allow external events to interrupt normal program execution in a processor like ARM. When an interrupt occurs, the processor halts execution of the current program, saves its state, and runs an interrupt handler routine. After the handler finishes, the processor restores the state and resumes the original program.

There are three main types of interrupts in ARM:

  • IRQ – Normal interrupt request generated by peripherals/devices
  • FIQ – Fast interrupt request for time critical events
  • NMI – Non-maskable interrupt that cannot be ignored

Both IRQ and FIQ can be disabled/masked by setting bits in the CPSR (Current Program Status Register). But NMI is always enabled.

Key Characteristics of NMI

The key characteristics of NMI in ARM are:

  • Cannot be ignored – NMIs cannot be disabled or masked by software. The NMI pin is typically connected to critical system circuits.
  • Highest priority – NMI has higher priority than any other interrupt. NMIs preempt both IRQ and FIQ.
  • Reserved vector – Each NMI has a reserved exception vector. This ensures quick processing without vector arbitration.
  • Minimal context saving – Only minimal processor context is stored, allowing fastest possible handling.
  • Precise exceptions – NMIs are precise, meaning the instruction causing the NMI is not allowed to complete.

Typical Uses of NMI

Here are some typical uses of NMI in ARM systems:

  • Signaling system failures – NMI is used to signal catastrophic failures like memory errors, bus errors, or power failures.
  • Debugging – Debuggers can leverage NMI to halt the system immediately.
  • Profiling – Using the NMI for accurate profiling and instrumentation of the system.
  • Critical interrupts – Hard real-time systems often use NMI for their most critical interrupt routines.

NMI Handling Process

When an NMI occurs in an ARM system, the following sequence of events happens:

  1. The NMI exception is recognized after completion of the current instruction.
  2. Processor state is saved to banked registers (R13, R14). Only minimal context is saved.
  3. The processor selects the NMI exception vector using the reserved NMI interrupt number.
  4. Execution begins at the NMI interrupt vector.
  5. The NMI handler runs to completion. It has unrestricted access to the system.
  6. The saved banked registers are restored once the handler finishes.
  7. Processor execution resumes from the point after NMI recognition.

NMI Handler Code

The NMI handler code resides at the NMI exception vector. It should have the following structure:


@ Function name for disassembly
NMI_Handler:

  // Save remaining context if needed

  // Process NMI source

  // Clear source if needed

  // Restore context if changed

  // Return from exception

The key steps are:

  • Save any additional context not already saved by hardware.
  • Check source of NMI using system registers.
  • Take appropriate action based on NMI source.
  • Clear the source if needed, so NMI is not retriggered.
  • Restore any context that was modified.
  • Execute exception return instruction to resume execution.

Enabling NMI on ARM Cortex-M

On ARM Cortex-M processors, the NMI is enabled by setting the Non-Maskable Interrupt Enable bit in the Program Status Register (PRIMASK).


// Enable NMI
__disable_irq(); 
PRIMASK = 0;
__enable_irq();

By default, the PRIMASK bit is set to 1 on reset, so NMI is initially disabled. The NMI enable only lasts for the duration of critical code. PRIMASK should be re-enabled after to block NMIs again.

Responding to NMI on ARM Cortex-A

On ARM Cortex-A series application processors, the Generic Interrupt Controller (GIC) is used to handle interrupts.

To enable the NMI:


// Configure NMI as non-maskable
GIC_Write_ICENABLERn(0, 1 << NMI_interrupt); 

// Set priority
GIC_Set_Priority(NMI_interrupt, 0x01);

The NMI handler can read the Interrupt Acknowledge register to determine the source:


NMI_Source = GIC_Read_Interrupt_Acknowledge();

// Take action based on NMI_Source

Summary

In summary, NMI is a critical, high priority interrupt in ARM systems that cannot be ignored or disabled by software. It is typically used to handle catastrophic events and system failures. NMI handlers follow a special low-latency process to respond within minimal cycles. Both Cortex-M and Cortex-A series processors provide mechanisms to leverage NMI for time-critical interrupts.

Newsletter Form (#3)

More ARM insights right in your inbox

 


Share This Article
Facebook Twitter Email Copy Link Print
Previous Article What is Single Instruction Multiple Data (SIMD) in ARM Neon?
Next Article How many different priority levels are there for the Cortex-M4?
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

Merging FPGA bitstream with Cortex-M1 application hex file

When working with certain ARM Cortex-M1 microcontrollers that have an…

5 Min Read

Implementing Floating Point Math on Cortex-M3

The Cortex-M3 processor provides hardware support for single precision floating…

11 Min Read

Cortex-M Exception Handling and Return Mechanism

The Cortex-M processor implements robust exception handling capabilities to respond…

6 Min Read

Understanding FreeRTOS Context Switch Time

FreeRTOS is a popular real-time operating system (RTOS) used in…

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

Sign in to your account