Professional Documents
Culture Documents
Microprocessor Systems
Contents
2 Interrupt Configuration
3 Interrupt Handling
5 Interrupt Nesting
2/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Introduction
Interrupt
An interrupt causes deviation to the normal program execution
flow. Both hardware (e.g., external inputs or peripherals) as well as
software events can generate interrupts
3/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
4/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
5/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
6/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Cortex-M Microprocessor
SysTick
Reset
Processor Core
NVIC
...
Software Interrupts
...
{
Integrated
Peripherals ...
{
Interrupt
Configurable I/Os
7/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
8/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Priority Levels
Priority Bits Unused Bits
7 6 5 4 3 2 1 0
10/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Interrupt States
The execution of an ISR corresponding to a low priority interrupt
might be suspended due to the occurrence of a high priority
interrupt. This leads to different possible operating states.
• Active: The interrupt is in active state when it is being
serviced by the processor
• Inactive: No interrupt condition has been generated from the
corresponding interrupt source.
• Pending: The interrupt is waiting to be serviced by the
processor.
• Active and pending: An interrupt is being serviced by the
processor and there is a pending interrupt from the same
source.
11/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Interrupt Configuration
12/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
13/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Global Configuration
14/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
15/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Interrupt Masking
There are three different interrupt/exception masking special
registers in a Cortex-M processor:
1. Priority masking register (PRIMASK)
2. Fault mask register (FAULTMASK)
3. Base priority masking register (BASEPRI)
– These registers can only be accessed when the processor is
operating at privileged access level.
– On reset these registers are cleared to zero resulting in no
interrupt masking.
– These interrupt masking registers are accessed through special
register access instructions i.e. MSR and MRS.
16/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
PRIMASK Register
17/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
FAULTMASK Register
• It is a 1-bit register
• Setting FAULTMASK to 1 only allows reset and NMI but
masks the HardFault exception.
• It is effectively equivalent to setting the priority level of
current exception to -1.
• FAULTMASK can be used to suppress any bus faults.
• FAULTMASK is cleared automatically when returning from an
exception.
18/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
BASEPRI Register
19/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
FAULTMASK Reserved
31 7 5 0
Reserved
BASEPRI ...
31 7 0
Reserved
20/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
22/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Configuring an Interrupt
23/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Setting Up Interrupts
24/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
25/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Exception Handling
26/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
27/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
28/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
29/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
R2
R1
SP after
R0
interrupt
Stack empty
region
PC xPSR R0 R1 R2 R3 R12 LR
time
30/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Updating Registers
• SP: The stack pointer (either the MSP or the PSP) will be updated
to a new value during register stacking.
• xPSR: The least significant nine bits of xPSR (corresponding to the
interrupt program status register, IPSR) will be updated to the new
exception number.
• PC: The program counter will be updated to the exception handler
and starts fetching the service routine instructions from the location
of the exception handler.
• LR: The LR will be updated to a special value called EXC RETURN.
The least significant 4 bits (5 bits in case of Cortex-M4F processors)
of LR are used to provide exception return information.
• Some other NVIC related registers are also updated to active or
pending depending on the process of interrupt handling.
32/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
33/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
LR value Description
0xFFFFFFF1 Return from exception handler to handler mode.
0xFFFFFFF9 Return from exception handler to thread mode
and use main stack on return.
0xFFFFFFFD Return from exception handler to thread mode
and use process stack on return.
34/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
t1 t2 Time
Register Register
Stacking Unstacking
LR= LR= t3 t4
0xFFFFFFF9 0xFFFFFFF1
35/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
t1 t2
Time
Register Register
Stacking Unstacking
LR= LR= t3 t4
0xFFFFFFFD 0xFFFFFFF1
37/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Some of the instructions, which can be used for returning from ISR
are:
• POP instruction
• Load instruction with PC as the destination register
• Branch instruction with any register holding the label
Some of the microprocessors support special instructions for
returning from interrupts (for instance, 8051 has RETI instruction).
In the case of Cortex-M3, return from interrupt can be performed
using normal return instruction, allowing to implement the entire
interrupt service routine as a normal C function.
38/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Interrupt Latency
39/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
40/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Interrupt 1 Interrupt 2
Time
Conventional
Stacking ISR 1 Unstacking Stacking ISR 2 Unstacking
interrupt handling
Interrupt Tail-
Stacking ISR 1 ISR 2 Unstacking
tail-chaining chaining
41/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
42/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
43/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
44/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
45/47
Cortex-M Exceptions & Interrupts Interrupt Configuration Interrupt Handling Interrupt Tail Chaining Interrupt Nesting
Interrupt 1
Time
Pending
status
Active
status
Processor
Stacking ISR 1 Unstacking
execution
Handler mode
47/47