pm0223 stm32 Cortexm0 Mcus Programming Manual Stmicroelectronics
pm0223 stm32 Cortexm0 Mcus Programming Manual Stmicroelectronics
Programming manual
Introduction
This programming manual provides information for application and system-level software developers. It gives a full description
of the programming model, instruction set, and core peripherals of the Cortex® M0+ processor.
Cortex®-M0+ is a high performance 32-bit processor designed for integration in microcontrollers. It offers significant benefits to
developers, including:
• Outstanding processing performance combined with fast interrupt handling
• Enhanced system debug with extensive breakpoint options
• Efficient processor core, system, and memories
• Ultralow power consumption with integrated sleep modes
• Platform security
Type Products
This document provides the information required for application and system-level software development. It does
not provide information on debug components, features, or operation.
This material is for microcontroller software and hardware engineers, including those who have no experience of
Arm®.
Note: Arm is a registered trademark of Arm Limited (or its subsidiaries) in the US and/or elsewhere.
Highlights important notes, introduces special terminology, denotes internal cross-references, and
italic
citations.
Highlights interface elements, such as menu names. Denotes signal names. Also used for terms in
bold
descriptive lists, where appropriate.
Denotes text that the user can enter at the keyboard, such as commands, file and program names, and
monospace
source code.
Denotes a permitted abbreviation for a command or option. The user can enter the underlined text
monospace
instead of the full command or option name.
monospace italic Denotes arguments to monospace text where the argument is to be replaced by a specific value.
monospace bold Denotes language keywords when used outside example code.
Enclose replaceable terms for assembler syntax where they appear in code or code fragments. For
< and > example:
LDRSB<cond> <Rt>, [<Rn>, #<offset>]
read/write (rw) The software can read and write to these bits.
read-only (r) The software can only read these bits.
The software can only write to this bit.
write-only (w)
Reading the bit returns the reset value.
The software can read as well as set this bit.
read/set (rs)
Writing '0' has no effect on the bit value.
read/clear (rc_w) The software can read as well as clear this bit by writing any value.
The software can read as well as clear this bit by writing 1.
read/clear (rc_w1)
Writing '0' has no effect on the bit value.
The software can read as well as clear this bit by writing 0.
read/clear (rc_w0)
Writing '1' has no effect on the bit value.
toggle (t) The software can only toggle this bit by writing '1'. Writing '0' has no effect.
Reserved (Res.) Reserved bit, must be kept at reset value.
Cortex-M0+ Components
Cortex-M0+ Processor
Interrupts Debug
Nested
Breakpoint
Vectored Cortex-M0+ Micro Trace
&
Interrupt processor Buffer
Watchpoint
Controller core (MTB)
Units
(NVIC)
Memory Debugger
Protection interface
Unit (MPU)
Debug
Access
Bus matrix Port
AHB-Lite
Serial-Wire
DT33821V1
Low-latency
interface peripheral I/O port debug port
to system
The Cortex®-M0+ processor is built on a 32-bit processor core that is highly optimized for area and power, with a
2-stage pipeline Von Neumann architecture. The processor delivers exceptional energy efficiency through a small
but powerful instruction set and extensively optimized design, providing high-end processing hardware including a
single-cycle multiplier.
The Cortex®-M0+ processor implements the ARMv6-M architecture, which is based on the 16-bit Thumb®
instruction set and includes Thumb-2 technology. This provides the exceptional performance expected of a
modern 32-bit architecture, with a higher code density than other 8-bit and 16-bit microcontrollers.
The Cortex®-M0+ processor closely integrates a configurable nested vectored interrupt controller (NVIC), to
deliver industry-leading interrupt performance. The NVIC:
• Includes a non-maskable interrupt (NMI).
• Provides zero jitter interrupt option.
• Provides four interrupt priority levels.
The tight integration of the processor core and NVIC provides fast execution of interrupt service routines (ISRs),
dramatically reducing the interrupt latency. This is achieved through the hardware stacking of registers, and the
ability to abandon and restart load-multiple and store-multiple operations. Interrupt handlers do not require any
assembler wrapper code, removing any code overhead from the ISRs. Tail-chaining optimization also significantly
reduces the overhead when switching from one ISR to another.
To optimize low-power designs, the NVIC integrates with the sleep modes that include a deep-sleep function that
enables the entire device to be rapidly powered down.
System timer
The system timer, SysTick, is a 24-bit count-down timer. Use this as a real time operating system (RTOS) tick
timer or as a simple counter.
I/O port
The I/O port provides single-cycle loads and stores to tightly coupled peripherals.
2 Cortex®-M0+ processor
Thread mode Executes application software. The processor enters thread mode when it comes out of reset.
Handler mode Handles exceptions. The processor returns to thread mode when it has finished all exception processing.
The software:
• Has limited access to system registers using the MSR and MRS instructions, and cannot use the CPS
Unprivileged instruction to mask interrupts.
• Cannot access the system timer, NVIC, or system control block.
• Might have restricted access to memory or peripherals.
The software can use all the instructions and has access to all resources. Privileged software executes at the
Privileged
privileged level.
In thread mode, the CONTROL register controls whether software execution is privileged or unprivileged, see
CONTROL register. In Handler mode, software execution is always privileged.
Only privileged software can write to the CONTROL register to change the privilege level for software execution
in thread mode. Unprivileged software can use the SVC instruction to make a supervisor call to transfer control to
privileged software.
2.1.2 Stacks
The processor uses a full descending stack. This means that the stack pointer indicates the last stacked item on
the stack memory. When the processor pushes a new item onto the stack, it decrements the stack pointer and
then writes the item to the new memory location. The processor implements two stacks, the main stack and the
process stack, with independent copies of the stack pointer, see Stack pointer.
In thread mode, the CONTROL register controls whether the processor uses the main stack or the process stack,
see CONTROL register. In handler mode, the processor always uses the main stack. The options for processor
operations are:
Table 2. Summary of processor mode, execution privilege level, and stack use options
Processor mode Used to execute Privilege level for software execution Stack used
R0
R1
R2
Low R3
registers R4
R5
R6 General purpose registers
R7
R8
High R9
registers R10 Banked stack pointers
R11
R12
Active Stack Pointer SP (R13) PSP MSP
Link Register LR (R14)
Program Counter PC (R15)
PSR Program Status Register
PRIMASK Interrupt mask register Special registers
CONTROL Control Register
DT33822V1
Table 3. Core register set summary
1. Describes access type during program execution in thread mode and handler mode. Debug access can differ.
2. Bit[24] is the T-bit and is loaded from bit[0] of the reset vector.
Stack pointer
The stack pointer (SP) is register R13. In thread mode, bit[1] of the CONTROL register indicates the stack pointer
to use:
• 0 = Main Stack Pointer (MSP). This is the reset value.
• 1 = Process Stack Pointer (PSP).
On reset, the processor loads the MSP with the value from address 0x00000000.
Link register
The link register (LR) is register R14. It stores the return information for subroutines, function calls, and
exceptions. On reset, the LR value is unknown.
Program counter
The program counter (PC) is register R15. It contains the current program address. On reset, the processor loads
the PC with the value of the reset vector, which is at address 0x00000004. Bit[0] of the value is loaded into the
EPSR T-bit at reset and must be 1.
31 30 29 28 27 25 24 23 6 5 0
APSR N Z C V Reserved
DT33823V1
Access these registers individually or as a combination of any two or all three registers, using the register name
as an argument to the MSR or MRS instructions. For example:
• Read all of the registers using PSR with the MRS instruction.
• Write to the APSR using APSR with the MSR instruction.
The PSR combinations and attributes are:
1. Reads of the EPSR bits return zero, and the processor ignores writes to these bits.
2. The processor ignores writes to the IPSR bits.
See the instruction descriptions Section 3.7.6 MRS and Section 3.7.7 MSR for more information about how to
access the program status registers.
See Section 3.3.6 Conditional execution for more information about the APSR negative, zero, carry or borrow,
and overflow flags.
[31:6] - Reserved
This is the number of the current exception:
0 = Thread mode.
1 = Reserved.
2 = NMI.
3 = HardFault.
4-10 = Reserved.
11 = SVCall.
12, 13 = Reserved.
[5:0] Exception number
14 = PendSV.
15 = SysTick | Reserved.
16 = IRQ0.
.
.
47 = IRQ31.
48-63 = Reserved.
see Section 2.3.2 Exception types for more information.
[31:25] - Reserved.
[24] T Thumb state bit.
[23:0] - Reserved.
Attempts by application software to read the EPSR directly using the MRS instruction always return zero. Attempts
to write the EPSR using the MRS instruction are ignored. Fault handlers can examine the EPSR value in the
stacked PSR to determine the cause of the fault. See Section 2.3.6 Exception entry and return. The following can
clear the T bit to 0:
• Instructions BLX, BX, and POP{PC}.
• Restoration from the stacked xPSR value on an exception return.
• Bit[0] of the vector value on an exception entry.
Attempting to execute instructions when the T bit is 0 results in a HardFault or lockup. See Section 2.4.1 Lockup
for more information.
Interruptible-restartable instructions
The interruptible-restartable instructions are LDM and STM, PUSH, POP, and MULS. When an interrupt occurs
during the execution of one of these instructions, the processor abandons execution of the instruction. After
servicing the interrupt, the processor restarts execution of the instruction from the beginning.
[31:1] - Reserved.
Prioritizable interrupt mask:
[0] PM 0 = No effect.
1 = Prevents the activation of all exceptions with configurable priority.
CONTROL register
The CONTROL register controls the stack used, and the privilege level for software execution, when the
processor is in thread mode. See the register summary in Table 3. Core register set summary for its attributes.
The bit assignments are:
31 2 1 0
Reserved
SPSEL
DT33824V1
nPRIV
[31:2] - Reserved.
Defines the current stack:
0 = MSP is the current stack pointer.
[1] SPSEL
1 = PSP is the current stack pointer.
In Handler mode this bit reads as zero and ignores writes.
Defines the thread mode privilege level:
[0] nPRIV 0 = Privileged.
1 = Unprivileged.
Handler mode always uses the MSP, so the processor ignores explicit writes to the active stack pointer bit of the
CONTROL register when in Handler mode. The exception entry and return mechanisms automatically update the
CONTROL register.
In an OS environment, it is recommended that threads running in thread mode use the process stack and the
kernel and exception handlers use the main stack.
By default, thread mode uses the MSP. To switch the stack pointer used in thread mode to the PSP, use the MSR
instruction to set the active stack pointer bit to 1, Section 3.7.6 MRS
Note: When changing the stack pointer, software must use an ISB instruction immediately after the MSR instruction.
This ensures that instructions after the ISB execute using the new stack pointer. See Section 3.7.5 ISB.
0xFFFFFFFF
Device 511MB
0xE0100000
0xE00FFFFF
Private peripheral bus 1MB
0xE0000000
0xDFFFFFFF
0xA0000000
0x9FFFFFFF
0x60000000
0x5FFFFFFF
Peripheral 0.5GB
0x40000000
0x3FFFFFFF
SRAM 0.5GB
0x20000000
0x1FFFFFFF
Code 0.5GB
0x00000000
DT33825V1
The processor reserves regions of the private peripheral bus (PPB) address range for core peripheral registers,
see Section 1.3 About the Cortex® M0+ processor and core peripherals.
Normal The processor can re-order transactions for efficiency, or perform speculative reads.
The processor preserves transaction order relative to other transactions to Device or Strongly-ordered
Device
memory.
Strongly-ordered The processor preserves transaction order relative to all other transactions.
The different ordering requirements for device and Strongly ordered memory mean that the memory system can
buffer a write to device memory, but must not buffer a write to Strongly ordered memory.
The additional memory attributes include.
For a shareable memory region, the memory system provides data synchronization between bus masters in a
system with multiple bus masters, for example, a processor with a DMA controller.
Strongly-ordered memory is always shareable.
Shareable If multiple bus masters can access a non-shareable memory region, software must ensure data coherency
between the bus masters.
<This description is required only if the device is likely to be used in systems where memory is shared
between multiple processors.>
Execute Means the processor prevents instruction accesses. A HardFault exception is generated on executing an
Never (XN) instruction fetched from an XN region of memory.
Normal access - - - -
DT33826V1
• - means that the memory system does not guarantee the ordering of the accesses.
• < means that accesses are observed in program order, that is A1 is always observed before A2.
0x20000000- Executable region for data. The user can also put
SRAM Normal -
0x3FFFFFFF code here.
0x40000000-
Peripheral Device XN External device memory.
0x5FFFFFFF
0x60000000-
External RAM Normal - Executable region for data.
0x9FFFFFFF
0xA0000000-
External device Device XN External device memory.
0xDFFFFFFF
This region includes the NVIC, System timer, and
0xE0000000- Private Peripheral Strongly-
XN System Control Block.
0xE00FFFFF Bus ordered
Only word accesses can be used in this region.
For further information, see Section 2.2.1 Memory regions, types, and attributes
The code, SRAM, and external RAM regions can hold programs.
The MPU can override the default memory access behavior described in this section. For more information, see
Section 4.5 Memory protection unit.
2.2.4 Additional memory access constraints for caches and shared memory
When a system includes caches or shared memory, some memory regions have additional access constraints,
and some regions are subdivided, as Table 11. Memory region shareability and cache policies shows:
Note:
For further information on memory types and shareability, see Section 2.2.1 Memory regions, types, and
attributes.
Cache policy: T = Write through, no write allocate. WBWA = Write back, write allocate.
The Data Memory Barrier (DMB) instruction ensures that outstanding memory transactions complete before
DMB
subsequent memory transactions. See Section 3.7.3 DMB.
The Data Synchronization Barrier (DSB) instruction ensures that outstanding memory transactions complete before
DSB
subsequent instructions execute. See Section 3.7.4 DSB.
The Instruction Synchronization Barrier (ISB) ensures that the effect of all completed memory transactions is
ISB
recognizable by subsequent instructions. See Section 3.7.5 ISB.
If the program changes an entry in the vector table, and then enables the corresponding exception, use
Vector table a DMB instruction between the operations. This ensures that if the exception is taken immediately after
being enabled the processor uses the new exception vector.
If a program contains self-modifying code, use an ISB instruction immediately after the code
Self-modifying code
modification in the program. This ensures subsequent instruction execution uses the updated program.
Memory map If the system contains a memory map switching mechanism, use a DSB instruction after switching the
switching memory map. This ensures subsequent instruction execution uses the updated memory map
Use a DSB followed by an ISB instruction or exception return to ensure that the new MPU configuration
MPU programming
is used by subsequent instructions.
If the program updates the value of the VTOR, use a DMB instruction to ensure that the new vector
VTOR programming
table is used for subsequent exceptions.
Memory accesses to strongly ordered memory, such as the system control block, do not require the use of DMB
instructions.
Little-endian format
In little-endian format, the processor stores the least significant byte (lsbyte) of a word at the lowest-numbered
byte, and the most significant byte (msbyte) at the highest-numbered byte. For example:
Memory Register
7 0
31 24 23 16 15 8 7 0
Address A B0 lsbyte B3 B2 B1 B0
A+1 B1
A+
B2
2
A+
B3 msbyte
3
DT33827V1
An interrupt request from a peripheral or from software can change the state of the corresponding interrupt to
pending.
An exception that is being serviced by the processor but has not completed.
Active An exception handler can interrupt the execution of another exception handler. In this case both exceptions
are in the active state.
Active and
The exception is being serviced by the processor and there is a pending exception from the same source.
pending
Reset is invoked on power-up or a warm reset. The exception model treats reset as a special form of exception.
When reset is asserted, the operation of the processor stops, potentially at any point in an instruction. When
Reset
reset is deasserted, execution restarts from the address provided by the reset entry in the vector table.
Execution restarts as privileged execution in thread mode.
A Non-Maskable Interrupt (NMI) can be signaled by a peripheral or triggered by software. This is the highest
priority exception other than reset. It is permanently enabled and has a fixed priority of -2. NMIs cannot be:
NMI
• Masked or prevented from activation by any other exception.
• Preempted by any exception other than Reset.
A HardFault is an exception that occurs because of an error during normal or exception processing. HardFaults
HardFault
have a fixed priority of -1, meaning they have higher priority than any exception with configurable priority.
A Supervisor Call (SVC) is an exception that is triggered by the SVC instruction. In an OS environment,
SVCall
applications can use SVC instructions to access OS kernel functions and device drivers.
PendSV is an interrupt-driven request for system-level service. In an OS environment, use PendSV for context
PendSV
switching when no other exception is active.
A SysTick exception is an exception that the system timer generates when it reaches zero. Software can also
SysTick
generate a SysTick exception. In an OS environment, the processor can use this exception as system tick.
An interrupt, or IRQ, is an exception signaled by a peripheral, or generated by a software request. All interrupts
Interrupt
are asynchronous to instruction execution. In the system, peripherals use interrupts to communicate with the
(IRQ)
processor.
4-10 - Reserved - - -
Configurable. See
11 -5 SVCall Section 4.2.6 Interrupt priority 0x0000002C Synchronous
registers.
12-13 - Reserved - - -
Configurable. See
14 -2 PendSV Section 4.2.6 Interrupt priority 0x00000038 Asynchronous
registers
Configurable. See
15 -1 SysTick Section 4.2.6 Interrupt priority 0x0000003C Asynchronous
registers
15 - Reserved - - -
1. To simplify the software layer, the CMSIS only uses IRQ numbers. It uses negative values for exceptions other than
interrupts. The IPSR returns the Exception number. See Interrupt program status register
2. See Figure 8. Vector table for more information.
For an asynchronous exception, other than reset, the processor can execute additional instructions between
when the exception is triggered and when the processor enters the exception handler.
Privileged software can disable the exceptions that Table 12. Properties of the different exception types shows as
having configurable priority, see Section 4.2.3 Interrupt clear-enable register.
For more information about HardFaults, see Section 2.4 Fault handling
47 31 IRQ31
0xBC
. . .
. . .
. . .
18 2 IRQ2
0x48
17 1 IRQ1
0x44
16 0 IRQ0
0x40
15 -1 SysTick
0x3C
14 -2 PendSV
0x38
13
Reserved
12
11 -5 SVCall
0x2C
10
9
8
7 Reserved
6
5
4
0x10
3 -13 HardFault
0x0C
2 -14 NMI
0x08
1 Reset
0x04
Initial SP value
0x00
DT33828V1
On system reset, the vector table is fixed at address 0x00000000. Privileged software can write to the VTOR
to relocate the vector table start address to a different memory location with the respect to vector table size and
granularity of TBLOFF settings (see Section 4.3.4 Vector table offset register).
If multiple pending exceptions have the same priority, the pending exception with the lowest exception number
takes precedence. For example, if both IRQ[0] and IRQ[1] are pending and have the same priority, then IRQ[0] is
processed before IRQ[1].
When the processor is executing an exception handler, the exception handler is preempted if a higher priority
exception occurs. If an exception occurs with the same priority as the exception being handled, the handler is not
preempted, irrespective of the exception number. However, the status of the new interrupt changes to pending.
When the processor is executing an exception handler, an exception can preempt the exception handler if its
priority is higher than the priority of the exception being handled.
Preemption
When one exception preempts another, the exceptions are called nested exceptions. See Exception entry for
more information.
This occurs when the exception handler is completed, and:
• There is no pending exception with sufficient priority to be serviced.
Return • The completed exception handler was not handling a late-arriving exception.
The processor pops the stack and restores the processor state to the state it had before the interrupt occurred.
See Exception return for more information.
This mechanism speeds up exception servicing. On completion of an exception handler, if there is a pending
Tail-chaining exception that meets the requirements for exception entry, the stack pop is skipped and control transfers to the
new exception handler.
This mechanism speeds up preemption. If a higher priority exception occurs during state saving for a previous
exception, the processor switches to handle the higher priority exception and initiates the vector fetch for that
Late-arriving exception. State saving is not affected by late arrival because the state saved would be the same for both
exceptions. On return from the exception handler of the late-arriving exception, the normal tail-chaining rules
apply.
Exception entry
Exception entry occurs when there is a pending exception with sufficient priority and either:
• The processor is in thread mode.
• The new exception is of higher priority than the exception being handled, in which case the new exception
preempts the exception being handled.
When one exception preempts another, the exceptions are nested.
Sufficient priority means that the exception has greater priority than any limit set by the mask register, see
Exception mask register. An exception with less priority than this is pending but is not handled by the processor.
When the processor takes an exception, unless the exception is a tail-chained or a late-arriving exception, the
processor pushes information onto the current stack. This operation is referred to as stacking and the structure of
eight data words is referred to as a stack frame. The stack frame contains the following information:
Immediately after stacking, the stack pointer indicates the lowest address in the stack frame. The stack frame is
aligned to a double-word address.
The stack frame includes the return address. This is the address of the next instruction in the interrupted program.
This value is restored to the PC at exception return so that the interrupted program resumes.
The processor performs a vector fetch that reads the exception handler start address from the vector table. When
stacking is complete, the processor starts executing the exception handler. At the same time, the processor writes
an EXC_RETURN value to the LR. This indicates which stack pointer corresponds to the stack frame and what
operation mode the processor was in before the entry occurred.
If no higher priority exception occurs during exception entry, the processor starts executing the exception handler,
and automatically changes the status of the corresponding pending interrupt to active.
If another higher priority exception occurs during exception entry, the processor starts executing the exception
handler for this exception, and does not change the pending status of the earlier exception. This is the late arrival
case.
Exception return
Exception return occurs when the processor is in handler mode and execution of one of the following instructions
attempts to set the PC to an EXC_RETURN value:
• A POP instruction that loads the PC.
• B PBX instruction using any register.
The processor saves an EXC_RETURN value to the LR on exception entry. The exception mechanism relies
on this value to detect when the processor has completed an exception handler. Bits[31:4] of an EXC_RETURN
value are 0xFFFFFFF. When the processor loads a value matching this pattern to the PC it detects that the
operation is a not a normal branch operation and, instead that the exception is complete. As a result, it starts the
exception return sequence. Bits[3:0] of the EXC_RETURN value indicate the required return stack and processor
mode, as Table 13. Exception return behavior shows.
EXC_RETURN Description
2.4.1 Lockup
The processor enters a Lockup state if a fault occurs when executing the NMI or HardFault handlers, or if
the system generates a bus error when unstacking the PSR on an exception return using the MSP. When the
processor is in lockup state, it does not execute any instructions. The processor remains in lockup state until one
of the following occurs:
• It is reset.
• A debugger halts it.
• An NMI occurs and the current lockup is in the HardFault handler.
Note: If lockup state occurs in the NMI handler a subsequent NMI does not cause the processor to leave lockup state.
Sleep-on-exit
If the SLEEPONEXIT bit of the SCR is set to 1, when the processor completes the execution of an exception
handler and returns to thread mode it immediately enters sleep mode. Use this mechanism in applications that
only require the processor to run when an interrupt occurs.
ADCS {Rd,} Rn, Rm Add with carry N,Z,C,V Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
ADD{S} {Rd,} Rn, <Rm|#imm> Add N,Z,C,V Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
ADR Rd, label PC-relative address to register - Section 3.4.1 ADR.
ANDS {Rd,} Rn, Rm Bitwise AND N,Z Section 3.5.2 AND, ORR, EOR, and BIC.
ASRS {Rd,} Rm, <Rs|#imm> Arithmetic shift right N,Z,C Section 3.5.3 ASR, LSL, LSR, and ROR.
B{cc} label Branch {conditionally} - Section 3.6.1 B, BL, BX, and BLX.
BICS {Rd,} Rn, Rm Bit clear N,Z Section 3.5.2 AND, ORR, EOR, and BIC.
BKPT #imm Breakpoint - Section 3.7.1 BKPT.
BL label Branch with link - Section 3.6.1 B, BL, BX, and BLX.
BLX Rm Branch indirect with link - Section 3.6.1 B, BL, BX, and BLX.
BX Rm Branch indirect - Section 3.6.1 B, BL, BX, and BLX.
CMN Rn, Rm Compare negative N,Z,C,V Section 3.5.4 CMP and CMN.
CMP Rn, <Rm|#imm> Compare N,Z,C,V Section 3.5.4 CMP and CMN.
CPSID i Change processor state, disable interrupts - Section 3.7.2 CPS.
CPSIE i Change processor state, enable interrupts - Section 3.7.2 CPS.
DMB - Data memory barrier - Section 3.7.3 DMB.
DSB - Data synchronization barrier - Section 3.7.4 DSB.
EORS {Rd,} Rn, Rm Exclusive OR N,Z Section 3.5.2 AND, ORR, EOR, and BIC.
ISB - Instruction synchronization barrier - Section 3.7.5 ISB.
LDM Rn{!}, reglist Load multiple registers, increment after - Section 3.4.5 LDM and STM.
LDR Rt, label Load register from PC-relative address - Section 3.4.2 LDR and STR, immediate offset.
LDR Rt, [Rn, <Rm|#imm>] Load register with word - Section 3.4.2 LDR and STR, immediate offset.
LDRB Rt, [Rn, <Rm|#imm>] Load register with byte - Section 3.4.2 LDR and STR, immediate offset.
LDRH Rt, [Rn, <Rm|#imm>] Load register with halfword - Section 3.4.2 LDR and STR, immediate offset.
LDRSB Rt, [Rn, <Rm|#imm>] Load register with signed byte - Section 3.4.2 LDR and STR, immediate offset.
LDRSH Rt, [Rn, <Rm|#imm>] Load register with signed halfword - Section 3.4.2 LDR and STR, immediate offset.
LSLS {Rd,} Rn, <Rs|#imm> Logical shift left N,Z,C Section 3.5.3 ASR, LSL, LSR, and ROR.
LSRS {Rd,} Rn, <Rs|#imm> Logical shift right N,Z,C Section 3.5.3 ASR, LSL, LSR, and ROR.
MOV{S} Rd, Rm Move N,Z Section 3.5.5 MOV and MVN.
MRS Rd, spec_reg Move to general register from special register - Section 3.7.6 MRS.
MSR spec_reg, Rm Move to special register from general register N,Z,C,V Section 3.7.7 MSR.
MULS Rd, Rn, Rm Multiply, 32-bit result N,Z Section 3.5.6 MULS.
MVNS Rd, Rm Bitwise NOT N,Z Section 3.5.5 MOV and MVN.
NOP - No operation - Section 3.7.8 NOP.
ORRS {Rd,} Rn, Rm Logical OR N,Z Section 3.5.2 AND, ORR, EOR, and BIC.
POP reglist Pop registers from stack - Section 3.4.6 PUSH and POP.
PUSH reglist Push registers onto stack - Section 3.4.6 PUSH and POP.
REV Rd, Rm Byte-reverse word - Section 3.5.7 REV, REV16, and REVSH.
REV16 Rd, Rm Byte-reverse packed halfwords - Section 3.5.7 REV, REV16, and REVSH.
REVSH Rd, Rm Byte-reverse signed halfword - Section 3.5.7 REV, REV16, and REVSH.
RORS {Rd,} Rn, Rs Rotate right N,Z,C Section 3.5.3 ASR, LSL, LSR, and ROR.
RSBS {Rd,} Rn, #0 Reverse subtract N,Z,C,V Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
SBCS {Rd,} Rn, Rm Subtract with carry N,Z,C,V Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
SEV - Send event - Section 3.7.9 SEV.
STM Rn!, reglist Store multiple registers, increment after - Section 3.4.5 LDM and STM.
STR Rt, [Rn, <Rm|#imm>] Store register as word - Section 3.4.2 LDR and STR, immediate offset.
STRB Rt, [Rn, <Rm|#imm>] Store register as byte - Section 3.4.2 LDR and STR, immediate offset.
STRH Rt, [Rn, <Rm|#imm>] Store register as halfword - Section 3.4.2 LDR and STR, immediate offset.
SUB{S} {Rd,} Rn, <Rm|#imm> Subtract N,Z,C,V Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
SVC #imm Supervisor call - Section 3.7.10 SVC.
SXTB Rd, Rm Sign extend byte - Section 3.5.8 SXT and UXT.
SXTH Rd, Rm Sign extend halfword - Section 3.5.8 SXT and UXT.
TST Rn, Rm Logical AND based test N,Z Section 3.5.9 TST.
UXTB Rd, Rm Zero extend a byte - Section 3.5.8 SXT and UXT.
UXTH Rd, Rm Zero extend a halfword - Section 3.5.8 SXT and UXT.
WFE - Wait for event - Section 3.7.11 WFE.
WFI - Wait for interrupt - Section 3.7.12 WFI.
The CMSIS also provides a number of functions for accessing the special registers using MRS and MSR
instructions.
:
3.3.1 Operands
An instruction operand can be an Arm® register, a constant, or another instruction-specific parameter. Instructions
act on the operands and often store the result in a destination register. When there is a destination register in the
instruction, it is usually specified before the other operands.
Carry
Flag
31 5 4 3 2 1 0
...
DT33830V1
LSR
Logical shift right by n bits moves the left-hand 32-n bits of the register Rm, to the right by n places, into the
right-hand 32-n bits of the result, and it sets the lefthand n bits of the result to 0. See Figure 11. LSR#3.
The user can use the LSR operation to divide the value in the register Rm by 2n, if the value is regarded as an
unsigned integer.
When the instruction is LSRS, the carry flag is updated to the last bit shifted out, bit[n-1], of the register Rm.
Note: If n is 32 or more, then all the bits in the result are cleared to 0.
If n is 33 or more and the carry flag is updated, it is updated to 0.
0 0 0 Carry
Flag
31 5 4 3 2 1 0
...
DT33831V1
LSL
Logical shift left by n bits moves the right-hand 32-n bits of the register Rm, to the left by n places, into the
left-hand 32-n bits of the result, and it sets the righthand n bits of the result to 0. See Section 3.3.3 Shift
operations.
The user can use the LSL operation to multiply the value in the register Rm by 2n, if the value is regarded as an
unsigned integer or a two's complement signed integer. Overflow can occur without warning.
When the instruction is LSLS the carry flag is updated to the last bit shifted out, bit[32-n],
of the register Rm. These instructions do not affect the carry flag when used with LSL#0.
Note: If n is 32 or more, then all the bits in the result are cleared to 0.
If n is 33 or more and the carry flag is updated, it is updated to 0.
0 0 0
Ca 31 5 4 3 2 1 0
rry
Fl ...
DT33832V1
ag
ROR
Rotate right by n bits moves the left-hand 32-nbits of the register Rm, to the right by n places, into the right-hand
32-n bits of the result, and it moves the righthand n bits of the register into the lefthand n bits of the result. See
Figure 12. LSL #3.
When the instruction is RORS the carry flag is updated to the last bit rotation, bit[n-1], of the register Rm.
Note: If n is 32, then the value of the result is same as the value in Rm, and if the carry flag is updated, it is updated to
bit[31] of Rm.
If ROR with shift length, n, greater than 32 is the same as ROR with shift length n-32.
Carry
Flag
31 5 4 3 2 1 0
...
DT33833V1
N Set to 1 when the result of the operation was negative, cleared to 0 otherwise
Z Set to 1 when the result of the operation was zero, cleared to 0 otherwise.
C Set to 1 when the operation resulted in a carry, cleared to 0 otherwise.
V Set to 1 when the operation caused overflow, cleared to 0 otherwise.
For more information about the APSR, see Application program status register.
A carry occurs:
• If the result of an addition is greater than or equal to 232.
• If the result of a subtraction is positive or zero.
• As the result of a shift or rotate instruction.
Overflow occurs when the sign of the result, in bit[31], does not match the sign of the result had the operation
been performed at infinite precision, for example:
• If adding two negative values results in a positive value.
• If adding two positive values results in a negative value.
• If subtracting a positive value from a negative value generates a positive value.
• If subtracting a negative value from a positive value generates a negative value.
The compare operations are identical to subtracting, for CMP, or adding, for CMN, except that the result is
discarded. See the instruction descriptions for more information.
MI N=1 Negative.
VS V=1 Overflow.
VC V=0 No overflow.
AL Can have any value Always. This is the default when no suffix is specified.
LDR{type} Load register using immediate offset Section 3.4.2 LDR and STR, immediate offset.
LDR{type} Load register using register offset Section 3.4.3 LDR and STR, register offset.
LDR Load register from PC-relative address Section 3.4.4 LDR, PCrelative.
POP Pop registers from stack Section 3.4.6 PUSH and POP.
PUSH Push registers onto stack Section 3.4.6 PUSH and POP.
STR{type} Store register using immediate offset Section 3.4.2 LDR and STR, immediate offset.
STR{type} Store register using register offset Section 3.4.3 LDR and STR, register offset.
3.4.1 ADR
Generates a PC-relative address.
Syntax
ADR Rd, label
Where:
Operation
ADR generates an address by adding an immediate value to the PC, and writes the result to the destination
register.
ADR facilitates the generation of positionindependent code, because the address is PCrelative.
If the user uses ADR to generate a target address for a BX or BLX instruction, the user must ensure that the bit[0]
of the address the user generates is set to 1 for correct execution.
Restrictions
In this instruction Rd must specify R0-R7. The data-value addressed must be word aligned and within 1020 bytes
of the current PC.
Condition flags
This instruction does not change the flags.
Examples:
ADR R1, TextMessage ; Write address value of a location labeled as;
TextMessage to R1
Where:
Operation
LDR, LDRB, and LDRH instructions load the register specified by Rt with either a word, byte, or halfword data
value from memory. Sizes less than word are zero extended to 32-bits before being written to the register
specified by Rt.
STR, STRB, and STRH instructions store the word, least-significant byte, or lower halfword contained in the
single register specified by Rt in to memory. The memory address, to load from or store to, is the sum of the value
in the register specified by either Rn or SP and the immediate value imm.
Restrictions
In these instructions:
• Rt and Rn must only specify R0-R7.
Condition flags
These instructions do not change the flags.
Examples
Syntax
Where:
Operation
LDR, LDRB, LDRH, LDRSB and LDRSH load the register specified by Rt with either a word, zero extended
byte, zero extended halfword, sign extended byte or sign extended halfword value from memory.
STR, STRB and STRH store the word, least-significant byte or lower halfword contained in the single register
specified by Rt into memory.
The memory address to load from or store to is the sum of the values in the registers specified by Rn and Rm.
Restrictions
In these instructions:
• Rt, Rn, and Rm must only specify R0-R7.
• The computed memory address must be divisible by the number of bytes in the load or store, see
Section 3.3.4 Address alignment.
Condition flags
These instructions do not change the flags.
Examples
; sum of R5 and R1
LDRSH R1, [R2, R3] ; Load a halfword from the memory address
Syntax
Where:
Operation
Loads the register specified by Rt from the word in memory specified by label.
Restrictions
In these instructions, label must be within 1020 bytes of the current PC and word aligned.
Condition flags
These instructions do not change the flags.
Examples
; labelled as LookUpTable.
LDR R3, [PC, #100] ; Load R3 with memory word at (PC + 100).
Where:
reglist Is a list of one or more registers to be loaded or stored, enclosed in braces. It can contain register ranges. It must
be comma separated if it contains more than one register or register range, see Examples.
LDMIA and LDMFD are synonyms for LDM. LDMIA refers to the base register being Incremented After each
access. LDMFD refers to its use for popping data from full descending stacks.
STMIA and STMEA are synonyms for STM. STMIA refers to the base register being incremented after each access.
STMEA refers to its use for pushing data onto empty ascending stacks.
Operation
LDM instructions load the registers in reglist with word values from memory addresses based on Rn.
STM instructions store the word values in the registers in reglist to memory addresses based on Rn.
The memory addresses used for the accesses are at 4-byte intervals ranging from the value in the register
specified by Rn to the value in the register specified by Rn + 4 * (n-1), where n is the number of registers in
reglist. The accesses happens in order of increasing register numbers, with the lowest numbered register using
the lowest memory address and the highest number register using the highest memory address. If the writeback
suffix is specified, the value in the register specified by Rn + 4 *n is written back to the register specified by Rn.
Restrictions
In these instructions:
• reglist and Rn are limited to R0-R7.
• The writeback suffix must always be used unless the instruction is an LDM where reglist also contains Rn,
in which case the writeback suffix must not be used.
• The value in the register specified by Rn must be word aligned. See Section 3.3.4 Address alignment for
more information.
• For STM, if Rn appears in reglist, then it must be the first register in the list.
Condition flags
These instructions do not change the flags.
Examples
STMIA R1!,{R2R4,R6}
Incorrect examples
Syntax
PUSH reglist
POP reglist
Where:
reglist Is a non-empty list of registers, enclosed in braces. It can contain register ranges. It must be comma separated if
it contains more than one register or register range.
Operation
PUSH stores registers on the stack, with the lowest numbered register using the lowest memory address and the
highest numbered register using the highest memory address.
POP loads registers from the stack, with the lowest numbered register using the lowest memory address and the
highest numbered register using the highest memory address.
PUSH uses the value in the SP register minus four as the highest memory address, POP uses the value in the SP
register as the lowest memory address, implementing a full-descending stack. On completion, PUSH updates the
SP register to point to the location of the lowest store value, POP updates the SP register to point to the location
above the highest location loaded.
If a POP instruction includes PC in its reglist, a branch to this location is performed when the POP instruction
has completed. Bit[0] of the value read for the PC is used to update the APSR T-bit. This bit must be 1 to ensure
correct operation.
Restrictions
In these instructions:
• reglist must use only R0-R7.
• The exception is LR for a PUSH and PC for a POP.
Condition flags
These instructions do not change the flags.
Examples
POP {R0,R6,PC} ; Pop r0,r6 and PC from the stack, then branch to
ADCS Add with carry Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
ADD{S} Add Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
ANDS Logical AND Section 3.5.2 AND, ORR, EOR, and BIC.
ASRS Arithmetic shift right Section 3.5.3 ASR, LSL, LSR, and ROR.
BICS Bit clear Section 3.5.2 AND, ORR, EOR, and BIC.
LSLS Logical shift left Section 3.5.3 ASR, LSL, LSR, and ROR.
LSRS Logical shift right Section 3.5.3 ASR, LSL, LSR, and ROR.
REV Reverse byte order in a word Section 3.5.7 REV, REV16, and REVSH.
REV16 Reverse byte order in each halfword Section 3.5.7 REV, REV16, and REVSH.
REVSH Reverse byte order in bottom halfword and sign extend Section 3.5.7 REV, REV16, and REVSH.
RORS Rotate right Section 3.5.3 ASR, LSL, LSR, and ROR.
RSBS Reverse subtract Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
SBCS Subtract with carry Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
SUBS Subtract Section 3.5.1 ADC, ADD, RSB, SBC, and SUB.
Syntax
Where:
When the optional Rd register specifier is omitted, it is assumed to take the same value as Rn, for example ADDS
R1,R2 is identical to ADDS R1,R1,R2.
Operation
The ADCS instruction adds the value in Rn to the value in Rm, adding another one if the carry flag is set, places the
result in the register specified by Rd and updates the N, Z, C, and V flags.
The ADD instruction adds the value in Rn to the value in Rm or an immediate value specified by imm and places
the result in the register specified by Rd.
The ADDS instruction performs the same operation as ADD and also updates the N, Z, C, and V flags.
The RSBS instruction subtracts the value in Rn from zero, producing the arithmetic negative of the value, and
places the result in the register specified by Rd and updates the N, Z, C, and V flags.
The SBCS instruction subtracts the value of Rm from the value in Rn, if the carry flag is clear, the result is reduced
by one. It places the result in the register specified by Rd and updates the N, Z, C, and V flags.
The SUB instruction subtracts the value in Rm or the immediate specified by imm. It places the result in the
register specified by Rd.
The SUBS instruction performs the same operation as SUB and also updates the N, Z, C, and V flags.
Use ADC and SBC to synthesize multiword arithmetic, see Examples.
See also Section 3.4.1 ADR.
Restrictions
Table 20. ADC, ADD, RSB, SBC and SUB operand restrictions lists the legal combinations of register specifiers
and immediate values that can be used with each instruction.
.
Table 20. ADC, ADD, RSB, SBC and SUB operand restrictions
ADCS R0-R7 R0-R7 R0-R7 - Rd and Rn must specify the same register.
SBCS R0-R7 R0-R7 R0-R7 - Rd and Rn must specify the same register.
Examples
64-bit addition shows two instructions that add a 64bit integer contained in R0 and R1 to another 64bit integer
contained in R2 and R3, and place the result in R0 and R1.
64-bit addition
ADDS R0, R0, R2 ; add the least significant words
ADCS R1, R1, R3 ; add the most significant words with carry
Multiword values do not have to use consecutive registers. 96-bit subtraction shows instructions that subtract a
96bit integer contained in R1, R2, and R3 from another contained in R4, R5, and R6. The example stores the
result in R4, R5, and R6.
96-bit subtraction
SUBS R4, R4, R1 ; subtract the least significant words
SBCS R6, R6, R3 ; subtract the most significant words with carry
Arithmetic negation shows the RSBS instruction used to perform a 1's complement of a single register.
Arithmetic negation
RSBS R7, R7, #0 ; subtract R7 from zero
Syntax
Where:
Operation
The AND, EOR, and ORR instructions perform bitwise AND, exclusive OR, and inclusive OR operations on the
values in Rn and Rm.
The BIC instruction performs an AND operation on the bits in Rn with the logical negation of the corresponding
bits in the value of Rm.
The condition code flags are updated on the result of the operation, see Condition flags.
Restrictions
In these instructions, Rd, Rn, and Rm must only specify R0-R7.
Condition flags
These instructions:
Update the N and Z flags according to the result.
Do not affect the C or V flag.
Examples
Syntax
Where:
Rd Is the destination register. If Rd is omitted, it is assumed to take the same value as Rm.
Rm Is the register holding the value to be shifted.
Rs Is the register holding the shift length to apply to the value in Rm
Is the shift length. The range of shift length depends on the instruction:
ASR shift length from 1 to 32
Imm
LSL shift length from 0 to 31
LSR shift length from 1 to 32.
Operation
ASR, LSL, LSR, and ROR perform an arithmetic-shift-left, logical-shift-left, logical-shift-right, or a right-rotation
of the bits in the register Rm by the number of places specified by the immediate imm or the value in the
least-significant byte of the register specified by Rs.
For details on what result is generated by the different instructions, see Section 3.3.3 Shift operations.
Restrictions
In these instructions, Rd, Rm, and Rs must only specify R0-R7. For non-immediate instructions, Rd and Rm must
specify the same register.
Condition flags
These instructions update the N and Z flags according to the result.
The C flag is updated to the last bit shifted out, except when the shift length is 0, see Section 3.3.3 Shift
operations. The V flag is left unmodified.
Examples
LSLS R1, R2, #3 ; Logical shift left by 3 bits with flag update
RORS R4, R4, R6 ; Rotate right by the value in the bottom byte of R6.
Syntax
CMN Rn, Rm
CMP Rn, Rm
Where:
Operation
These instructions compare the value in a register with either the value in another register or an immediate value.
They update the condition flags on the result, but do not write the result to a register.
The CMP instruction subtracts either the value in the register specified by Rm, or the immediate imm from the
value in Rn and updates the flags. This is the same as a SUBS instruction, except that the result is discarded.
The CMN instruction adds the value of Rm to the value in Rn and updates the flags. This is the same as an ADDS
instruction, except that the result is discarded.
Restrictions
For the:
• CMN instruction Rn, and Rm must only specify R0-R7.
• CMP instruction:
– Rn and Rm can specify R0-R14.
– Immediate must be in the range 0-255.
Condition flags
These instructions update the N, Z, C, and V flags according to the result.
Examples
CMP R2, R9
CMN R0, R2
Syntax
MOV{S} Rd, Rm
MVNS Rd, Rm
Where:
Is an optional suffix. If S is specified, the condition code flags are updated on the result of the operation, see
S
Section 3.3.6 Conditional execution.
Rd Is the destination register.
Rm Is a register.
Imm Is any value in the range 0-255.
Operation
The MOV instruction copies the value of Rm into Rd.
The MOVS instruction performs the same operation as the MOV instruction, but also updates the N and Z flags.
The MVSN instruction takes the value of Rm, performs a bitwise logical negate operation on the value, and places
the result into Rd.
Restrictions
In these instructions, Rd, and Rm must only specify R0-R7.
When Rd is the PC in a MOV instruction:
• Bit[0] of the result is discarded.
• A branch occurs to the address created by forcing the bit[0] of the result to 0. The T-bit remains unmodified.
Note: Though it is possible to use MOV as a branch instruction, Arm® strongly recommends the use of a BX, or BLX
instruction to branch for software portability.
Condition flags
If S is specified, these instructions:
• update the N and Z flags according to the result
• do not affect the C or V flags.
Example
MOVS R0, #0x000B ; Write value of 0x000B to R0, flags get updated
MOVS R1, #0x0 ; Write value of zero to R1, flags are updated
MOV R10, R12 ; Write value in R12 to R10, flags are not updated
3.5.6 MULS
Multiply using 32bit operands, and producing a 32-bit result.
Syntax
MULS Rd, Rn, Rm
Where:
Operation
The MUL instruction multiplies the values in the registers specified by Rn and Rm, and places the least
significant 32 bits of the result in Rd. The condition code flags are updated on the result of the operation, see
Section 3.3.6 Conditional execution.
The results of this instruction do not depend on whether the operands are signed or unsigned.
Restrictions
In this instruction:
• Rd, Rn, and Rm must only specify R0-R7.
• Rd must be the same as Rm.
Condition flags
This instruction:
Examples
Syntax
REV Rd, Rn
REV16 Rd, Rn
REVSH Rd, Rn
Where:
Operation
Use these instructions to change the endianness of data:
RER
REV Converts 32-bit big-endian data into little-endian data or 32-bit little-endian data into big-endian data.
REV16 Converts two packed 16-bit big-endian data into little-endian data or two packed 16-bit little-endian data into big-
endian data.
REVSH Converts 16-bit signed big-endian data into 32-bit signed little-endian data or 16-bit signed little-endian data into
32-bit signed big-endian data.
Restrictions
In these instructions, Rd, and Rn must only specify R0-R7.
Condition flags
These instructions do not change the flags.
Examples
Syntax
SXTB Rd, Rm
SXTH Rd, Rm
UXTB Rd, Rm
UXTH Rd, Rm
Where:
Operation
• These instructions extract bits from the resulting value:
• SXTB extracts bits[7:0] and sign extends to 32 bits.
• UXTB extracts bits[7:0] and zero extends to 32 bits.
• SXTH extracts bits[15:0] and sign extends to 32 bits.
• UXTH extracts bits[15:0] and zero extends to 32 bits.
Restrictions
In these instructions, Rd and Rm must only specify R0-R7.
Condition flags
These instructions do not affect the flags.
Examples
UXTB R3, R1 ; Extract lowest byte of the value in R10 and zero
3.5.9 TST
Test bits.
Syntax
TST Rn, Rm
Where:
Operation
This instruction tests the value in a register against another register. It updates the condition flags based on the
result, but does not write the result to a register.
The TST instruction performs a bitwise AND operation on the value in Rn and the value in Rm. This is the same
as the ANDS instruction, except that it discards the result.
To test whether a bit of Rn is 0 or 1, use the TST instruction with a register that has that bit set to 1 and all other
bits cleared to 0.
Restrictions
In these instructions, Rn and Rm must only specify R0-R7.
Condition flags
This instruction:
• updates the N and Z flags according to the result
• does not affect the C or V flags.
Examples
BLX Branch indirect with Link Section 3.6.1 B, BL, BX, and BLX.
Syntax
B{cond} label
BL label
BX Rm
BLX Rm
Where:
Operation
All these instructions cause a branch to the address indicated by the label or contained in the register specified by
Rm. In addition:
• the BL and BLX instructions write the address of the next instruction to LR, the link register R14.
• the BX and BLX instructions result in a HardFault exception if bit[0] of Rm is 0.
BL and BLX instructions also set bit[0] of the LR to 1. This ensures that the value is suitable for use by a
subsequent POP {PC} or BX instruction to perform a successful return branch.
Table 22. Branch ranges shows the ranges for the various branch instructions.
B label -2 KB to +2 KB.
Restrictions
In these instructions:
• Do not use SP or PC in the BX or BLX instruction.
• For BX and BLX, the bit[0] of Rm must be 1 for correct execution. Bit[0] is used to update the EPSR T-bit
and is discarded from the target address.
Note: Bcond is the only conditional instruction on the Cortex-M0+ processor.
Condition flags
These instructions do not change the flags.
Examples
; stored in LR
; in R0
3.7.1 BKPT
Breakpoint.
Syntax
BKPT #imm
Where:
Operation
The BKPT instruction causes the processor to enter debug state. Debug tools can use this to investigate system
state when the instruction at a particular address is reached.
Imm is ignored by the processor. If required, a debugger can use it to store additional information about the
breakpoint.
The processor might also produce a HardFault or go in to Lockup if a debugger is not attached when a BKPT
instruction is executed. See Section 2.4.1 Lockup for more information.
Restrictions
There are no restrictions.
Condition flags
This instruction does not change the flags.
Examples
3.7.2 CPS
Change processor state.
Syntax
CPSID i
CPSIE i
Operation
CPS changes the PRIMASK special register values. CPSID causes interrupts to be disabled by setting PRIMASK.
CPSIE cause interrupts to be enabled by clearing PRIMASK. See Exception mask register for more information
about these registers.
Restrictions
If the current mode of execution is not privileged, then this instruction behaves as a NOP and does not change the
current state of PRIMASK.
Condition flags
This instruction does not change the condition flags.
Examples
3.7.3 DMB
Data memory barrier.
Syntax
DMB
Operation
DMB acts as a data memory barrier. It ensures that all explicit memory accesses that appear in program order
before the DMB instruction are observed before any explicit memory accesses that appear in program order after
the DMB instruction. DMB does not affect the ordering of instructions that do not access memory.
Restrictions
There are no restrictions.
Condition flags
This instruction does not change the flags.
Examples
3.7.4 DSB
Data synchronization barrier.
Syntax
DSB
Operation
DSB acts as a special data synchronization memory barrier. Instructions that come after the DSB, in program
order, do not execute until the DSB instruction completes. The DSB instruction completes when all explicit
memory accesses before it complete.
Restrictions
There are no restrictions.
Condition flags
This instruction does not change the flags.
Examples
3.7.5 ISB
Instruction synchronization barrier.
Syntax
ISB
Operation
ISB acts as an instruction synchronization barrier. It flushes the pipeline of the processor, so that all instructions
following the ISB are fetched from cache or memory again, after the ISB instruction has been completed.
Restrictions
There are no restrictions.
Condition flags
This instruction does not change the flags.
Examples
3.7.6 MRS
Move the contents of a special register to a general purpose register.
Syntax
Where:
Operation
MSR stores the contents of a special-purpose register to a general purpose register. The MSR instruction can be
combined with the MSR instruction to produce read-modify-write sequences, which are suitable for modifying a
specific flag in the PSR.
See Section 3.7.7 MSR.
Restrictions
In this instruction, Rd must not be SP or PC.
If the current mode of execution is not privileged, then the values of all registers other than the APSR read as
zero.
Condition flags
This instruction does not change the flags.
Examples
3.7.7 MSR
Move the contents of a generalpurpose register into the specified special register.
Syntax
MSR spec_reg, Rn
Where:
Operation
MSR updates one of the special registers with the value from the register specified by Rn.
See Section 3.7.6 MRS.
Restrictions
In this instruction, Rn must not be SP and must not be PC.
If the current mode of execution is not privileged, then all attempts to modify any register other than the APSR are
ignored.
Condition flags
This instruction updates the flags explicitly based on the value in Rn.
Examples
3.7.8 NOP
No operation.
Syntax
NOP
Operation
NOP performs no operation and is not guaranteed to be time consuming. The processor might remove it from the
pipeline before it reaches the execution stage.
Restrictions
There are no restrictions.
Condition flags
This instruction does not change the flags.
Examples
NOP ; No operation
3.7.9 SEV
Send Event.
Syntax
SEV
Operation
SEV causes an event to be signaled to all processors within a multiprocessor system. It also sets the local event
register, see Section 2.5 Power management.
See also Section 3.7.11 WFE.
Restrictions
There are no restrictions.
Condition flags
This instruction does not change the flags.
Examples
3.7.10 SVC
Supervisor call.
Syntax
SVC #imm
Where:
Operation
The SVC instruction causes the SVC exception.
Imm is ignored by the processor. If required, it can be retrieved by the exception handler to determine what
service is being requested.
Restrictions
Executing the SVC instruction, while the current execution priority level is greater than or equal to that of the
SVCall handler, results in a fault being generated.
Condition flags
This instruction does not change the flags.
Examples
SVC #0x32 ; Supervisor call (SVC handler can extract the immediate value.
3.7.11 WFE
Wait for event.
Syntax
WFE
Operation
If the event register is 0, WFE suspends execution until one of the following events occurs:
• An exception, unless masked by the exception mask registers or the current priority level.
• An exception enters the pending state, if SEVONPEND in the system control register is set.
• A debug entry request, if debug is enabled.
• An event signaled by a peripheral or another processor in a multiprocessor system using the SEV
instruction.
If the event register is 1, WFE clears it to 0 and completes immediately.
For more information, see Section 2.5 Power management.
Note: WFE is intended for power saving only. When writing the software, it is assumed that WFE might behave as
NOP.
Restrictions
There are no restrictions.
Condition flags
This instruction does not change the flags.
Examples
3.7.12 WFI
Wait for interrupt.
Syntax
WFI
Operation
WFI suspends execution until one of the following events occurs:
• An exception.
• An interrupt becomes pending which would preempt if PRIMASK.PM was clear.
• A debug entry request, regardless of whether debug is enabled.
Note: WFI is intended for power saving only. When writing software, it is assumed that WFI might behave as a NOP
operation.
Restrictions
There are no restrictions.
Condition flags
This instruction does not change the flags.
Examples
0xE000E008-0xE000E00F System Control Block Table 29. Summary of the SCB registers.
0xE000E010-0xE000E01F Reserved -
0xE000E100-0xE000E4EF Nested vectored interrupt controller Table 25. NVIC register summary.
0xE000ED00-0xE000ED3F System control block Table 29. Summary of the SCB registers.
0xE000EF00-0xE000EF03 Nested vectored interrupt controller Table 25. NVIC register summary.
1. Software can read the MPU type register at 0xE000ED90 to test for the presence of a memory protection unit (MPU).
• the required privilege gives the privilege level required to access the register, as follows:
Privileged
Only privileged software can access the register.
Unprivileged
Both unprivileged and privileged software can access the register.
uint32_t NVIC_GetPendingIRQ(IRQn_Type Reads the pending status of interrupt or exception. This function returns
IRQn) nonzero value if the pending status is set to 1.
Note: The input parameter IRQn is the IRQ number, see Table 12. Properties of the different exception types
If a pending interrupt is enabled, the NVIC activates the interrupt based on its priority. If an interrupt is not
enabled, asserting its interrupt signal changes the interrupt state to pending, but the NVIC never activates the
interrupt, regardless of its priority.
Note: Writing 1 to an NVIC_ICPR bit does not affect the active state of the corresponding interrupt.
31 24 23 16 15 8 7 0
NVIC_IPR
PRI_31 PRI_30 PRI_29 PRI_28
7
...
.
..
NVIC_IPR
PRI_(4n+3) PRI_(4n+2) PRI_(4n+1) PRI_(4n)
n
...
.
..
NVIC_IPR
PRI_3 PRI_2 PRI_1 PRI_0
0
DT33834V1
Table 27. NVIC_IPRx bit assignments
Priority, byte
[31:24]
offset 3
Priority, byte
[23:16] Each priority field holds a priority value, 0-192. The lower the value, the greater the priority of the corresponding
offset 2
interrupt. The processor implements only bits[7:6] of each field, bits [5:0] read as zero and ignore writes. This
Priority, byte means writing 255 to a priority register saves value 192 to the register.
[15:8]
offset 1
Priority, byte
[7:0]
offset 0
See Section 4.2.1 Accessing the Cortex®-M0+ NVIC registers using CMSIS for more information about the
access to the interrupt priority array, which provides the software view of the interrupt priorities.
Find the NVIC_IPR number and byte offset for interrupt M as follows:
• The corresponding NVIC_IPR number, N, is given by N = N DIV 4.
• The byte offset of the required priority field in this register is M MOD 4, where:
– Byte offset 0 refers to register bits[7:0].
– Byte offset 1 refers to register bits[15:8].
– Byte offset 2 refers to register bits[23:16].
– Byte offset 3 refers to register bits[31:24].
In addition, the CMSIS provides a number of functions for NVIC control, including:
void NVIC_SetPriority (IRQn_t IRQn, uint32_t priority) Set priority for IRQn.
The input parameter IRQn is the IRQ number, see Table 12. Properties of the different exception types. For more
information about these functions, see the CMSIS documentation.
0xE000ED04 ICSR RW(1) 0x00000000 Section 4.3.3 Interrupt control and state register (ICSR).
0xE000ED0C AIRCR RW(1) 0xFA050000 Section 4.3.5 Application interrupt and reset control register.
0xE000ED14 CCR RO 0x00000204 Section 4.3.7 Configuration and control register (CCR).
VECTPENDING[8:4]
NMIPENDSET
ISRPREEMPT
ISRPENDING
PENDSVCLR
PENDSVSET
PENDSTCLR
PENDSTSET
Reserved
Reserved
Reserved
rw rw w rw w r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
VECTPENDING[3:0] VECTACTIVE[8:0]
Reserved
r r r r rw rw rw rw rw rw rw rw rw
[20:12] VECTPENDING r Nonzero = the exception number of the highest priority pending enabled exception.
Subtract 16 from this value to obtain the CMSIS IRQ number that identifies the
corresponding bit in the interrupt clear-enable, setenable, clear-pending, set-pending, and
priority register, see Table 6. IPSR bit assignments.
[11:9] - - Reserved.
Contains the active exception number:
[8:0] VECTACTIVE r 0 = Thread mode
Nonzero = The exception number of the currently active exception.
1. This is the same value as IPSR bits[5:0], Table 6. IPSR bit assignments.
When the user writes to the ICSR, the effect is unpredictable if:
• write 1 to the PENDSVSET bit and write 1 to the PENDSVCLR bit
• write 1 to the PENDSTSET bit and write 1 to the PENDSTCLR bit.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
TBLOFF[31:16]
rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TBLOFF[15:7]
Reserved
rw rw rw rw rw rw rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
Reserved
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
SEVO SLEE SLEE
NPEN PDEE P ON
Reserved D Res. P EXIT Res.
rw rw rw
Each PRI_N field is 8 bits wide, but the processor implements only bits[7:6] of each field, and bits[5:0] read as
zero and ignore writes.
Bits 31:24 PRI_15: Priority of system handler 15, SysTick exception. This is reserved when the SysTick timer is not implemented.
Required
Address Name Type Reset value Description
privilege
0xE000E018 STK_CVR RW Privileged Unknown Section 4.4.3 SysTick current value register (STK_CVR).
Reserved rc_r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Reserved rw rw rw
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16
NO
SKEW TENMS[23:16]
REF Reserved
r r r r r r r r r r
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
TENMS[15:0]
r r r r r r r r r r r r r r r r
Bit 31 NOREF: Reads as zero. Indicates that separate reference clock is provided. The frequency of this clock is HCLK/8.
Bit 30 SKEW: Reads as one. Calibration value for the 1ms inexact timing is not known because TENMS is not known. This can affect
the suitability of SysTick as a software real time clock.
Bits 29:24 Reserved, must be kept cleared.
Bits 23:0 TENMS[23:0]:
Indicates the calibration value when the SysTick counter runs on HCLK max/8 as external
clock. The value is product dependent, please refer to the Product Reference Manual, SysTick
Calibration Value section. When HCLK is programmed at the maximum frequency, the SysTick period is 1ms.
If calibration information is not known, calculate the calibration value required from the frequency of the processor
clock or external clock.
In an OS environment, the kernel can update the MPU region setting dynamically based on the process to be
executed. Typically, an embedded OS uses the MPU for memory protection.
Configuration of MPU regions is based on memory types, see Section 2.2.1 Memory regions, types, and
attributes.
Table 33. Memory attributes summary shows the possible MPU region attributes. These include Shareability and
cache behavior attributes that are not relevant to most microcontroller implementations. See MPU configuration
for a microcontroller for guidelines for programming such an implementation.
Use the MPU registers to define the MPU regions and their attributes. Table 34. MPU registers summary shows
the MPU registers.
Reset
Address Name Type Description
value
0xE000ED9C MPU_RBAR RW Unknown Section 4.5.4 MPU region base address register.
0xE000EDA0 MPU_RASR RW Unknown Section 4.5.5 MPU region attribute and size register.
1. Software can read the MPU type register to test for the presence of a memory protection unit
(MPU). See Section 4.5.1 MPU type register
Bits 15:8 DREGION[7:0]: Indicates the number of supported MPU data regions:
0x00 = Zero regions if the device does not include the MPU.
0x08 = Eight regions if the device includes the MPU.
Bits 7:1 Reserved.
Bit 0 SEPARATE: Indicates support for unified or separate instruction and date memory maps:
0 = Unified.
• Any access by unprivileged software that does not address an enabled memory region causes a
MemManage fault.
XN and Strongly ordered rules always apply to the System Control Space regardless of the value of the ENABLE
bit.
When the ENABLE bit is set to 1, at least one region of the memory map must be enabled for the system to
function unless the PRIVDEFENA bit is set to 1. If the PRIVDEFENA bit is set to 1 and no regions are enabled,
then only privileged software can operate.
When the ENABLE bit is set to 0, the system uses the default memory map. This has the same memory attributes
as if the MPU is not implemented, see Section 2.2 Memory model. The default memory map applies to accesses
from both privileged and unprivileged software.
When the MPU is enabled, accesses to the System Control Space, and vector table are always permitted. Other
areas are accessible based on regions and whether PRIVDEFENA is set to 1.
Unless HFNMIENA is set to 1, the MPU is not enabled when the processor is executing the handler for an
exception with priority –1 or –2. These priorities are only possible when handling a HardFault or NMI exception.
Setting the HFNMIENA bit to 1 enables the MPU when operating with these two priorities.
Normally, the user writes the required region number to this register before accessing the MPU_RBAR or
MPU_RASR. However, the user can change the region number by writing to the MPU_RBAR with the VALID
bit set to 1, see Section 4.5.4 MPU region base address register. This write updates the value of the REGION
field.
If the region size is 32B, the ADDR field is bits [31:5], and there is no reserved field.
For information about access permission, see Section 4.5.6 MPU access permission attributes.
1. In the MPU_RBAR, see Section 4.5.4 MPU region base address register.
0 Not shareable
0 Normal Outer and inner write-through. No write allocate.
1 Shareable
1
0 Not shareable
1 Normal Outer and inner write-back. No write allocate.
1 Shareable
Table 37. AP encoding shows the AP encodings that define the access permissions for privileged and
unprivileged software.
.
Privileged Unprivileged
AP[2:0] Description
permissions permissions
; R2 = size/enable
; R3 = attributes
; R4 = address
For example, if the user wants all of the memory access behavior to take effect immediately after the
programming sequence, use a DSB instruction and an ISB instruction. A DSB is required after changing MPU
settings, such as at the end of context switch. An ISB is required if the code that programs the MPU region or
regions is entered using a branch or call. If the programming sequence is entered using a return from exception,
or by taking an exception, then that do not require an ISB.
Subregions
Regions are divided into eight equal-sized subregions. Set the corresponding bit in the SRD field of the
MPU_RASR to disable a subregion, see Section 4.5.5 MPU region attribute and size register. The least significant
bit of SRD controls the first subregion, and the most significant bit controls the last subregion. Disabling a
subregion means another region overlapping the disabled range matches instead. If no other enabled region
overlaps the disabled subregion the MPU issues a fault.
DT33835V1
regions Disabled subregion 64KB
0
In most microcontroller implementations, the shareability and cache policy attributes do not affect the system
behavior. However, using these settings for the MPU regions can make the application code more portable. The
values given are for typical situations. In special systems, such as multiprocessor designs or designs with a
separate DMA engine, the shareability attribute might be important. In these cases refer to the recommendations
of the memory device manufacturer.
Revision history
Table 39. Document revision history
Contents
1 About this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.1 Typographical conventions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.2 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 About the Cortex® M0+ processor and core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3.1 System-level interface. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.2 Integrated configurable debug. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.3 Cortex®-M0+ processor feature summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.3.4 Cortex®-M0+ core peripherals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2 Cortex®-M0+ processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1 Programmers model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.1 Processor modes and privilege levels for software execution . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.2 Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.3 Core registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.1.4 Exceptions and interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1.5 Data types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2.1.6 Cortex® microcontroller software interface standard . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2 Memory model. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.2.1 Memory regions, types, and attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2.2 Memory system ordering of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2.3 Behavior of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2.4 Additional memory access constraints for caches and shared memory. . . . . . . . . . . . . . . 14
2.2.5 Software ordering of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
2.2.6 Memory endianness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 Exception model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3.1 Exception states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3.2 Exception types. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
2.3.3 Exception handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.3.4 Vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
2.3.5 Exception priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.3.6 Exception entry and return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.4 Fault handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.4.1 Lockup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.5 Power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.5.1 Entering sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
2.5.2 Wake-up from sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.7.6 MRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.7.7 MSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.7.8 NOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.7.9 SEV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.7.10 SVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.7.11 WFE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.7.12 WFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
List of tables
Table 1. Applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
Table 2. Summary of processor mode, execution privilege level, and stack use options. . . . . . . . . . . . . . . . . . . . . . . . . . 5
Table 3. Core register set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Table 4. PSR register combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 5. APSR bit assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 6. IPSR bit assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Table 7. EPSR bit assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 8. PRIMASK register bit assignments. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Table 9. Control register bit assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Table 10. Memory access behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Table 11. Memory region shareability and cache policies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
Table 12. Properties of the different exception types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Table 13. Exception return behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
Table 14. Cortex®-M0+ instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
Table 15. CMSIS intrinsic functions to generate some Cortex®-M0+ instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Table 16. CMSIS intrinsic functions to access the special registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Table 17. Condition code suffixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Table 18. Memory access instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Table 19. Data processing instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Table 20. ADC, ADD, RSB, SBC and SUB operand restrictions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Table 21. Branch and control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Table 22. Branch ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Table 23. Miscellaneous instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Table 24. Core peripheral register regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Table 25. NVIC register summary. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Table 26. CMSIS access NVIC functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Table 27. NVIC_IPRx bit assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Table 28. CMSIS functions for NVIC control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
Table 29. Summary of the SCB registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Table 30. ICSR bit assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Table 31. System fault handler priority fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Table 32. System timer registers summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
Table 33. Memory attributes summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Table 34. MPU registers summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Table 35. Example SIZE field values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Table 36. C, B, and S encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Table 37. AP encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Table 38. Memory region attributes for a microcontroller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Table 39. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
List of figures
Figure 1. Cortex®-M0+ implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
Figure 2. Processor core registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Figure 3. APSR, IPSR, and EPSR bit assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 4. Control bit assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 5. Memory map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Figure 6. Ordering of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Figure 7. Little-endian format example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Figure 8. Vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Figure 9. Stack frame . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Figure 10. ASR#3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Figure 11. LSR#3. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Figure 12. LSL #3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Figure 13. ROR #3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
Figure 14. Priority fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
Figure 15. Example of SRD use . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72