Exception Model
105
SLAU723A – October 2017 – Revised October 2018
Copyright © 2017–2018, Texas Instruments Incorporated
Cortex
®
-M4F Processor
•
The halfword instructions LDREXH and STREXH
•
The byte instructions LDREXB and STREXB
Software must use a Load-Exclusive instruction with the corresponding Store-Exclusive instruction.
To perform an exclusive read-modify-write of a memory location, software must:
1. Use a Load-Exclusive instruction to read the value of the location.
2. Modify the value, as required.
3. Use a Store-Exclusive instruction to try to write the new value back to the memory location.
4. Test the returned status bit.
If the status bit is clear, the read-modify-write completed successfully. If the status bit is set, no write
was performed, which indicates that the value returned at step 1 might be out of date. The software
must retry the entire read-modify-write sequence.
Software can use the synchronization primitives to implement a semaphore as follows:
1. Use a Load-Exclusive instruction to read from the semaphore address to check whether the
semaphore is free.
2. If the semaphore is free, use a Store-Exclusive instruction to write the claim value to the semaphore
address.
3. If the returned status bit from Step 2 indicates that the Store-Exclusive succeeded, then the software
has claimed the semaphore. However, if the Store-Exclusive instruction failed, another process might
have claimed the semaphore after the software performed Step 1.
The Cortex-M4F includes an exclusive access monitor that tags the fact that the processor has executed a
Load-Exclusive instruction. The processor removes its exclusive access tag if:
•
It executes a CLREX instruction.
•
It executes a Store-Exclusive instruction, regardless of whether the write succeeds.
•
An exception occurs, which means the processor can resolve semaphore conflicts between different
threads.
For more information about the synchronization primitive instructions, see the Cortex-M4 instruction set
chapter in the
Arm Cortex-M4 Devices Generic User Guide
.
1.6
Exception Model
The Arm Cortex-M4F processor and the NVIC prioritize and handle all exceptions in handler mode. The
processor state is automatically stored to the stack on an exception and automatically restored from the
stack at the end of the ISR. The vector is fetched in parallel to the state saving, enabling efficient interrupt
entry. The processor supports tail-chaining, which enables performance of back-to-back interrupts to be
performed without the overhead of state saving and restoration.
lists all exception types. Software can set eight priority levels on seven of these exceptions
(system handlers) as well as on interrupts (see
Priorities on the system handlers are set with the NVIC System Handler Priority n (SYSPRIn) registers.
Interrupts are enabled through the NVIC Interrupt Set Enable n (ENn) register and prioritized with the
NVIC Interrupt Priority n (PRIn) registers. Priorities can be grouped by splitting priority levels into
preemption priorities and subpriorities. All the interrupt registers are described in
.
Internally, the highest user-programmable priority (0) is treated as fourth priority, after a Reset,
Nonmaskable Interrupt (NMI), and a Hard Fault, in that order. The default priority is 0 for all the
programmable priorities.