The Cortex-M4 processor
The pairs of Load-Exclusive and Store-Exclusive instructions are:
•
The word instructions LDREX and STREX
•
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 a guaranteed read-modify-write of a memory location, software must:
1.
Use a Load-Exclusive instruction to read the value of the location.
2.
Update the value, as required.
3.
Use a Store-Exclusive instruction to attempt to write the new value back to the memory
location.
4.
Test the returned status bit. If this bit is:
0: The read-modify-write completed successfully.
1: No write was performed. This indicates that the value returned at step 1 might be out
of date. The software must retry the read-modify-write sequence.
Software can use the synchronization primitives to implement a semaphores 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 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 failed,
another process might have claimed the semaphore after software performed step 1.
The Cortex-M4 includes an exclusive access monitor, that tags the fact that the processor
has executed a Load-Exclusive instruction. If the processor is part of a multiprocessor
system, the system also globally tags the memory locations addressed by exclusive
accesses by each processor.
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. This means the processor can resolve semaphore conflicts
between different threads.
In a multiprocessor implementation, executing a:
•
CLREX instruction removes only the local exclusive access tag for the processor.
•
Store-Exclusive instruction, or an exception, removes the local exclusive access tags,
and global exclusive access tags for the processor.
For more information about the synchronization primitive instructions, see
STREX on page 78
34/260
and
CLREX on page
DocID022708 Rev 6
79.
PM0214
LDREX and
Need help?
Do you have a question about the STM32F4 Series and is the answer not in the manual?
Questions and answers