In this lesson, you will learn to distinguish between synchronous exceptions and asynchronous interrupts, the two fundamental ways the ARM Cortex-M processor handles events that divert it from its main execution flow.
Synchronous Exceptions: The "Self-Inflicted" Events
A synchronous exception is directly tied to the specific instruction currently being executed by the CPU. Because it happens in direct response to the code, it is deterministic; if you run the same code under the same conditions, the exception will trigger at exactly the same point.
Common examples include:
- SVC (Supervisor Call): Triggered by an
SVCinstruction when your code intentionally requests a service from the OS or a higher-privileged level. - Faults: Triggered by invalid memory access or execution of an undefined instruction (e.g., trying to access memory that hasn't been mapped).
Because these occur during the execution of an instruction, the CPU handles them immediately before or during the instruction lifecycle to maintain state integrity.
Asynchronous Interrupts: The "External" Events
Asynchronous interrupts, often called IRQs (Interrupt Requests), are completely independent of what the processor is currently doing. They are triggered by external hardware peripherals—such as a timer expiring, a UART receiving a byte, or a GPIO pin changing state.
The processor does not know when an interrupt will arrive. From the perspective of the main program flow, the timing is essentially random. When an IRQ fires, the processor finishes the currently executing instruction and then pushes the current state onto the stack to jump to the Interrupt Service Routine (ISR).
Illustrative Comparison
| Feature | Synchronous (Exceptions) | Asynchronous (Interrupts) |
|---|---|---|
| Origin | Inside the processor (instruction) | Outside the processor (peripheral) |
| Predictability | High (follows the code path) | Low (event-driven) |
| Cause | Software faults or system calls | Hardware signals (e.g., Timer, I2C) |
Key Takeaway: Synchronous exceptions are predictable events triggered by the execution of a specific instruction, whereas asynchronous interrupts are unpredictable events triggered by external hardware signals that require immediate attention regardless of current software progress.