2.2 The NVIC, interrupt state and execution priority
The NVIC is part of the PE’s System Control Space (SCS), at 0xE000E100 onward. It is not a separate distributor or redistributor. Each external interrupt has a bit or byte in these registers:
NVIC_ISERn/NVIC_ICERn: write 1 to enable or disable the interrupt. Reads return the enable state.NVIC_ISPRn/NVIC_ICPRn: write 1 to set or clear the pending state. Software can pend a disabled interrupt.NVIC_IABRn: read-only active bits.NVIC_IPRn: one priority byte per interrupt. Byte access works with the Main Extension; on Baseline parts such as Cortex-M23, use word accesses.NVIC_ITNSn(Security Extension): 1 targets the interrupt at Non-secure state. ITNS is RAZ/WI to Non-secure accesses, and in the other NVIC registers the bits of Secure-targeted interrupts are RAZ/WI from Non-secure state.
The system exceptions are controlled through the SCB instead: SHPRn sets priorities, SHCSR holds enables plus active and some pending bits, and ICSR holds PENDSVSET, PENDSTSET and similar bits.
No acknowledge or EOI step. Taking an exception moves it from pending to active automatically. The exception return deactivates it. For a level-sensitive source that is still asserted after the return, the NVIC sets the pending state again.
Execution priority is the highest of these:
- the group priority of every active exception;
PRIMASK = 1, which boosts the execution priority to 0 and so masks every configurable-priority exception;BASEPRI(Main Extension), whose non-zero value boosts the execution priority to that value.BASEPRI = 0has no effect;FAULTMASK = 1(Main Extension), which boosts it to -1. FAULTMASK is cleared on exception return, except on return from NMI.
With the Security Extension these masks are banked per Security state, the FAULTMASK and HardFault levels depend on AIRCR.BFHFNMINS, and AIRCR.PRIS changes how Non-secure priorities map. That detail is left out here.
Synchronisation: NVIC/SCS registers are accessed with loads and stores. To guarantee that a change (for example an ICER disable) is in effect for the instructions that follow it, issue DSB and then ISB. The DSB waits until the store has completed, and the ISB flushes the pipeline so that later instructions are fetched and executed under the new state. A DMB is not enough, because it only orders memory accesses against each other and does not wait for completion.
Coming from A-profile: With the GIC you read ICC_IAR to acknowledge an interrupt and write ICC_EOIR (and ICC_DIR when EOImode = 1) to finish it. On M-profile, exception entry and exception return do that work, so a handler is an ordinary AAPCS function with no interrupt-controller handshake.
Checkpoint
Q2.2.1 A handler for a level-sensitive peripheral interrupt returns without clearing the interrupt condition in the peripheral. What happens on Armv8-M?
- A. The interrupt stays active forever, blocking itself and lower priorities, because no EOI was written
- B. The interrupt is pending again after the return, so the handler runs again (often by tail-chaining), repeatedly while the line stays asserted
- C. Nothing, because NVIC interrupts are edge-triggered and the condition is ignored until a new edge
- D. A UsageFault is raised for returning with an unserviced interrupt
Answer
B. The exception return deactivates the interrupt. A level input that is still asserted then sets the pending state again, and the handler re-enters, often without any Thread-mode instruction executing in between. ‘Active forever’ is the GIC mental model where a missing EOI leaves the interrupt active, but M-profile has no EOI step.
Read more: Armv8-M ARM (DDI0553), NVIC: interrupt states; Exception return
Q2.2.2 Code in Thread mode on a Mainline core executes MOVS r0, #0; MSR BASEPRI, r0. What is the effect on interrupt masking?
- A. All configurable-priority exceptions are masked, because priority 0 is the highest
- B. Only exceptions with priority 0 are masked
- C. Nothing is masked, because BASEPRI = 0 disables the BASEPRI boost
- D. NMI and HardFault are also masked
Answer
C. A BASEPRI value of zero means no boost. Only a non-zero value raises the execution priority to that level. Masking everything configurable is the job of PRIMASK = 1, and only FAULTMASK reaches -1. FreeRTOS relies on this when it leaves a critical section by writing 0 to BASEPRI.
Read more: Armv8-M ARM (DDI0553), Special registers: BASEPRI, PRIMASK, FAULTMASK
Q2.2.3 IRQ 37 is pending but disabled. Software writes the IRQ’s bit in NVIC_ICER1, and later writes the same bit in NVIC_ISER1. What happens?
- A. The interrupt is taken once it is enabled (if priority allows), because writing ICER disables the interrupt but does not clear its pending state
- B. Nothing, because writing ICER also clears the pending bit
- C. The ISER write faults because the interrupt is still pending
- D. The interrupt is taken immediately when ICER is written
Answer
A. Enable and pending are independent state. ICER only clears the enable. Discarding a pending interrupt needs a write to ICPR, and for a level source the peripheral must also stop asserting the line, otherwise it pends again. Assuming ICER clears the pending state causes spurious interrupts when drivers re-enable an interrupt.
Read more: Armv8-M ARM (DDI0553), NVIC_ICERn, NVIC_ICPRn