Course: Computer Architectures
Source lesson: ARM Exceptions and Interrupts

Fault diagnosis

A handler reads a fault-status register to learn what happened and may read a fault-address register for a precise memory fault:

LDR r0, =FSRaddress
LDR r1, [r0]
TST r1, #mask

The source distinguishes several faults:

  • NMI: high-priority event such as a watchdog or voltage warning.
  • Hard Fault: serious fault or escalation when a specific handler cannot run.
  • Usage Fault: invalid instruction, invalid branch state, division by zero or unaligned access when trapping is enabled.
  • Bus Fault: invalid instruction/data bus access, stacking/unstacking failure, or forbidden peripheral access.
  • Memory Management Fault: violation of MPU access or execution permissions.

A precise fault can identify the offending address. An imprecise fault may be reported after the original access has completed, making the exact instruction harder to identify.

Supervisor calls

SVC is a deliberate software exception used to request a privileged operating-system service:

SVC #5

An SVC handler can find the request by:

  1. Testing bit 2 of LR to choose MSP or PSP.
  2. Reading the stacked PC at [stack,#24].
  3. Reading the halfword immediately before that PC.
  4. Extracting the low byte containing the SVC immediate.

The immediate value selects the requested service.

SysTick

SysTick is a 24-bit countdown timer that can generate periodic interrupts. It is useful for timing, alarms, and task switching.

Configuration sequence:

  1. Disable the timer.
  2. Write the interval to the reload register.
  3. Clear the current counter.
  4. Enable the clock, interrupt, and timer.

The timer has control/status, reload, current-value, and calibration registers. Writing to the current-value register clears the counter.

Retrieval questions

  • What does a fault-status register tell the handler? The cause bits for the exception.
  • Why does an SVC handler read [stack,#24]? That is the automatically stacked PC.
  • What happens when SysTick reaches zero? The counter reloads and can raise an interrupt if enabled.