ARM Cortex-M processors (M0/M0+, M1, M3, M4, M7) use a unified exception mechanism to handle both faults generated by the core itself and external interrupt sources. Whenever something “disturbs” normal program flow—be it a reset, a peripheral interrupt, or an internal fault—the processor switches from Thread mode into Handler mode and vectors to the appropriate handler routine. In this article, we’ll walk through the basics of Cortex-M exceptions, distinguish system exceptions from interrupts, and see how they’re laid out in the vector table.
What Is an Exception?
“Exception” is the umbrella term for any event that forces the processor to halt normal execution and enter a privileged Handler mode. Cortex-M defines two broad categories:
-
System Exceptions are generated internally by the CPU core (e.g. reset, hard fault, SVC).
-
Interrupts originate from on-chip or external peripherals (e.g. timers, GPIO, UART).
In total there are 15 slots reserved for system exceptions (though only nine are implemented on most Cortex-M devices) and up to 240 external interrupt lines, for a combined potential of 255 exception vectors.
The 9 Implemented System Exceptions
| Exception Number | Name | Source / Trigger |
|---|---|---|
| 1 | Reset | Power-on or external reset pin |
| 2 | NMI | Non-maskable interrupt; cannot be disabled |
| 3 | HardFault | Fault escalated when no other handler applies |
| 4 | MemManage | MPU access violation |
| 5 | BusFault | Errant bus transaction (e.g. misaligned load/store) |
| 6 | UsageFault | Undefined instruction, division by zero, etc. |
| 11 | SVCall | SVC (supervisor call) instruction |
| 14 | PendSV | Software-triggered interrupt for context switching |
| 15 | SysTick | System timer periodic interrupt |
Exception Vector Table
At reset, the processor loads the Main Stack Pointer (MSP) from address 0x0000_0000, then reads the reset handler address from 0x0000_0004. Immediately following that in memory are the addresses for NMI, HardFault, and so on, one word per exception slot:
Peripherals provide their own IRQ lines beginning at exception number 16 (External IRQ0) up to whatever the SoC implements (e.g. up to IRQ81 on many STM32 parts).
Conclusion
The Cortex-M exception model unifies resets, fault conditions, and peripheral interrupts under a single vectored mechanism. Understanding the difference between system exceptions (reset, faults, SVC, PendSV, SysTick) and external interrupts—and how they map into the vector table—is fundamental for writing robust embedded software. In upcoming articles we’ll dive into how to configure priorities, write handlers for faults, and harness PendSV/SVC for RTOS task switching.
Written By: Musaab Taha
This article was improved with the assistance of AI.