Page 2
This document is intended only to assist the reader in the use of the product. ARM shall not be liable for any loss or damage arising from the use of any information in this document, or any error or omission in such information, or any incorrect use of the product.
Cortex-M4 Devices Generic User Guide Preface About this book ......................vi Feedback ........................ix Chapter 1 Introduction About the Cortex-M4 processor and core peripherals ..........1-2 Chapter 2 The Cortex-M4 Processor Programmers model ....................2-2 Memory model ....................... 2-12 Exception model ....................2-21 Fault handling ......................
Page 4
Chapter 4 Cortex-M4 Peripherals About the Cortex-M4 peripherals ................4-2 Nested Vectored Interrupt Controller ............... 4-3 System control block ....................4-11 System timer, SysTick ................... 4-33 Optional Memory Protection Unit ................4-37 Floating Point Unit (FPU) ..................4-48 Appendix A Cortex-M4 Options Cortex-M4 implementation options ................
Preface About this book This book is a generic user guide for devices that implement the ARM Cortex-M4 processor. Implementers of Cortex-M4 designs make a number of implementation choices, that can affect the functionality of the device. This means that, in this book: •...
Page 9
Preface Feedback ARM welcomes feedback on this product and its documentation. Feedback on content If you have comments on content then send an e-mail to . Give: errata@arm.com • the title • the number, ARM DUI 0553A • the page numbers to which your comments apply •...
Page 11
Figure 1-1 Cortex-M4 implementation The Cortex-M4 processor is built on a high-performance processor core, with a 3-stage pipeline Harvard architecture, making it ideal for demanding embedded applications. The processor delivers exceptional power efficiency through an efficient instruction set and extensively...
Page 12
Boolean data handling. The Cortex-M4 processor has an optional Memory Protection Unit (MPU) that permits control of individual regions in memory, enabling applications to utilize multiple privilege levels, separating and protecting code, data and stack on a task-by-task basis.
Chapter 2 The Cortex-M4 Processor This chapter describes the Cortex-M4 processor. It contains the following sections: • Programmers model on page 2-2 • Memory model on page 2-12 • Exception model on page 2-21 • Fault handling on page 2-29 •...
Page 15
The Cortex-M4 Processor Programmers model This section describes the Cortex-M4 programmers model. In addition to the individual core register descriptions, it contains information about the processor modes and privilege levels for software execution and stacks. 2.1.1 Processor mode and privilege levels for software execution...
Page 20
The conditions for the instructions are either all the same, or some can be the inverse of others. See IT on page 3-122 for more information. Thumb state The Cortex-M4 processor only supports execution of instructions in Thumb state. The following can clear the T bit to 0: • instructions POP{PC •...
0 = no floating-point context active 1 = floating-point context active. The Cortex-M4 uses this bit to determine whether to preserve floating-point state when processing an exception. SPSEL Defines the currently active stack pointer: In Handler mode this bit reads as zero and ignores writes. The...
Page 23
The Cortex-M4 Processor In an OS environment, ARM recommends 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, either: •...
Page 25
Optional bit-banding on page 2-16. The processor reserves regions of the Private Peripheral Bus (PPB) address range for core peripheral registers, see About the Cortex-M4 peripherals on page 4-2. 2.2.1 Memory regions, types and attributes The memory map and programming the optional MPU splits the memory map into regions.
Page 27
Memory regions, types and attributes on page 2-12 for more information. The Code, SRAM, and external RAM regions can hold programs. However, ARM recommends that programs always use the Code region. This is because the processor has separate buses that enable instruction fetches and data accesses to occur simultaneously.
2.2.7 Synchronization primitives The Cortex-M4 instruction set includes pairs of synchronization primitives. These provide a non-blocking mechanism that a thread or process can use to obtain exclusive access to a memory location. Software can use them to perform a guaranteed read-modify-write memory update sequence, or for a semaphore mechanism.
Page 32
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.
Page 39
Figure 2-3 on page 2-27 shows the Cortex-M4 stack frame layout when floating-point state is preserved on the stack as the result of an interrupt or an exception. Note Where stack space for floating-point state is not allocated, the stack frame is the same as that of ARMv7-M implementations without an FPU.
The Cortex-M4 Processor Power management The Cortex-M4 processor sleep modes reduce power consumption. The sleep modes your device implements are implementation-defined. The modes can be one or both of the following: • sleep mode stops the processor clock • deep sleep mode stops the system clock and switches off the PLL and flash memory.
Page 46
When the WIC is enabled and the processor enters deep sleep mode, the power management unit in the system can power down most of the Cortex-M4 processor. This has the side effect of stopping the SysTick timer. When the WIC receives an interrupt, it takes a number of clock cycles to wakeup the processor and restore its state, before it can process the interrupt.
Page 48
Chapter 3 The Cortex-M4 Instruction Set This chapter is the reference material for the Cortex-M4 instruction set description in a User Guide. The following sections give general information: • Instruction set summary on page 3-2 • CMSIS functions on page 3-9 •...
Page 55
VMOV Sd, Sm Copy ARM core register to single precision page 3-143 VMOV Sn, Rt Copy 2 ARM core registers to 2 single precision page 3-144 VMOV Sm, Sm1, Rt, Rt2 Copy ARM core register to scalar page 3-145 VMOV...
The Cortex-M4 Instruction Set CMSIS functions ISO/IEC C code cannot directly access some Cortex-M4 instructions. This section describes intrinsic functions that can generate these instructions, provided by the CMSIS and that might be provided by a C compiler. If a C compiler does not support an appropriate intrinsic function, you might have to use inline assembler to access some instructions.
Page 59
Bit[0] of any address you write to the PC with a , or instruction must be 1 for correct execution, because this bit indicates the required instruction set, and the Cortex-M4 processor only supports Thumb instructions. 3.3.3 Flexible second operand Many general data processing instructions have a flexible second operand.
Page 64
An aligned access is an operation where a word-aligned address is used for a word, dual word, or multiple word access, or where a halfword-aligned address is used for a halfword access. Byte accesses are always aligned. The Cortex-M4 processor supports unaligned access only for the following instructions: • LDRT •...
Page 89
0b00 calculation word-aligned. — If you want to generate the address of an instruction, you have to adjust the constant based on the value of the PC. ARM recommends that you use the instruction instead of with equal to the PC, because your assembler automatically calculates the correct constant for the instruction.
Page 98
0. Note Though it is possible to use as a branch instruction, ARM strongly recommends the use of instruction to branch for software portability to the ARM instruction set. Condition flags is specified, these instructions: •...
Page 174
Table 3-15 Floating-point instructions (continued) Mnemonic Brief description Copies between ARM core register to scalar VMOV ARM Core register to scalar on page 3-145 VMOV Copies between Scalar to ARM core register VMOV Scalar to ARM Core register on page 3-142...
Page 184
, of the registers in size list • For the base address, the SP can be used. In the ARM instruction set, if is not specified can be used. • must contain at least one register. If it contains doubleword registers, it must not list contain more than 16 registers.
Page 185
Specifies the label of the literal data item to be loaded. label Operation This instruction: • Loads a single extension register from memory, using a base address from an ARM core register, with an optional offset. Restrictions There are no restrictions. Condition flags These instructions do not change the flags.
Page 189
If x is 1, use upper half of doubleword register. Operation This instruction transfers: • one word from the upper or lower half of a doubleword floating-point register to an ARM core register. Restrictions Rt cannot be PC or SP.
Page 190
The Cortex-M4 Instruction Set 3.11.16 VMOV ARM Core register to single precision Transfers a single-precision register to and from an ARM core register. Syntax VMOV{cond} Sn, Rt VMOV{cond} Rt, Sn where: Is an optional condition code, see Conditional execution on page 3-18.
Page 191
• The contents of two consecutively numbered single-precision registers to two ARM core registers. • The contents of two ARM core registers to a pair of single-precision registers. Restrictions The restrictions are: • The floating-point registers must be contiguous, one after the other.
Page 192
The Cortex-M4 Instruction Set 3.11.18 VMOV ARM Core register to scalar Transfers one word to a floating-point register from an ARM core register. Syntax VMOV{cond}{.32} Dd[x], Rt where: Is an optional condition code, see Conditional execution on page 3-18. cond Is an optional data size specifier.
Page 193
Is an optional condition code, see Conditional execution on page 3-18. cond Specifies the destination ARM core register. This register can be R0-R14. Transfer floating-point flags to the APSR flags. APSR_nzcv Operation This instruction performs one of the following actions: •...
Page 194
The Cortex-M4 Instruction Set 3.11.20 VMSR Move to floating-point System Register from ARM Core register. Syntax VMSR{cond} FPSCR, Rt where: Is an optional condition code, see Conditional execution on page 3-18. cond Specifies the general-purpose register to be transferred to the FPSCR.
Page 202
0-1020. can be omitted, meaning an offset of Operation This instruction: • Stores a single extension register to memory, using an address from an ARM core register, with an optional offset, defined in Restrictions The restrictions are: •...
Page 217
Chapter 4 Cortex-M4 Peripherals This chapter describes the ARM Cortex-M4 core peripherals. It contains the following sections: • About the Cortex-M4 peripherals on page 4-2 • Nested Vectored Interrupt Controller on page 4-3 • System control block on page 4-11 •...
Page 220
Cortex-M4 Peripherals 4.2.1 Accessing the Cortex-M4 NVIC registers using CMSIS CMSIS functions enable software portability between different Cortex-M profile processors. To access the NVIC registers when using CMSIS, use the following functions: Table 4-3 CMSIS access NVIC functions CMSIS function Description Enables an interrupt or exception.
Page 223
[15:8] Priority, byte offset 1 [7:0] Priority, byte offset 0 Accessing the Cortex-M4 NVIC registers using CMSIS on page 4-4 for more information about the access to the interrupt priority array, which provides the software view of the interrupt priorities.
Page 224
0x03 4.2.9 Level-sensitive and pulse interrupts A Cortex-M4 device can support both level-sensitive and pulse interrupts. Pulse interrupts are also described as edge-triggered interrupts. A level-sensitive interrupt is held asserted until the peripheral deasserts the interrupt signal. Typically this happens because the ISR accesses the peripheral, causing it to clear the interrupt request.
Page 225
Cortex-M4 Peripherals Hardware and software control of interrupts The Cortex-M4 latches all interrupts. A peripheral interrupt becomes pending for one of the following reasons: • the NVIC detects that the interrupt signal is HIGH and the interrupt is not active •...
Page 228
BusFaults to be precise BusFaults but decreases performance because any store to memory must complete before the processor can execute the next instruction. Note This bit only affects write buffers implemented in the Cortex-M4 processor. DISMCYCINT When set to 1, disables interruption of load multiple and store multiple instructions. This increases the interrupt latency of the processor because any LDM or STM must complete before the processor can stack the current state and enter the interrupt handler.
Page 253
• overlapping regions • export of memory attributes to the system. The memory attributes affect the behavior of memory accesses to the region. The Cortex-M4 MPU defines: • eight separate memory regions, 0-7 •...
Page 269
Appendix A Cortex-M4 Options This appendix describes the configuration options for a Cortex-M4 processor implementation. It shows what features of a Cortex-M4 implementation are determined by the device manufacturer. It contains the following section: • Cortex-M4 implementation options on page A-2.
• the LSPERR bit in the BusFault Status Register (BFSR). Number of The implementer decides how many interrupts the Cortex-M4 implementation supports Cortex-M4 interrupts implementation supports, in the range 1-240. This affects: The range of IRQ values in Table 2-5 on page 2-6...
Page 271
Cortex-M4 Options Table A-1 Effects of the Cortex-M4 implementation options (continued) Option Description, and affected documentation Bit-banding The implementer decides whether bit-banding is implemented., see Optional bit-banding on page 2-16 Memory model on page 2-12. SysTick timer The SYST_CALIB register is implementation- defined. This can affect: •...
Page 272
Glossary This glossary describes some of the terms used in technical documents from ARM. A mechanism that indicates to a processor that the value associated with a memory access is Abort invalid. An abort can be caused by the external or internal memory system as a result of attempting to access invalid instruction or data memory.
Page 273
If the condition code flags indicate that the corresponding condition is true when the instruction starts executing, it executes normally. Otherwise, the instruction does nothing. The environment that each process operates in for a multitasking operating system. In ARM Context processors, this is limited to mean the physical address range that it can access in memory and the associated memory access permissions.
Need help?
Do you have a question about the Cortex-M4 and is the answer not in the manual?
Questions and answers