ST STM32F4 Series Programming Manual

ST STM32F4 Series Programming Manual

Cortex-m4
Hide thumbs Also See for STM32F4 Series:
Table of Contents

Advertisement

Quick Links

STM32F3 Series, STM32F4 Series, STM32L4 Series and
Introduction
This programming manual provides information for application and system-level software
developers. It gives a full description of the STM32 Cortex
model, instruction set and core peripherals.
The STM32F3 Series, STM32F4 Series, STM32L4 Series and STM32L4+ Series
®
Cortex
-M4 processor is a high performance 32-bit processor designed for the
microcontroller market. It offers significant benefits to developers, including:
• Outstanding processing performance combined with fast interrupt handling
• Enhanced system debug with extensive breakpoint and trace capabilities
• Efficient processor core, system and memories
• Ultra-low power consumption with integrated sleep modes
• Platform security

Reference documents

Available from STMicroelectronics web site www.st.com:
STM32F3 Series, STM32F4 Series, STM32L4 Series and STM32L4+ Series
datasheets
STM32F3 Series, STM32F4 Series, STM32L4 Series and STM32L4+ Series reference
manuals
October 2017
STM32L4+ Series Cortex
DocID022708 Rev 6
Programming manual
®
-M4 programming manual
®
-M4 processor programming
PM0214
1/260
www.st.com
1

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the STM32F4 Series and is the answer not in the manual?

Questions and answers

Summary of Contents for ST STM32F4 Series

  • Page 1: Reference Documents

    It gives a full description of the STM32 Cortex -M4 processor programming model, instruction set and core peripherals. The STM32F3 Series, STM32F4 Series, STM32L4 Series and STM32L4+ Series ® Cortex -M4 processor is a high performance 32-bit processor designed for the microcontroller market.
  • Page 2: Table Of Contents

    Contents PM0214 Contents About this document ........12 Typographical conventions .
  • Page 3 PM0214 Contents Fault handling ..........43 2.4.1 Fault types .
  • Page 4 Contents PM0214 3.5.3 ASR, LSL, LSR, ROR, and RRX ......85 3.5.4 CLZ .
  • Page 5 PM0214 Contents 3.7.2 SSAT16 and USAT16 ........126 3.7.3 QADD and QSUB .
  • Page 6 Contents PM0214 3.10.18 VMOV ARM Core register to scalar ......167 3.10.19 VMRS ..........168 3.10.20 VMSR .
  • Page 7 PM0214 Contents 4.2.9 MPU region attribute and size register (MPU_RASR) ... . . 203 4.2.10 MPU register map ........205 Nested vectored interrupt controller (NVIC) .
  • Page 8 Contents PM0214 4.5.3 SysTick current value register (STK_VAL) ..... . 248 4.5.4 SysTick calibration value register (STK_CALIB) ....249 4.5.5 SysTick design hints and tips .
  • Page 9 PM0214 List of tables List of tables Table 1. Summary of processor mode, execution privilege level, and stack usage ... . . 17 Table 2. Core register set summary ..........17 Table 3.
  • Page 10 List of tables PM0214 Table 49. Summary of the system control block registers ....... . 220 Table 50.
  • Page 11 PM0214 List of figures List of figures Figure 1. STM32 Cortex-M4 implementation ......... . . 13 Figure 2.
  • Page 12: About This Document

    About this document PM0214 About this document 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 products.
  • Page 13: About The Stm32 Cortex-M4 Processor And Core Peripherals

    PM0214 About this document About the STM32 Cortex-M4 processor and core peripherals The Cortex-M4 processor is a high performance 32-bit processor designed for the microcontroller market. It offers significant benefits to developers, including: • outstanding processing performance combined with fast interrupt handling •...
  • Page 14: System Level Interface

    About this document PM0214 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 suspend load-multiple and store-multiple operations.
  • Page 15: Cortex-M4 Core Peripherals

    PM0214 About this document 1.3.4 Cortex-M4 core peripherals The peripherals are: Nested vectored interrupt controller The nested vectored interrupt controller (NVIC) is an embedded interrupt controller that supports low latency interrupt processing. System control block The system control block (SCB) is the programmer’s model interface to the processor. It provides system implementation information and system control, including configuration, control, and reporting of system exceptions.
  • Page 16: The Cortex-M4 Processor

    The Cortex-M4 processor PM0214 The Cortex-M4 processor Programmers model This section describes the Cortex-M4 programmer’s 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 The processor modes are: Thread mode: Used to execute application software.
  • Page 17: Core Registers

    PM0214 The Cortex-M4 processor Table 1. Summary of processor mode, execution privilege level, and stack usage Processor Used to Privilege level for Stack used mode execute software execution Thread Applications Privileged or unprivileged Main stack or process stack Handler Exception handlers Always privileged Main stack 1.
  • Page 18: Stack Pointer

    The Cortex-M4 processor PM0214 Table 2. Core register set summary (continued) Required Reset Name Type Description privilege value read-write Privileged 0x01000000 Program status register on page 18 Application program status register on ASPR read-write Either Unknown page 20 Interrupt program status register on IPSR read-only Privileged...
  • Page 19: Table 3. Psr Register Combinations

    PM0214 The Cortex-M4 processor These registers are mutually exclusive bitfields in the 32-bit PSR. The bit assignments are as shown in Figure 3 Figure Figure 3. APSR, IPSR and EPSR bit assignments 31 30 29 28 27 25 24 23 16 15 10 9 APSR...
  • Page 20: Table 4. Apsr Bit Definitions

    The Cortex-M4 processor PM0214 Application program status register The APSR contains the current state of the condition flags from previous instruction executions. See the register summary in Table 2 on page 17 for its attributes. The bit assignments are: Table 4. APSR bit definitions Bits Description Bit 31...
  • Page 21: Table 5. Ipsr Bit Definitions

    PM0214 The Cortex-M4 processor Interrupt program status register The IPSR contains the exception type number of the current Interrupt Service Routine (ISR). See the register summary in Table 2 on page 17 for its attributes. The bit assignments are: Table 5. IPSR bit definitions Bits Description Bits 31:9...
  • Page 22: Table 6. Epsr Bit Definitions

    The Cortex-M4 processor PM0214 Table 6. EPSR bit definitions Bits Description Bits 31:27 Reserved. Bits 26:25, 15:10 ICI: Interruptible-continuable instruction bits, see Interruptible-continuable instructions on page IT on page 144 Bits 26:25, 15:10 IT: Indicates the execution state bits of the IT instruction, see Bit 24 T: Thumb state bit.
  • Page 23: Table 7. Primask Register Bit Definitions

    PM0214 The Cortex-M4 processor To access the exception mask registers use the MSR and MRS instructions, or the CPS instruction to change the value of PRIMASK or FAULTMASK. See MRS on page 185, on page 186, and CPS on page 181 for more information.
  • Page 24: Table 9. Basepri Register Bit Assignments

    The Cortex-M4 processor PM0214 Base priority mask register The BASEPRI register defines the minimum priority for exception processing. When BASEPRI is set to a nonzero value, it prevents the activation of all exceptions with same or lower priority level as the BASEPRI value. See the register summary in Table 2 on page 17 for its attributes.
  • Page 25: Exceptions And Interrupts

    PM0214 The Cortex-M4 processor 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 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.
  • Page 26 The Cortex-M4 processor PM0214 The CMSIS includes address definitions and data structures for the core peripherals in the Cortex-M4 processor. CMSIS simplifies software development by enabling the reuse of template code and the combination of CMSIS-compliant software components from various middleware vendors. Software vendors can expand the CMSIS to include their peripheral definitions and access functions for those peripherals.
  • Page 27: Memory Model

    PM0214 The Cortex-M4 processor Memory model This section describes the processor memory map, the behavior of memory accesses, and the bit-banding features. The processor has a fixed memory map that provides up to 4 GB of addressable memory. Figure 8. Memory map 0xFFFFFFFF Vendor-specific 511MB...
  • Page 28: Memory Regions, Types And Attributes

    The Cortex-M4 processor PM0214 2.2.1 Memory regions, types and attributes The memory map and the programming of the MPU splits the memory map into regions. Each region has a defined memory type, and some regions have additional memory attributes. The memory type and attributes determine the behavior of accesses to the region.
  • Page 29: Behavior Of Memory Accesses

    PM0214 The Cortex-M4 processor 2.2.3 Behavior of memory accesses The behavior of accesses to each region in the memory map is: Table 12. Memory access behavior Address Memory Memory Description range region type 0x00000000- Executable region for program code. Can also put Code Normal 0x1FFFFFFF...
  • Page 30: Software Ordering Of Memory Accesses

    The Cortex-M4 processor PM0214 2.2.4 Software ordering of memory accesses The order of instructions in the program flow does not always guarantee the order of the corresponding memory transactions. The reason for this is that: • The processor can reorder some memory accesses to improve efficiency, providing this does not affect the behavior of the instruction sequence.
  • Page 31: Bit-Banding

    PM0214 The Cortex-M4 processor 2.2.5 Bit-banding A bit-band region maps each word in a bit-band alias region to a single bit in the bit-band region. The bit-band regions occupy the lowest 1 Mbyte of the SRAM and peripheral memory regions. The memory map has two 32 Mbyte alias regions that map to two 1 Mbyte bit-band regions: •...
  • Page 32: Figure 9. Bit-Band Mapping

    The Cortex-M4 processor PM0214 Where: • Bit_word_offset is the position of the target bit in the bit-band memory region. • Bit_word_addr is the address of the word in the alias memory region that maps to the targeted bit. • Bit_band_base is the starting address of the alias region. •...
  • Page 33: Memory Endianness

    PM0214 The Cortex-M4 processor Reading a word in the alias region: • 0x00000000 indicates that the targeted bit in the bit-band region is set to zero • 0x00000001 indicates that the targeted bit in the bit-band region is set to 1 Directly accessing a bit-band region Behavior of memory accesses on page 29 describes the behavior of direct byte, halfword,...
  • Page 34 The Cortex-M4 processor PM0214 The pairs of Load-Exclusive and Store-Exclusive instructions are: • The word instructions LDREX and STREX • The halfword instructions LDREXH and STREXH • The byte instructions LDREXB and STREXB. Software must use a Load-Exclusive instruction with the corresponding Store-Exclusive instruction.
  • Page 35: Programming Hints For The Synchronization Primitives

    PM0214 The Cortex-M4 processor 2.2.8 Programming hints for the synchronization primitives ISO/IEC C cannot directly generate the exclusive access instructions. CMSIS provides intrinsic functions for generation of these instructions: Table 15. CMSIS functions for exclusive access instructions Instruction CMSIS function LDREX uint32_t __LDREXW (uint32_t *addr) LDREXH...
  • Page 36: Exception Model

    The Cortex-M4 processor PM0214 Exception model This section describes the exception model. 2.3.1 Exception states Each exception is in one of the following states: Inactive The exception is not active and not pending. Pending The exception is waiting to be serviced by the processor. An interrupt request from a peripheral or from software can change the state of the corresponding interrupt to pending.
  • Page 37: Table 16. Properties Of The Different Exception Types

    PM0214 The Cortex-M4 processor Bus fault A bus fault is an exception that occurs because of a memory related fault for an instruction or data memory transaction. This might be from an error detected on a bus in the memory system. Usage fault A usage fault is an exception that occurs in case of an instruction execution fault.
  • Page 38: Exception Handlers

    The Cortex-M4 processor PM0214 Table 16. Properties of the different exception types (continued) Exception Exception Vector address Priority Activation number number type or offset SysTick Configurable 0x0000003C Asynchronous 16 and 0 and 0x00000040 and Interrupt (IRQ) Configurable Asynchronous above above above 1.
  • Page 39: Vector Table

    PM0214 The Cortex-M4 processor 2.3.4 Vector table The vector table contains the reset value of the stack pointer, and the start addresses, also called exception vectors, for all exception handlers. Figure 11 on page 39 shows the order of the exception vectors in the vector table. The least-significant bit of each vector must be 1, indicating that the exception handler is Thumb code.
  • Page 40: Exception Priorities

    The Cortex-M4 processor PM0214 2.3.5 Exception priorities Table 16 on page 37 shows that all exceptions have an associated priority, in details: • A lower priority value indicating a higher priority • Configurable priorities for all exceptions except Reset, Hard fault, and NMI. If software does not configure any priorities, then all exceptions with a configurable priority have a priority of 0.
  • Page 41: Exception Entry And Return

    PM0214 The Cortex-M4 processor 2.3.7 Exception entry and return Descriptions of exception handling use the following terms: Preemption 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.
  • Page 42: Figure 12. Cortex-M4 Stack Frame Layout

    The Cortex-M4 processor PM0214 stack frame is the same as that of ARMv7-M implementations without an FPU. Figure 12 on page 42 also shows this stack frame. Figure 12. Cortex-M4 stack frame layout Pre-IRQ top of stack {aligner} FPSCR Pre-IRQ top of stack {aligner} Decreasing memory...
  • Page 43: Fault Handling

    PM0214 The Cortex-M4 processor Exception return Exception return occurs when the processor is in Handler mode and executes one of the following instructions to load the EXC_RETURN value into the PC: • an LDM or POP instruction that loads the PC •...
  • Page 44: Fault Types

    The Cortex-M4 processor PM0214 2.4.1 Fault types Table 18 shows the types of fault, the handler used for the fault, the corresponding fault status register, and the register bit that indicates that the fault has occurred. See Configurable fault status register (CFSR; UFSR+BFSR+MMFSR) on page 236 for more information about the fault status registers.
  • Page 45: Fault Escalation And Hard Faults

    PM0214 The Cortex-M4 processor 2.4.2 Fault escalation and hard faults All faults exceptions except for hard fault have configurable exception priority, as described System handler priority registers (SHPRx) on page 232. Software can disable execution of the handlers for these faults, as described in System handler control and state register (SHCSR) on page 234.
  • Page 46: Fault Status Registers And Fault Address Registers

    The Cortex-M4 processor PM0214 2.4.3 Fault status registers and fault address registers The fault status registers indicate the cause of a fault. For bus faults and memory management faults, the fault address register indicates the address accessed by the operation that caused the fault, as shown in Table Table 19.
  • Page 47: Entering Sleep Mode

    PM0214 The Cortex-M4 processor 2.5.1 Entering sleep mode This section describes the mechanisms software can use to put the processor into sleep mode. The system can generate spurious wakeup events, for example a debug operation that wakes up the processor. Therefore software must be able to put the processor back into sleep mode after such an event.
  • Page 48: External Event Input / Extended Interrupt And Event Input

    The Cortex-M4 processor PM0214 Wakeup from WFE The processor wakes up if: • it detects an exception with sufficient priority to cause exception entry • it detects an external event signal, see Section 2.5.3: External event input / extended interrupt and event input •...
  • Page 49: The Stm32 Cortex-M4 Instruction Set

    PM0214 The STM32 Cortex-M4 instruction set The STM32 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: Section 3.1: Instruction set summary on page 49 Section 3.2: CMSIS intrinsic functions on page 57 Section 3.3: About the instruction descriptions on page 59 Each of the following sections describes a functional group of Cortex-M4 instructions.
  • Page 50 The STM32 Cortex-M4 instruction set PM0214 Table 20. Cortex-M4 instructions (continued) Mnemonic Operands Brief description Flags Page AND, ANDS {Rd,} Rn, Op2 Logical AND N,Z,C 3.5.2 on page 84 ASR, ASRS Rd, Rm, <Rs|#n> Arithmetic shift right N,Z,C 3.5.3 on page 85 label Branch —...
  • Page 51 PM0214 The STM32 Cortex-M4 instruction set Table 20. Cortex-M4 instructions (continued) Mnemonic Operands Brief description Flags Page Load register exclusive with LDREXB Rt, [Rn] — 3.4.8 on page 78 byte Load register exclusive with LDREXH Rt, [Rn] — 3.4.8 on page 78 halfword LDRH, Rt, [Rn, #offset]...
  • Page 52 The STM32 Cortex-M4 instruction set PM0214 Table 20. Cortex-M4 instructions (continued) Mnemonic Operands Brief description Flags Page QDADD {Rd,} Rn, Rm Saturating add 3.7.5 on page 129 Saturating double and QDSUB {Rd,} Rn, Rm 3.7.5 on page 129 subtract Saturating subtract and add QSAX {Rd,} Rn, Rm 3.7.4 on page 128...
  • Page 53 PM0214 The STM32 Cortex-M4 instruction set Table 20. Cortex-M4 instructions (continued) Mnemonic Operands Brief description Flags Page Signed multiply with SMLAL RdLo, RdHi, Rn, Rm accumulate (32 x 32 + 64), 64- — 3.6.2 on page 110 bit result SMLALBB, Signed multiply accumulate SMLALBT, RdLo, RdHi, Rn, Rm...
  • Page 54 The STM32 Cortex-M4 instruction set PM0214 Table 20. Cortex-M4 instructions (continued) Mnemonic Operands Brief description Flags Page STRD Rt, Rt2, [Rn, #offset] Store register two words — 3.4.2 on page 70 STREX Rd, Rt, [Rn, #offset] Store register exclusive — 3.4.8 on page 78 STREXB Rd, Rt, [Rn]...
  • Page 55 PM0214 The STM32 Cortex-M4 instruction set Table 20. Cortex-M4 instructions (continued) Mnemonic Operands Brief description Flags Page UDIV {Rd,} Rn, Rm Unsigned divide — 3.6.3 on page 111 Unsigned multiply accumulate UMAAL RdLo, RdHi, Rn, Rm accumulate long (32 x 32 + 32 —...
  • Page 56 The STM32 Cortex-M4 instruction set PM0214 Table 20. Cortex-M4 instructions (continued) Mnemonic Operands Brief description Flags Page Compare two floating-point VCMP.F32 Sd, <Sm | #0.0> registers, or one floating-point FPSCR 3.10.3 on page 152 register and zero Compare two floating-point registers, or one floating-point VCMPE.F32 Sd, <Sm | #0.0>...
  • Page 57: Cmsis Intrinsic Functions

    PM0214 The STM32 Cortex-M4 instruction set Table 20. Cortex-M4 instructions (continued) Mnemonic Operands Brief description Flags Page Copy ARM core register to 3.10.15 on page VMOV Dd[x], Rt — scalar Copy scalar to ARM core 3.10.16 on page VMOV Rt, Dn[x] —...
  • Page 58: Table 21. Cmsis Intrinsic Functions To Generate Some Cortex-M4 Instructions

    The STM32 Cortex-M4 instruction set PM0214 Table 21. CMSIS intrinsic functions to generate some Cortex-M4 instructions Instruction CMSIS intrinsic function CPSIE I void __enable_irq(void) CPSID I void __disable_irq(void) CPSIE F void __enable_fault_irq(void) CPSID F void __disable_fault_irq(void) void __ISB(void) void __DSB(void) void __DMB(void) uint32_t __REV(uint32_t int value) REV16...
  • Page 59: About The Instruction Descriptions

    PM0214 The STM32 Cortex-M4 instruction set About the instruction descriptions The following sections give more information about using the instructions: • Operands on page 59 • Restrictions when using PC or SP on page 59 • Flexible second operand on page 59 •...
  • Page 60 The STM32 Cortex-M4 instruction set PM0214 Constant You specify an operand2 constant in the form #constant, where constant can be: • Any constant that can be produced by shifting an 8-bit value left by any number of bits within a 32-bit word. •...
  • Page 61: Shift Operations

    PM0214 The STM32 Cortex-M4 instruction set 3.3.4 Shift operations Register shift operations move the bits in a register left or right by a specified number of bits, the shift length. Register shift can be performed: • Directly by the instructions ASR, LSR, LSL, ROR, and RRX. The result is written to a destination register.
  • Page 62: Figure 14. Lsr #3

    The STM32 Cortex-M4 instruction set PM0214 Logical shift right by n bits moves the left-hand 32-n bits of the Rm register to the right by n places, into the right-hand 32-n bits of the result. And it sets the left-hand n bits of the result to 0 (see Figure 14).
  • Page 63: Figure 16. Ror #3

    PM0214 The STM32 Cortex-M4 instruction set Rotate right by n bits moves the left-hand 32-n bits of the Rm register to the right by n places, into the right-hand 32-n bits of the result. It also moves the right-hand n bits of the register into the left-hand n bits of the result (see Figure 16).
  • Page 64: Address Alignment

    The STM32 Cortex-M4 instruction set PM0214 3.3.5 Address alignment 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.
  • Page 65 PM0214 The STM32 Cortex-M4 instruction set Conditional execution is available by using conditional branches or by adding condition code suffixes to instructions. See Table 23: Condition code suffixes on page 66 for a list of the suffixes to add to instructions to make them conditional instructions. The condition code suffix enables the processor to test a condition based on the flags.
  • Page 66: Table 23. Condition Code Suffixes

    The STM32 Cortex-M4 instruction set PM0214 Condition code suffixes The instructions that can be conditional have an optional condition code, shown in syntax descriptions as {cond}. Conditional execution requires a preceding IT instruction. An instruction with a condition code is only executed if the condition code flags in the APSR meet the specified condition.
  • Page 67: Instruction Width Selection

    PM0214 The STM32 Cortex-M4 instruction set CMPGT R2, R3; if 'greater than', compare R2 and R3, setting flags MOVGT R4, R5 ; if still 'greater than', do R4 = R5 3.3.8 Instruction width selection There are many instructions that can generate either a 16-bit encoding or a 32-bit encoding depending on the specified operands and destination register.
  • Page 68: Memory Access Instructions

    The STM32 Cortex-M4 instruction set PM0214 Memory access instructions Table 24 shows the memory access instructions: Table 24. Memory access instructions Mnemonic Brief description Load PC-relative address ADR on page 69 CLREX Clear exclusive CLREX on page 79 LDM{mode} Load multiple registers LDM and STM on page 75 LDR{type} Load register using immediate offset...
  • Page 69: Adr

    PM0214 The STM32 Cortex-M4 instruction set 3.4.1 Load PC-relative address. Syntax ADR{cond} Rd, label Where: • ‘cond’ is an optional condition code (see Conditional execution on page • ‘Rd’ is the destination register • ‘label’ is a PC-relative expression (see PC-relative expressions on page Operation ADR determines the address by adding an immediate value to the PC.
  • Page 70: Ldr And Str, Immediate Offset

    The STM32 Cortex-M4 instruction set PM0214 3.4.2 LDR and STR, immediate offset Load and Store with immediate offset, pre-indexed immediate offset, or post-indexed immediate offset. Syntax op{type}{cond} Rt, [Rn {, #offset}]; immediate offset op{type}{cond} Rt, [Rn, #offset]!; pre-indexed op{type}{cond} Rt, [Rn], #offset; post-indexed opD{cond} Rt, Rt2, [Rn {, #offset}];...
  • Page 71: Table 25. Immediate, Pre-Indexed And Post-Indexed Offset Ranges

    PM0214 The STM32 Cortex-M4 instruction set The value to load or store can be a byte, halfword, word, or two words. Bytes and halfwords can either be signed or unsigned (see Address alignment on page 64). Table 25 shows the range of offsets for immediate, pre-indexed and post-indexed forms. Table 25.
  • Page 72: Ldr And Str, Register Offset

    The STM32 Cortex-M4 instruction set PM0214 3.4.3 LDR and STR, register offset Load and Store with register offset. Syntax op{type}{cond} Rt, [Rn, Rm {, LSL #n}] Where: • ‘op’ is either LDR (load register) or STR (store register). • ‘type’ is one of the following: B: Unsigned byte, zero extends to 32 bits on loads.
  • Page 73: Ldr And Str, Unprivileged

    PM0214 The STM32 Cortex-M4 instruction set ; to a word value and put it in R0 STR R0, [R1, R2, LSL #2]; stores R0 to an address equal to sum of R1 ; and four times R2 3.4.4 LDR and STR, unprivileged Load and Store with unprivileged access.
  • Page 74: Ldr, Pc-Relative

    The STM32 Cortex-M4 instruction set PM0214 3.4.5 LDR, PC-relative Load register from memory. Syntax LDR{type}{cond} Rt, label LDRD{cond} Rt, Rt2, label; load two words Where: • ‘type’ is one of the following: B: Unsigned byte, zero extends to 32 bits. SB: Signed byte, sign extends to 32 bits.
  • Page 75: Ldm And Stm

    PM0214 The STM32 Cortex-M4 instruction set Condition flags These instructions do not change the flags. Examples LDR R0, LookUpTable; load R0 with a word of data from an address ; labelled as LookUpTable LDRSB R7, localdata; load a byte value from an address labelled ;...
  • Page 76 The STM32 Cortex-M4 instruction set PM0214 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 of Rn + 4 * (n-1) is written back to Rn. For LDMDB, LDMEA, STMDB, and STMFD the memory addresses used for the accesses are at 4-byte intervals ranging from Rn to Rn - 4 * (n-1), where n is the number of registers in reglist.
  • Page 77: Push And Pop

    PM0214 The STM32 Cortex-M4 instruction set 3.4.7 PUSH and POP Push registers onto, and pop registers off a full-descending stack. PUSH and POP are synonyms for STMDB and LDM (or LDMIA) with the memory addresses for the access based on SP, and with the final address for the access written back to the SP. PUSH and POP are the preferred mnemonics in these cases.
  • Page 78: Ldrex And Strex

    The STM32 Cortex-M4 instruction set PM0214 3.4.8 LDREX and STREX Load and Store Register Exclusive. Syntax LDREX{cond} Rt, [Rn {, #offset}] STREX{cond} Rd, Rt, [Rn {, #offset}] LDREXB{cond} Rt, [Rn] STREXB{cond} Rd, Rt, [Rn] LDREXH{cond} Rt, [Rn] STREXH{cond} Rd, Rt, [Rn] Where: •...
  • Page 79: Clrex

    PM0214 The STM32 Cortex-M4 instruction set Restrictions In these instructions: • Do not use PC. • Do not use SP for Rd and Rt. • For STREX, Rd must be different from both Rt and Rn. • The value of offset must be a multiple of four in the range 0-1020. Condition flags These instructions do not change the flags.
  • Page 80: General Data Processing Instructions

    The STM32 Cortex-M4 instruction set PM0214 General data processing instructions Table 27 shows the data processing instructions. Table 27. Data processing instructions Mnemonic Brief description Add with carry ADD, ADC, SUB, SBC, and RSB on page 82 ADD, ADC, SUB, SBC, and RSB on page 82 ADDW ADD, ADC, SUB, SBC, and RSB on page 82 Logical AND...
  • Page 81 PM0214 The STM32 Cortex-M4 instruction set Table 27. Data processing instructions (continued) Mnemonic Brief description SHASX Signed Halving Add and Subtract with Exchange SHASX and SHSAX on page 94 SHSAX Signed Halving Subtract and Add with exchange SHASX and SHSAX on page 94 SHSUB16 Signed Halving Subtract 16 SHSUB16 and SHSUB8 on page 95...
  • Page 82: Add, Adc, Sub, Sbc, And Rsb

    The STM32 Cortex-M4 instruction set PM0214 3.5.1 ADD, ADC, SUB, SBC, and RSB Add, Add with Carry, Subtract, Subtract with Carry, and Reverse Subtract. Syntax op{S}{cond} {Rd,} Rn, Operand2 op{cond} {Rd,} Rn, #imm12; ADD and SUB only Where: • ‘op’ is one of the following: ADD: Add ADC: Add with carry SUB: Subtract...
  • Page 83 PM0214 The STM32 Cortex-M4 instruction set Restrictions In these instructions: • Operand2 must be neither SP nor PC • Rd can be SP only in ADD and SUB, and only with the following additional restrictions: – Rn must also be SP. –...
  • Page 84: And, Orr, Eor, Bic, And Orn

    The STM32 Cortex-M4 instruction set PM0214 Multiword values do not have to use consecutive registers. Specific example 5: 96-bit subtraction shows instructions that subtract a 96-bit integer contained in R9, R1, and R11 from another contained in R6, R2, and R8. The example stores the result in R6, R9, and R2. Specific example 5: 96-bit subtraction SUBS R6, R6, R9 ;...
  • Page 85: Asr, Lsl, Lsr, Ror, And Rrx

    PM0214 The STM32 Cortex-M4 instruction set Condition flags If S is specified, these instructions: • Update the N and Z flags according to the result. • Can update the C flag during the calculation of operand2, see Flexible second operand on page •...
  • Page 86: Clz

    The STM32 Cortex-M4 instruction set PM0214 Operation ASR, LSL, LSR, and ROR move the bits in the Rm register to the left or right by the number of places specified by constant n or register Rs. RRX moves the bits in Rm register to the right by 1. In all these instructions, the result is written to Rd, but the value in Rm register remains unchanged.
  • Page 87: Cmp And Cmn

    PM0214 The STM32 Cortex-M4 instruction set Examples CLZ R4,R9 CLZNE R2,R3 3.5.5 CMP and CMN Compare and Compare Negative. Syntax CMP{cond} Rn, Operand2 CMN{cond} Rn, Operand2 Where: • ‘cond’ is an optional condition code (see Conditional execution on page 64). •...
  • Page 88: Mov And Mvn

    The STM32 Cortex-M4 instruction set PM0214 3.5.6 MOV and MVN Move and Move NOT. Syntax MOV{S}{cond} Rd, Operand2 MOV{cond} Rd, #imm16 MVN{S}{cond} Rd, Operand2 Where: • ‘S’ is an optional suffix. If S is specified, the condition code flags are updated on the result of the operation (see Conditional execution on page 64).
  • Page 89 PM0214 The STM32 Cortex-M4 instruction set Restrictions You can use SP and PC only in the MOV instruction, with the following restrictions: • The second operand must be a register without shift • You must not specify the S suffix When Rd is PC in a MOV instruction: •...
  • Page 90: Movt

    The STM32 Cortex-M4 instruction set PM0214 3.5.7 MOVT Move Top. Syntax MOVT{cond} Rd, #imm16 Where: • ‘cond’ is an optional condition code (see Conditional execution on page 64). • ‘Rd’ is the destination register. • ‘imm16’ is a 16-bit immediate constant. Operation MOVT writes a 16-bit immediate value, imm16, to the top halfword, Rd[31:16], of its destination register.
  • Page 91: Rev, Rev16, Revsh, And Rbit

    PM0214 The STM32 Cortex-M4 instruction set 3.5.8 REV, REV16, REVSH, and RBIT Reverse bytes and Reverse bits. Syntax op{cond} Rd, Rn Where: • ‘op’ is one of the following: REV: Reverse byte order in a word. REV16: Reverse byte order in each halfword independently. REVSH: Reverse byte order in the bottom halfword, and sign extends to 32 bits.
  • Page 92: Sadd16 And Sadd8

    The STM32 Cortex-M4 instruction set PM0214 3.5.9 SADD16 and SADD8 Signed Add 16 and Signed Add 8 Syntax op{cond}{Rd,} Rn, Rm Where: • op is any of the following: SADD16: Performs two 16-bit signed integer additions. SADD8: Performs four 8-bit signed integer additions. •...
  • Page 93: Shadd16 And Shadd8

    PM0214 The STM32 Cortex-M4 instruction set 3.5.10 SHADD16 and SHADD8 Signed Halving Add 16 and Signed Halving Add 8 Syntax op{cond}{Rd,} Rn, Rm Where: • op is any of the following: SHADD16: Signed halving add 16. SHADD8: Signed halving add 8. •...
  • Page 94: Shasx And Shsax

    The STM32 Cortex-M4 instruction set PM0214 3.5.11 SHASX and SHSAX Signed Halving Add and Subtract with Exchange / Signed Halving Subtract and Add with Exchange. Syntax op{cond} {Rd}, Rn, Rm Where: • op is any of the following: SHASX: Add and subtract with exchange and halving. SHSAX: Subtract and add with exchange and halving.
  • Page 95: Shsub16 And Shsub8

    PM0214 The STM32 Cortex-M4 instruction set ; R4 and writes halved result to bottom halfword of R7 SHSAX R0, R3, R5 ; Subtracts bottom halfword of R5 from top halfword ; of R3 and writes halved result to top halfword of R0 ;...
  • Page 96: Ssub16 And Ssub8

    The STM32 Cortex-M4 instruction set PM0214 ; and writes to corresponding byte in R4. 3.5.13 SSUB16 and SSUB8 Signed Subtract 16 and Signed Subtract 8 Syntax op{cond}{Rd,} Rn, Rm Where: • op is one of the following: SSUB16: Performs two 16-bit signed integer subtractions. SSUB8: Performs four 8-bit signed integer subtractions.
  • Page 97: Sasx And Ssax

    PM0214 The STM32 Cortex-M4 instruction set 3.5.14 SASX and SSAX Signed Add and Subtract with Exchange and Signed Subtract and Add with Exchange. Syntax op{cond} {Rd}, Rm, Rn Where: • op is any of the following: SASX: Signed add and subtract with exchange. SSAX: Signed subtract and add with exchange.
  • Page 98: Tst And Teq

    The STM32 Cortex-M4 instruction set PM0214 ; Adds top halfword of R3 with bottom halfword of R2 and ; writes to top halfword of R7. 3.5.15 TST and TEQ Test bits and Test Equivalence. Syntax TST{cond} Rn, Operand2 TEQ{cond} Rn, Operand2 Where: •...
  • Page 99: Uadd16 And Uadd8

    PM0214 The STM32 Cortex-M4 instruction set 3.5.16 UADD16 and UADD8 Unsigned Add 16 and Unsigned Add 8 Syntax op{cond}{Rd,} Rn, Rm Where: • op is one of the following: UADD16: Performs two 16-bit unsigned integer additions. UADD8: Performs four 8-bit unsigned integer additions. •...
  • Page 100: Uasx And Usax

    The STM32 Cortex-M4 instruction set PM0214 3.5.17 UASX and USAX Add and Subtract with Exchange and Subtract and Add with Exchange. Syntax op{cond} {Rd}, Rn, Rm Where: • op is one of: UASX: Add and subtract with exchange. USAX: Subtract and add with exchange. •...
  • Page 101: Uhadd16 And Uhadd8

    PM0214 The STM32 Cortex-M4 instruction set ; writes to top halfword of R7. 3.5.18 UHADD16 and UHADD8 Unsigned Halving Add 16 and Unsigned Halving Add 8 Syntax op{cond}{Rd,} Rn, Rm Where: • op is any of the following: UHADD16: Unsigned halving add 16. UHADD8: Unsigned halving add 8.
  • Page 102: Uhasx And Uhsax

    The STM32 Cortex-M4 instruction set PM0214 3.5.19 UHASX and UHSAX Unsigned Halving Add and Subtract with Exchange and Unsigned Halving Subtract and Add with Exchange. Syntax op{cond} {Rd}, Rn, Rm Where: • op is one of the following: UHASX: Add and subtract with exchange and halving. UHSAX: Subtract and add with exchange and halving.
  • Page 103: Uhsub16 And Uhsub8

    PM0214 The STM32 Cortex-M4 instruction set UHSAX R0, R3, R5 ; Subtracts bottom halfword of R5 from top halfword of ; R3 and writes halved result to top halfword of R0 ; Adds top halfword of R5 to bottom halfword of R3 and ;...
  • Page 104: Sel

    The STM32 Cortex-M4 instruction set PM0214 UHSUB8 R4, R0, R5 ; Subtracts bytes of R5 from corresponding byte in R0 and ; writes halved result to corresponding byte in R4. 3.5.21 Select bytes. Selects each byte of its result from either its first operand or its second operand, according to the values of the GE flags.
  • Page 105: Usad8

    PM0214 The STM32 Cortex-M4 instruction set 3.5.22 USAD8 Unsigned Sum of Absolute Differences Syntax USAD8{cond}{Rd,} Rn, Rm Where: • ‘cond’ is an optional condition code (see Conditional execution on page 64). • ‘Rd’ is the destination register. • ‘Rn’ is the first operand register. •...
  • Page 106: Usada8

    The STM32 Cortex-M4 instruction set PM0214 3.5.23 USADA8 Unsigned Sum of Absolute Differences and Accumulate Syntax USADA8{cond}{Rd,} Rn, Rm, Ra Where: • ‘cond’ is an optional condition code (see Conditional execution on page 64). • ‘Rd’ is the destination register. •...
  • Page 107: Usub16 And Usub8

    PM0214 The STM32 Cortex-M4 instruction set 3.5.24 USUB16 and USUB8 Unsigned Subtract 16 and Unsigned Subtract 8 Syntax op{cond}{Rd,} Rn, Rm Where: • op is any of: USUB16: Unsigned Subtract 16. USUB8: Unsigned Subtract 8. • ‘cond’ is an optional condition code (see Conditional execution on page •...
  • Page 108: Multiply And Divide Instructions

    The STM32 Cortex-M4 instruction set PM0214 Multiply and divide instructions Table 28 shows the multiply and divide instructions. Table 28. Multiply and divide instructions Mnemonic Brief description Multiply with Accumulate, 32-bit result MUL, MLA, and MLS on page 109 Multiply and Subtract, 32-bit result MUL, MLA, and MLS on page 109 Multiply, 32-bit result MUL, MLA, and MLS on page 109...
  • Page 109: Mul, Mla, And Mls

    PM0214 The STM32 Cortex-M4 instruction set 3.6.1 MUL, MLA, and MLS Multiply, Multiply with Accumulate, and Multiply with Subtract, using 32-bit operands, and producing a 32-bit result. Syntax MUL{S}{cond} {Rd,} Rn, Rm ; Multiply MLA{cond} Rd, Rn, Rm, Ra ; Multiply with accumulate MLS{cond} Rd, Rn, Rm, Ra ;...
  • Page 110: Umull, Umaal And Umlal

    The STM32 Cortex-M4 instruction set PM0214 3.6.2 UMULL, UMAAL and UMLAL Unsigned Long Multiply, with Optional Accumulate, 32-bit operands, producing a 64-bit result. Syntax op{cond} RdLo, RdHi, Rn, Rm Where: • ‘op’ is one of the following: UMULL: Unsigned long multiply. UMAAL: Unsigned long multiply, with accumulate accumulate.
  • Page 111: Smla And Smlaw

    PM0214 The STM32 Cortex-M4 instruction set ; top 32 bits to R6, and the bottom 32 bits to R3 UMLAL R2, R1, R3, R5 ; Multiplies R5 and R3, adds R1:R2, writes to R1:R2. 3.6.3 SMLA and SMLAW Signed Multiply Accumulate (halfwords). Syntax op{XY}{cond} Rd, Rn, Rm op{Y}{cond} Rd, Rn, Rm, Ra...
  • Page 112 The STM32 Cortex-M4 instruction set PM0214 Condition flags If an overflow is detected, the Q flag is set. Examples SMLABB R5, R6, R4, R1 ; Multiplies bottom halfwords of R6 and R4, adds ; R1 and writes to R5 SMLATB R5, R6, R4, R1 ;...
  • Page 113: Smlad

    PM0214 The STM32 Cortex-M4 instruction set 3.6.4 SMLAD Signed Multiply Accumulate Long Dual Syntax op{X}{cond} Rd, Rn, Rm, Ra Where: • op is one of the following: SMLAD: Signed multiply accumulate dual. SMLADX: Signed multiply accumulate dual reverse. X specifies which halfword of the source register Rn is used as the multiply operand.
  • Page 114: Smlal And Smlald

    The STM32 Cortex-M4 instruction set PM0214 3.6.5 SMLAL and SMLALD Signed Multiply Accumulate Long, Signed Multiply Accumulate Long (halfwords) and Signed Multiply Accumulate Long Dual. Syntax op{cond} RdLo, RdHi, Rn, Rm op{XY}{cond} RdLo, RdHi, Rn, Rm op{X}{cond} RdLo, RdHi, Rn, Rm Where: •...
  • Page 115 PM0214 The STM32 Cortex-M4 instruction set The SMLALD and SMLALDX instructions interpret the values from Rn and Rm as four halfword two’s complement signed 16-bit integers. These instructions: • If X is not present, multiply the top signed halfword value of Rn with the top signed halfword of Rm and the bottom signed halfword values of Rn with the bottom signed halfword of Rm.
  • Page 116: Smlsd And Smlsld

    The STM32 Cortex-M4 instruction set PM0214 3.6.6 SMLSD and SMLSLD Signed Multiply Subtract Dual and Signed Multiply Subtract Long Dual Syntax op{X}{cond} Rd, Rn, Rm, Ra Where: • op is one of: SMLSD: Signed multiply subtract dual. SMLSDX: Signed multiply subtract dual reversed SMLSLD: Signed multiply subtract long dual.
  • Page 117 PM0214 The STM32 Cortex-M4 instruction set For the Thumb instruction set, these instructions do not affect the condition code flags. Examples SMLS R0, R4, R5, R6 ; Multiplies bottom halfword of R4 with bottom ; halfword of R5, multiplies top halfword of R4 ;...
  • Page 118: Smmla And Smmls

    The STM32 Cortex-M4 instruction set PM0214 3.6.7 SMMLA and SMMLS Signed Most Significant Word Multiply Accumulate and Signed Most Significant Word Multiply Subtract. Syntax op{R}{cond} Rd, Rn, Rm, Ra Where: • op is one of the following: SMMLA: Signed most significant word multiply accumulate. SMMLS: Signed most significant word multiply subtract.
  • Page 119: Smmul

    PM0214 The STM32 Cortex-M4 instruction set SMMLS R4, R5, R3, R8 ; Multiplies R5 and R3, extracts top 32 bits, ; subtracts R8, truncates and writes to R4. 3.6.8 SMMUL Signed most significant word multiply Syntax op{R}{cond} Rd, Rn, Rm Where: •...
  • Page 120: Smuad And Smusd

    The STM32 Cortex-M4 instruction set PM0214 3.6.9 SMUAD and SMUSD Signed Dual Multiply Add and Signed Dual Multiply Subtract Syntax op{X}{cond} Rd, Rn, Rm Where: • op is one of: SMUAD: Signed dual multiply add. SMUADX: Signed dual multiply add reversed. SMUSD: Signed dual multiply subtract.
  • Page 121: Smul And Smulw

    PM0214 The STM32 Cortex-M4 instruction set SMUSD R3, R6, R2 ; Multiplies bottom halfword of R4 with bottom halfword ; of R6, subtracts multiplication of top halfword of R6 ; with top halfword of R3, writes to R3 SMUSDX R4, R5, R3 ; Multiplies bottom halfword of R5 with top halfword of ;...
  • Page 122: Umull, Umlal, Smull, And Smlal

    The STM32 Cortex-M4 instruction set PM0214 SMULBB R0, R4, R5 ; Multiplies the bottom halfword of R4 with the bottom ; halfword of R5, multiplies results and writes to R0 SMULTT R0, R4, R5 ; Multiplies the top halfword of R4 with the top ;...
  • Page 123: Sdiv And Udiv

    PM0214 The STM32 Cortex-M4 instruction set Restrictions In these instructions: • Do not use either SP or PC • RdHi and RdLo must be different registers. Condition flags These instructions do not affect the condition code flags. Examples UMULL R0, R4, R5, R6 ;...
  • Page 124: Saturating Instructions

    The STM32 Cortex-M4 instruction set PM0214 Saturating instructions This section describes the saturating instructions. Table 29. Saturating instructions Mnemonic Brief description SSAT Signed Saturate SSAT and USAT on page 125 SSAT16 Signed Saturate Halfword SSAT16 and USAT16 on page 126 USAT Unsigned Saturate SSAT and USAT on page 125...
  • Page 125: Ssat And Usat

    PM0214 The STM32 Cortex-M4 instruction set 3.7.1 SSAT and USAT Signed Saturate and Unsigned Saturate to any bit position, with optional shift before saturating. Syntax op{cond} Rd, #n, Rm {, shift #s} Where: • op’ is one of: SSAT: Saturates a signed value to a signed range. USAT: Saturates a signed value to an unsigned range.
  • Page 126: Ssat16 And Usat16

    The STM32 Cortex-M4 instruction set PM0214 3.7.2 SSAT16 and USAT16 Signed Saturate and Unsigned Saturate to any bit position for two halfwords. Syntax op{cond} Rd, #n, Rm Where: • op’ is one of: SSAT16 Saturates a signed halfword value to a signed range. USAT16 Saturates a signed halfword value to an unsigned range.
  • Page 127: Qadd And Qsub

    PM0214 The STM32 Cortex-M4 instruction set 3.7.3 QADD and QSUB Saturating Add and Saturating Subtract, signed. Syntax op{cond} {Rd}, Rn, Rm op{cond} {Rd}, Rn, Rm Where: • op’ is one of: QADD: Saturating 32-bit add. QADD8: Saturating four 8-bit integer additions. QADD16: Saturating two 16-bit integer additions.
  • Page 128: Qasx And Qsax

    The STM32 Cortex-M4 instruction set PM0214 ; of R2, saturates to 16 bits, writes to corresponding ; halfword of R4 QSUB8 R4, R2, R5 ; Subtracts bytes of R5 from the corresponding byte in R2 ; saturates to 8 bits, writes to corresponding byte ofR4. 3.7.4 QASX and QSAX Saturating Add and Subtract with Exchange and Saturating Subtract and Add with...
  • Page 129: Qdadd And Qdsub

    PM0214 The STM32 Cortex-M4 instruction set ; Subtracts top highword of R2 from bottom halfword of ; R4, saturates to 16 bits and writes to bottom halfword ; of R7 QSAX R0, R3, R5 ; Subtracts bottom halfword of R5 from top halfword of ;...
  • Page 130: Uqasx And Uqsax

    The STM32 Cortex-M4 instruction set PM0214 ; from R5, saturates to 32 bits, writes to R0. 3.7.6 UQASX and UQSAX Saturating Add and Subtract with Exchange and Saturating Subtract and Add with Exchange, unsigned. Syntax op{cond} {Rd}, Rm, Rn Where: •...
  • Page 131: Uqadd And Uqsub

    PM0214 The STM32 Cortex-M4 instruction set ; R4, saturates to 16 bits, writes to bottom halfword of R7 UQSAX R0, R3, R5 ; Subtracts bottom halfword of R5 from top halfword of ; R3, saturates to 16 bits, writes to top halfword of R0 ;...
  • Page 132 The STM32 Cortex-M4 instruction set PM0214 Restrictions Do not use SP and do not use PC. Condition flags These instructions do not affect the condition code flags. Examples UQADD16 R7, R4, R2; Adds halfwords in R4 to corresponding halfword in R2, ;...
  • Page 133: Packing And Unpacking Instructions

    PM0214 The STM32 Cortex-M4 instruction set Packing and unpacking instructions Table 30 shows the instructions that operate on packing and unpacking data: Table 30. Packing and unpacking instructions Mnemonic Brief description Pack Halfword PKHBT and PKHTB on page 134 SXTAB Extend 8 bits to 32 and add SXTA and UXTA on page 136 SXTAB16...
  • Page 134: Pkhbt And Pkhtb

    The STM32 Cortex-M4 instruction set PM0214 3.8.1 PKHBT and PKHTB Pack Halfword Syntax op{cond} {Rd}, Rn, Rm {, LSL #imm} op{cond} {Rd}, Rn, Rm {, ASR #imm} Where: • op’ is one of: PKHBT Pack Halfword, bottom and top with shift. PKHTB Pack Halfword, top and bottom with shift.
  • Page 135: Sxt And Uxt

    PM0214 The STM32 Cortex-M4 instruction set 3.8.2 SXT and UXT Sign extend and Zero extend. Syntax op{cond} {Rd,} Rm {, ROR #n} op{cond} {Rd}, Rm {, ROR #n} Where: • op’ is one of: SXTB Sign extends an 8-bit value to a 32-bit value. SXTH Sign extends a 16-bit value to a 32-bit value.
  • Page 136: Sxta And Uxta

    The STM32 Cortex-M4 instruction set PM0214 Examples SXTH R4, R6, ROR #16 ; Rotates R6 right by 16 bits, obtains bottom halfword ; of result, sign extends to 32 bits and writes to R4 UXTB R3, R10 ; Extracts lowest byte of value in R10, zero extends, and ;...
  • Page 137: Bitfield Instructions

    PM0214 The STM32 Cortex-M4 instruction set Restrictions Do not use SP and do not use PC. Condition flags These instructions do not affect the flags. Examples SXTAH R4, R8, R6, ROR #16 ; Rotates R6 right by 16 bits, obtains bottom ;...
  • Page 138: Bfc And Bfi

    The STM32 Cortex-M4 instruction set PM0214 3.9.1 BFC and BFI Bit Field Clear and Bit Field Insert. Syntax BFC{cond} Rd, #lsb, #width BFI{cond} Rd, Rn, #lsb, #width Where: • ‘cond’ is an optional condition code, see Conditional execution on page •...
  • Page 139: Sbfx And Ubfx

    PM0214 The STM32 Cortex-M4 instruction set 3.9.2 SBFX and UBFX Signed Bit Field Extract and Unsigned Bit Field Extract. Syntax SBFX{cond} Rd, Rn, #lsb, #width UBFX{cond} Rd, Rn, #lsb, #width Where: • ‘cond’ is an optional condition code, see Conditional execution on page •...
  • Page 140: Sxt And Uxt

    The STM32 Cortex-M4 instruction set PM0214 3.9.3 SXT and UXT Sign extend and Zero extend. Syntax SXTextend{cond} {Rd,} Rm {, ROR #n} UXTextend{cond} {Rd}, Rm {, ROR #n} Where: • ‘extend’ is one of: B: Extends an 8-bit value to a 32-bit value. H: Extends a 16-bit value to a 32-bit value.
  • Page 141: Branch And Control Instructions

    PM0214 The STM32 Cortex-M4 instruction set 3.9.4 Branch and control instructions Table 32 shows the branch and control instructions: Table 32. Branch and control instructions Mnemonic Brief description Branch B, BL, BX, and BLX on page 141 Branch with Link B, BL, BX, and BLX on page 141 Branch indirect with Link B, BL, BX, and BLX on page 141...
  • Page 142: Table 33. Branch Ranges

    The STM32 Cortex-M4 instruction set PM0214 B cond label is the only conditional instruction that can be either inside or outside an IT block. All other branch instructions must be conditional inside an IT block, and must be unconditional outside the IT block, see IT on page 144.
  • Page 143: Cbz And Cbnz

    PM0214 The STM32 Cortex-M4 instruction set ; Branch with link and exchange (Call) to a address stored ; in R0 3.9.6 CBZ and CBNZ Compare and Branch on Zero, Compare and Branch on Non-Zero. Syntax CBZ Rn, label CBNZ Rn, label Where: •...
  • Page 144 The STM32 Cortex-M4 instruction set PM0214 3.9.7 If-Then condition instruction. Syntax IT{x{y{z}}} cond Where: • ‘x’ specifies the condition switch for the second instruction in the IT block. • ‘y’ specifies the condition switch for the third instruction in the IT block. •...
  • Page 145 PM0214 The STM32 Cortex-M4 instruction set Other restrictions when using an IT block are: • a branch or any instruction that modifies the PC must either be outside an IT block or must be the last instruction inside the IT block. These are: –...
  • Page 146: Tbb And Tbh

    The STM32 Cortex-M4 instruction set PM0214 3.9.8 TBB and TBH Table Branch Byte and Table Branch Halfword. Syntax TBB [Rn, Rm] TBH [Rn, Rm, LSL #1] Where: • ‘Rn’ is the register containing the address of the table of branch lengths. If Rn is PC, then the address of the table is the address of the byte immediately following the TBB or TBH instruction.
  • Page 147 PM0214 The STM32 Cortex-M4 instruction set BranchTable_H ((CaseA - BranchTable_H)/2) ; CaseA offset calculation ((CaseB - BranchTable_H)/2) ; CaseB offset calculation ((CaseC - BranchTable_H)/2) ; CaseC offset calculation CaseA ; an instruction sequence follows CaseB ; an instruction sequence follows CaseC ;...
  • Page 148: Floating-Point Instructions

    The STM32 Cortex-M4 instruction set PM0214 3.10 Floating-point instructions These instructions are only available if the FPU is included, and enabled, in the system. See Enabling the FPU on page 256 for information about enabling the floating-point unit. Table 34. Floating-point instructions Mnemonic Brief description VABS...
  • Page 149 PM0214 The STM32 Cortex-M4 instruction set Table 34. Floating-point instructions Mnemonic Brief description Move to ARM core register from floating-point VMRS VMRS on page 168 System Register Move to floating-point System Register from ARM VMSR VMSR on page 169 Core register VMUL Multiply floating-point VMUL on page 170...
  • Page 150: Vabs

    The STM32 Cortex-M4 instruction set PM0214 3.10.1 VABS Floating-point Absolute. Syntax VABS{cond}.F32 Sd, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd, Sm’ are the destination floating-point value and the operand floating-point value. Operation This instruction: Takes the absolute value of the operand floating-point register.
  • Page 151: Vadd

    PM0214 The STM32 Cortex-M4 instruction set 3.10.2 VADD Floating-point Add Syntax VADD{cond}.F32 {Sd,} Sn, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the destination floating-point value • ‘Sn, Sm’ are the operand floating-point values. Operation This instruction: Adds the values in the two floating-point operand registers.
  • Page 152: Vcmp, Vcmpe

    The STM32 Cortex-M4 instruction set PM0214 3.10.3 VCMP, VCMPE Compares two floating-point registers, or one floating-point register and zero. Syntax VCMP{E}{cond}.F32 Sd, Sm VCMP{E}{cond}.F32 Sd, #0.0 Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘E’...
  • Page 153: Vcvt, Vcvtr Between Floating-Point And Integer

    PM0214 The STM32 Cortex-M4 instruction set 3.10.4 VCVT, VCVTR between floating-point and integer Converts a value in a register from floating-point to a 32-bit integer. Syntax VCVT{R}{cond}.Tm.F32 Sd, Sm VCVT{cond}.F32.Tm Sd, Sm Where: • ‘R’ . If R is specified, the operation uses the rounding mode specified by the FPSCR. If R is omitted.
  • Page 154: Vcvt Between Floating-Point And Fixed-Point

    The STM32 Cortex-M4 instruction set PM0214 3.10.5 VCVT between floating-point and fixed-point Converts a value in a register from floating-point to and from fixed-point. Syntax VCVT{cond}.Td.F32 Sd, Sd, #fbits VCVT{cond}.F32.Td Sd, Sd, #fbits Where: • ‘cond’ is an optional condition code, see Conditional execution on page •...
  • Page 155: Vcvtb, Vcvtt

    PM0214 The STM32 Cortex-M4 instruction set 3.10.6 VCVTB, VCVTT Converts between a half-precision value and a single-precision value. Syntax VCVT{y}{cond}.F32.F16 Sd, Sm VCVT{y}{cond}.F16.F32 Sd, Sm Where: • ‘y’ Specifies which half of the operand register Sm or destination register Sd is used for the operand or destination: If y is B, then the bottom half, bits [15:0], of Sm or Sd is used.
  • Page 156: Vdiv

    The STM32 Cortex-M4 instruction set PM0214 3.10.7 VDIV Divides floating-point values. Syntax VDIV{cond}.F32 {Sd,} Sn, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the destination register • ‘Sn, Sm’ are the operand registers. Operation This instruction: Divides one floating-point value by another floating-point value.
  • Page 157: Vfma, Vfms

    PM0214 The STM32 Cortex-M4 instruction set 3.10.8 VFMA, VFMS Floating-point Fused Multiply Accumulate and Subtract. Syntax VFMA{cond}.F32 {Sd,} Sn, Sm VFMS{cond}.F32 {Sd,} Sn, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the destination register •...
  • Page 158: Vfnma, Vfnms

    The STM32 Cortex-M4 instruction set PM0214 3.10.9 VFNMA, VFNMS Floating-point Fused Negate Multiply Accumulate and Subtract. Syntax VFNMA{cond}.F32 {Sd,} Sn, Sm VFNMS{cond}.F32 {Sd,} Sn, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the destination register •...
  • Page 159: Vldm

    PM0214 The STM32 Cortex-M4 instruction set 3.10.10 VLDM Floating-point Load Multiple Syntax VLDM{mode}{cond}{.size} Rn{!}, list Where: • ‘mode’ is the addressing mode: IA: Increment After. The consecutive addresses start at the address specified in Rn. DB: Decrement Before. The consecutive addresses end just before the address specified in Rn.
  • Page 160: Vldr

    The STM32 Cortex-M4 instruction set PM0214 3.10.11 VLDR Loads a single extension register from memory Syntax VLDR{cond}{.64} Dd, [Rn{#imm}] VLDR{cond}{.64} Dd, label VLDR{cond}{.64} Dd, [PC, #imm}] VLDR{cond}{.32} Sd, [Rn {, #imm}] VLDR{cond}{.32} Sd, label VLDR{cond}{.32} Sd, [PC, #imm] Where: • ‘cond’...
  • Page 161: Vlma, Vlms

    PM0214 The STM32 Cortex-M4 instruction set 3.10.12 VLMA, VLMS Multiplies two floating-point values, and accumulates or subtracts the results. Syntax VLMA{cond}.F32 Sd, Sn, Sm VLMS{cond}.F32 Sd, Sn, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page •...
  • Page 162: Vmov Immediate

    The STM32 Cortex-M4 instruction set PM0214 3.10.13 VMOV immediate Move floating-point immediate Syntax VMOV{cond}.F32 Sd, #imm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the branch destination • ‘imm’ is a floating-point constant. Operation This instruction copies a constant value to a floating-point register.
  • Page 163: Vmov Register

    PM0214 The STM32 Cortex-M4 instruction set 3.10.14 VMOV register Copies the contents of one register to another. Syntax VMOV{cond}.F64 Dd, Dm VMOV{cond}.F32 Sd, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Dd’ is the destination register, for a doubleword operation. •...
  • Page 164: Vmov Scalar To Arm Core Register

    The STM32 Cortex-M4 instruction set PM0214 3.10.15 VMOV scalar to ARM core register Transfers one word of a doubleword floating-point register to an ARM core register. Syntax VMOV{cond} Rt, Dn[x] Where: • ‘cond’ is an optional condition code, see Conditional execution on page •...
  • Page 165: Vmov Arm Core Register To Single Precision

    PM0214 The STM32 Cortex-M4 instruction set 3.10.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: • ‘cond’ is an optional condition code, see Conditional execution on page •...
  • Page 166: Vmov Two Arm Core Registers To Two Single Precision

    The STM32 Cortex-M4 instruction set PM0214 3.10.17 VMOV two ARM core registers to two single precision Transfers two consecutively numbered single-precision registers to and from two ARM core registers. Syntax VMOV{cond} Sm, Sm1, Rt, Rt2 VMOV{cond} Rt, Rt2, Sm, Sm Where: •...
  • Page 167: Vmov Arm Core Register To Scalar

    PM0214 The STM32 Cortex-M4 instruction set 3.10.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: • ‘cond’ is an optional condition code, see Conditional execution on page •...
  • Page 168: Vmrs

    The STM32 Cortex-M4 instruction set PM0214 3.10.19 VMRS Move to ARM Core register from floating-point System Register. Syntax VMRS{cond} Rt, FPSCR VMRS{cond} APSR_nzcv, FPSCR Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Rt’ is the destination ARM core register. This register can be R0-R14. •...
  • Page 169: Vmsr

    PM0214 The STM32 Cortex-M4 instruction set 3.10.20 VMSR Move to floating-point System Register from ARM Core register. Syntax VMSR{cond} FPSCR, Rt Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Rt’ is the general-purpose register to be transferred to the FPSCR. Operation This instruction moves the value of a general-purpose register to the FPSCR.
  • Page 170: Vmul

    The STM32 Cortex-M4 instruction set PM0214 3.10.21 VMUL Floating-point Multiply. Syntax VMUL{cond}.F32 {Sd,} Sn, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the destination floating-point value • ‘Sn, Sm’ are the operand floating-point values. Operation This instruction: Multiplies two floating-point values.
  • Page 171: Vneg

    PM0214 The STM32 Cortex-M4 instruction set 3.10.22 VNEG Floating-point Negate. Syntax VNEG{cond}.F32 Sd, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the destination floating-point value • ‘Sm’ is the operand floating-point value. Operation This instruction: Negates a floating-point value.
  • Page 172: Vnmla, Vnmls, Vnmul

    The STM32 Cortex-M4 instruction set PM0214 3.10.23 VNMLA, VNMLS, VNMUL Floating-point multiply with negation followed by add or subtract. Syntax VNMLA{cond}.F32 Sd, Sn, Sm VNMLS{cond}.F32 Sd, Sn, Sm VNMUL{cond}.F32 {Sd,} Sn, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page •...
  • Page 173: Vpop

    PM0214 The STM32 Cortex-M4 instruction set 3.10.24 VPOP Floating-point extension register Pop. Syntax VPOP{cond}{.size} list Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘size’ is an optional data size specifier. If present, it must be equal to the size in bits, 32 or 64, of the registers in list.
  • Page 174: Vpush

    The STM32 Cortex-M4 instruction set PM0214 3.10.25 VPUSH Floating-point extension register Push. Syntax VPUSH{cond}{.size} list Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘size’ is an optional data size specifier. If present, it must be equal to the size in bits, 32 or 64, of the registers in list.
  • Page 175: Vsqrt

    PM0214 The STM32 Cortex-M4 instruction set 3.10.26 VSQRT Floating-point Square Root. Syntax VSQRT{cond}.F32 Sd, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the destination floating-point value • ‘Sm’ is the operand floating-point value. Operation This instruction: Calculates the square root of the value in a floating-point register.
  • Page 176: Vstm

    The STM32 Cortex-M4 instruction set PM0214 3.10.27 VSTM Floating-point Store Multiple. Syntax VSTM{mode}{cond}{.size} Rn{!}, list Where: • ‘mode’ is the addressing mode: IA Increment After. The consecutive addresses start at the address specified in Rn. This is the default and can be omitted. DB Decrement Before.
  • Page 177: Vstr

    PM0214 The STM32 Cortex-M4 instruction set 3.10.28 VSTR Floating-point Store. Syntax VSTR{cond}{.32} Sd, [Rn{, #imm}] VSTR{cond}{.64} Dd, [Rn{, #imm}] Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘32, 64’ are the optional data size specifiers. •...
  • Page 178: Vsub

    The STM32 Cortex-M4 instruction set PM0214 3.10.29 VSUB Floating-point Subtract. Syntax VSUB{cond}.F32 {Sd,} Sn, Sm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Sd’ is the destination floating-point value • ‘Sn, Sm’ are the operand floating-point values. Operation This instruction: Subtracts one floating-point value from another floating-point value.
  • Page 179: Miscellaneous Instructions

    PM0214 The STM32 Cortex-M4 instruction set 3.11 Miscellaneous instructions Table 35 shows the remaining Cortex-M4 instructions: Table 35. Miscellaneous instructions Mnemonic Brief description BKPT Breakpoint BKPT on page 180 CPSID Change Processor State, Disable Interrupts CPS on page 181 CPSIE Change Processor State, Enable Interrupts CPS on page 181 Data Memory Barrier...
  • Page 180: Bkpt

    The STM32 Cortex-M4 instruction set PM0214 3.11.1 BKPT Breakpoint. Syntax BKPT #imm Where: • ‘imm’ is an expression evaluating to an integer in the range 0-255 (8-bit value). 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.
  • Page 181: Cps

    PM0214 The STM32 Cortex-M4 instruction set 3.11.2 Change processor state. Syntax CPSeffect iflags Where: • ‘effect’ is one of: IE: Clears the special purpose register. ID: Sets the special purpose register. • ‘iflags’ is a sequence of one or more flags: i: Set or clear PRIMASK.
  • Page 182: Dmb

    The STM32 Cortex-M4 instruction set PM0214 3.11.3 Data memory barrier. Syntax DMB{cond} Where: ‘cond’ is an optional condition code, see Conditional execution on page 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 completed before any explicit memory accesses that appear, in program order, after the DMB instruction.
  • Page 183: Dsb

    PM0214 The STM32 Cortex-M4 instruction set 3.11.4 Data synchronization barrier. Syntax DSB{cond} Where: ‘cond’ is an optional condition code, see Conditional execution on page 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.
  • Page 184: Isb

    The STM32 Cortex-M4 instruction set PM0214 3.11.5 Instruction synchronization barrier. Syntax ISB{cond} Where: ‘cond’ is an optional condition code, see Conditional execution on page 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 is completed.
  • Page 185: Mrs

    PM0214 The STM32 Cortex-M4 instruction set 3.11.6 Move the contents of a special register to a general-purpose register. Syntax MRS{cond} Rd, spec_reg Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Rd’ is the destination register. •...
  • Page 186: Msr

    The STM32 Cortex-M4 instruction set PM0214 3.11.7 Move the contents of a general-purpose register into the specified special register. Syntax MSR{cond} spec_reg, Rn Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘Rn’ is the source register. •...
  • Page 187: Nop

    PM0214 The STM32 Cortex-M4 instruction set 3.11.8 No Operation. Syntax NOP{cond} Where: • ‘cond’ is an optional condition code, see Conditional execution on page Operation NOP does nothing. NOP is not necessarily a time-consuming NOP. The processor might remove it from the pipeline before it reaches the execution stage. Use NOP for padding, for example to place the following instruction on a 64-bit boundary.
  • Page 188: Sev

    The STM32 Cortex-M4 instruction set PM0214 3.11.9 Send Event. Syntax SEV{cond} Where: • ‘cond’ is an optional condition code, see Conditional execution on page Operation SEV is a hint instruction that causes an event to be signaled to all processors within a multiprocessor system.
  • Page 189: Svc

    PM0214 The STM32 Cortex-M4 instruction set 3.11.10 Supervisor Call. Syntax SVC{cond} #imm Where: • ‘cond’ is an optional condition code, see Conditional execution on page • ‘imm’ is an expression evaluating to an integer in the range 0-255 (8-bit value). Operation The SVC instruction causes the SVC exception.
  • Page 190: Wfe

    The STM32 Cortex-M4 instruction set PM0214 3.11.11 Wait For Event. WFE is a hint instruction. Syntax WFE{cond} Where: ‘cond’ is an optional condition code, see Conditional execution on page Operation If the event register is 0, WFE suspends execution until one of the following events occurs: •...
  • Page 191: Wfi

    PM0214 The STM32 Cortex-M4 instruction set 3.11.12 Wait for Interrupt. Syntax WFI{cond} Where: • ‘cond’ is an optional condition code, see Conditional execution on page Operation WFI is a hint instruction that suspends execution until one of the following events occurs: •...
  • Page 192: Core Peripherals

    Core peripherals PM0214 Core peripherals About the STM32 Cortex-M4 core peripherals The address map of the Private peripheral bus (PPB) is: Table 36. STM32 core peripheral register regions Address Core peripheral Description 0xE000E010-0xE000E01F System timer Table 54 on page 250 Nested vectored interrupt 0xE000E100-0xE000E4EF Table 48 on page 218...
  • Page 193: Table 37. Memory Attributes Summary

    PM0214 Core peripherals When memory regions overlap, a memory access is affected by the attributes of the region with the highest number. For example, the attributes for region 7 take precedence over the attributes of any region that overlaps region 7. The background region has the same memory access attributes as the default memory map, but is accessible from privileged software only.
  • Page 194: Mpu Access Permission Attributes

    Core peripherals PM0214 4.2.1 MPU access permission attributes This section describes the MPU access permission attributes. The access permission bits, TEX, C, B, S, AP, and XN, of the MPU_RASR register, control access to the corresponding memory region. If an access is made to an area of memory without the required permissions, then the MPU generates a permission fault.
  • Page 195: Mpu Mismatch

    PM0214 Core peripherals Table 40 shows the AP encodings that define the access permissions for privileged and unprivileged software. Table 40. AP encoding Privileged Unprivileged AP[2:0] Description permissions permissions No access No access All accesses generate a permission fault No access Access from privileged software only Writes by unprivileged software generate a permission fault...
  • Page 196 Core peripherals PM0214 ; R3 = attributes ; R4 = address LDR R0,=MPU_RNR ; 0xE000ED98, MPU region number register STR R1, [R0, #0x0] ; Region Number BIC R2, R2, #1 ; Disable STRH R2, [R0, #0x8] ; Region Size and Enable STR R4, [R0, #0x4] ;...
  • Page 197: Figure 18. Subregion Example

    PM0214 Core peripherals ; R1 = address and region number in one ; R2 = size and attributes in one LDR R0, =MPU_RBAR ; 0xE000ED9C, MPU Region Base register STR R1, [R0, #0x0] ; Region base address and ; region number combined with VALID (bit 4) set to 1 STR R2, [R0, #0x4] ;...
  • Page 198: Mpu Design Hints And Tips

    Core peripherals PM0214 4.2.4 MPU design hints and tips To avoid unexpected behavior, disable the interrupts before updating the attributes of a region that the interrupt handlers might access. Ensure software uses aligned accesses of the correct size to access MPU registers: •...
  • Page 199: Mpu Type Register (Mpu_Typer)

    PM0214 Core peripherals 4.2.5 MPU type register (MPU_TYPER) Address offset: 0x00 Reset value: 0x0000 0800 Required privilege: Privileged The MPU_TYPER register indicates whether the MPU is present, and if so, how many regions it supports. Reserved IREGION[7:0] SEPA DREGION[7:0] Reserved RATE Bits 31:24 Reserved.
  • Page 200: Mpu Control Register (Mpu_Ctrl)

    Core peripherals PM0214 4.2.6 MPU control register (MPU_CTRL) Address offset: 0x04 Reset value: 0x0000 0000 Required privilege: Privileged The MPU_CTRL register: • Enables the MPU • Enables the default memory map background region • Enables use of the MPU when in the hard fault, Non-maskable Interrupt (NMI), and FAULTMASK escalated handlers.
  • Page 201: Mpu Region Number Register (Mpu_Rnr)

    PM0214 Core peripherals Bits 31:3 Reserved, forced by hardware to 0. Bit 2 PRIVDEFENA: Enable priviliged software access to default memory map. 0: If the MPU is enabled, disables use of the default memory map. Any memory access to a location not covered by any enabled region causes a fault.
  • Page 202: Mpu Region Base Address Register (Mpu_Rbar)

    Core peripherals PM0214 4.2.8 MPU region base address register (MPU_RBAR) Address offset: 0x0C Reset value: 0x0000 0000 Required privilege: Privileged The MPU_RBAR register defines the base address of the MPU region selected by the MPU_RNR register, and can update the value of the MPU_RNR register. Write to the MPU_RBAR register with the VALID bit set to 1 to change the current region number and update the MPU_RNR register.
  • Page 203: Mpu Region Attribute And Size Register (Mpu_Rasr)

    PM0214 Core peripherals 4.2.9 MPU region attribute and size register (MPU_RASR) Address offset: 0x10 Reset value: 0x0000 0000 Required privilege: Privileged The MPU_RASR register defines the region size and memory attributes of the MPU region specified by the MPU_RNR, and enables that region and any subregions. MPU_RASR is accessible using word or halfword accesses: •...
  • Page 204: Table 42. Example Size Field Values

    Core peripherals PM0214 Bits 15:8 SRD: Subregion disable bits. For each bit in this field: 0: corresponding sub-region is enabled 1: corresponding sub-region is disabled Subregions on page 197 for more information. Region sizes of 128 bytes and less do not support subregions. When writing the attributes for such a region, write the SRD field as 0x00.
  • Page 205: Mpu Register Map

    PM0214 Core peripherals 4.2.10 MPU register map Table 43. MPU register map and reset values Offset Register MPU_TYPER Reserved IREGION[7:0] DREGION[7:0] Reserved 0x00 Reset Value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 MPU_CTRL Reserved 0x04...
  • Page 206 Core peripherals PM0214 Table 43. MPU register map and reset values (continued) Offset Register MPU_RBAR_A3 ADDR[31:N]... 0x1C Reset Value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 MPU_RASR_A3 AP[2:0] S C B...
  • Page 207: Nested Vectored Interrupt Controller (Nvic)

    PM0214 Core peripherals Nested vectored interrupt controller (NVIC) This section describes the Nested Vectored Interrupt Controller (NVIC) and the registers it uses. The NVIC supports: • Up to 81 interrupts (interrupt number depends on the STM32 device type; refer to the datasheets) •...
  • Page 208: Accessing The Cortex-M4 Nvic Registers Using Cmsis

    Core peripherals PM0214 4.3.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 45. CMSIS access NVIC functions CMSIS function Description void NVIC_EnableIRQ(IRQn_Type IRQn) Enables an interrupt or exception.
  • Page 209: Interrupt Set-Enable Registers (Nvic_Iserx)

    PM0214 Core peripherals 4.3.2 Interrupt set-enable registers (NVIC_ISERx) Address offset: 0x00 - 0x0B Reset value: 0x0000 0000 Required privilege: Privileged SETENA[31:16] SETENA[15:0] Bits 31:0 SETENA: Interrupt set-enable bits. Write: 0: No effect 1: Enable interrupt Read: 0: Interrupt disabled 1: Interrupt enabled. If a pending interrupt is enabled, the NVIC activates the interrupt based on its priority.
  • Page 210: Interrupt Clear-Enable Registers (Nvic_Icerx)

    Core peripherals PM0214 4.3.3 Interrupt clear-enable registers (NVIC_ICERx) Address offset: 0x00 - 0x0B Reset value: 0x0000 0000 Required privilege: Privileged The ICER0-ICER2 registers disable interrupts, and show which interrupts are enabled. CLRENA[31:16] rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1...
  • Page 211: Interrupt Set-Pending Registers (Nvic_Isprx)

    PM0214 Core peripherals 4.3.4 Interrupt set-pending registers (NVIC_ISPRx) Address offset: 0x00 - 0x0B Reset value: 0x0000 0000 Required privilege: Privileged The ISPR0-ISPR2 registers force interrupts into the pending state, and show which interrupts are pending. SETPEND[31:16] SETPEND[15:0] Bits 31:0 SETPEND: Interrupt set-pending bits Write: 0: No effect 1: Changes interrupt state to pending...
  • Page 212: Interrupt Clear-Pending Registers (Nvic_Icprx)

    Core peripherals PM0214 4.3.5 Interrupt clear-pending registers (NVIC_ICPRx) Address offset: 0x00 - 0x0B Reset value: 0x0000 0000 Required privilege: Privileged The ICPR0-ICPR2 registers remove the pending state from interrupts, and show which interrupts are pending. CLRPEND[31:16] rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1 rc_w1...
  • Page 213: Interrupt Active Bit Registers (Nvic_Iabrx)

    PM0214 Core peripherals 4.3.6 Interrupt active bit registers (NVIC_IABRx) Address offset: 0x00- 0x0B Reset value: 0x0000 0000 Required privilege: Privileged The IABR0-IABR2 registers indicate which interrupts are active. The bit assignments are: ACTIVE[31:16] ACTIVE[15:0] Bits 31:0 ACTIVE: Interrupt active flags 0: Interrupt not active 1: Interrupt active A bit reads as 1 if the status of the corresponding interrupt is active or active and pending.
  • Page 214: Interrupt Priority Registers (Nvic_Iprx)

    Core peripherals PM0214 4.3.7 Interrupt priority registers (NVIC_IPRx) Address offset: 0x00- 0x0B Reset value: 0x0000 0000 Required privilege: Privileged The NVIC_IPR0-IPR80 registers provide an 8-bit priority field for each interrupt. These registers are byte-accessible. Each register holds four priority fields, that map to four elements in the CMSIS interrupt priority array IP[0] to IP[67], as shown in Figure Figure 19.
  • Page 215: Software Trigger Interrupt Register (Nvic_Stir)

    PM0214 Core peripherals 4.3.8 Software trigger interrupt register (NVIC_STIR) Address offset: 0xE00 Reset value: 0x0000 0000 Required privilege: When the USERSETMPEND bit in the SCR is set to 1, unprivileged software can access the STIR, see Section 4.4.6: System control register (SCR).
  • Page 216: Level-Sensitive And Pulse Interrupts

    Core peripherals PM0214 4.3.9 Level-sensitive and pulse interrupts STM32 interrupts are both level-sensitive and pulse-sensitive. 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 217: Nvic Design Hints And Tips

    PM0214 Core peripherals 4.3.10 NVIC design hints and tips Ensure software uses correctly aligned register accesses. The processor does not support unaligned accesses to NVIC registers. See the individual register descriptions for the supported access sizes. An interrupt can enter pending state even it is disabled. Disabling an interrupt only prevents the processor from taking that interrupt.
  • Page 218: Nvic Register Map

    Core peripherals PM0214 4.3.11 NVIC register map This table shows the NVIC register map and reset values. The base address of the main NVIC register block is 0xE000E100. The NVIC_STIR register is located in a separate block at 0xE000EF00. Table 48. NVIC register map and reset values Offset Register NVIC_ISER0...
  • Page 219 PM0214 Core peripherals Table 48. NVIC register map and reset values (continued) Offset Register NVIC_IPR0 IP[3] IP[2] IP[1] IP[0] 0x300 Reset Value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 NVIC_IPR25 Reserved IP[101]...
  • Page 220: System Control Block (Scb)

    Core peripherals PM0214 System control block (SCB) The System control block (SCB) provides system implementation information, and system control. This includes configuration, control, and reporting of the system exceptions. Table 49. Summary of the system control block registers Required Address Name Type Reset value...
  • Page 221: Auxiliary Control Register (Actlr)

    PM0214 Core peripherals 4.4.1 Auxiliary control register (ACTLR) Address offset: 0x00 (base adress = 0xE000 E008) Reset value: 0x0000 0000 Required privilege: Privileged By default this register is set to provide optimum performance from the Cortex-M4 processor, and does not normally require modification. The ACTLR register provides disable bits for the following processor functions: •...
  • Page 222 Core peripherals PM0214 DISFOLD Bit 2 Disables folding of IT instructions: 0: Enables IT instructions folding. 1: Disables IT instructions folding. In some situations, the processor can start executing the first instruction in an IT block while it is still executing the IT instruction. This behavior is called IT folding, and improves performance, However, IT folding can cause jitter in looping.
  • Page 223: Cpuid Base Register (Cpuid)

    PM0214 Core peripherals 4.4.2 CPUID base register (CPUID) Address offset: 0x00 Reset value: 0x410F C241 Required privilege: Privileged The CPUID register contains the processor part number, version, and implementation information. Implementer Variant Constant PartNo Revision Bits 31:24 Implementer: Implementer code 0x41: ARM Bits 23:20 Variant: Variant number The r value in the rnpn product revision identifier...
  • Page 224: Interrupt Control And State Register (Icsr)

    Core peripherals PM0214 4.4.3 Interrupt control and state register (ICSR) Address offset: 0x04 Reset value: 0x0000 0000 Required privilege: Privileged The ICSR: • Provides: – A set-pending bit for the Non-Maskable Interrupt (NMI) exception – Set-pending and clear-pending bits for the PendSV and SysTick exceptions •...
  • Page 225 PM0214 Core peripherals Bit 28 PENDSVSET: PendSV set-pending bit. Write: 0: No effect 1: Change PendSV exception state to pending. Read: 0: PendSV exception is not pending 1: PendSV exception is pending Writing 1 to this bit is the only way to set the PendSV exception state to pending. Bit 27 PENDSVCLR: PendSV clear-pending bit.
  • Page 226: Vector Table Offset Register (Vtor)

    Core peripherals PM0214 4.4.4 Vector table offset register (VTOR) Address offset: 0x08 Reset value: 0x0000 0000 Required privilege: Privileged TBLOFF[29:16] Reserved TBLOFF[15:9] Reserved Bits 31:30 Reserved, must be kept cleared Bits 29:9 TBLOFF: Vector table base offset field. It contains bits [29:9] of the offset of the table base from memory address 0x00000000. When setting TBLOFF, you must align the offset to the number of exception entries in the vector table.
  • Page 227: Application Interrupt And Reset Control Register (Aircr)

    PM0214 Core peripherals 4.4.5 Application interrupt and reset control register (AIRCR) Address offset: 0x0C Reset value: 0xFA05 0000 Required privilege: Privileged The AIRCR provides priority grouping control for the exception model, endian status for data accesses, and reset control of the system. To write to this register, you must write 0x5FA to the VECTKEY field, otherwise the processor ignores the write.
  • Page 228: Table 50. Priority Grouping

    Core peripherals PM0214 bits you might require more explanation here, and want to remove invalid rows from the table, and modify the entries in the number of columns. Table 50. Priority grouping Interrupt priority level value, PRI_N[7:4] Number of PRIGROUP Binary Group priority Subpriority...
  • Page 229: System Control Register (Scr)

    PM0214 Core peripherals 4.4.6 System control register (SCR) Address offset: 0x10 Reset value: 0x0000 0000 Required privilege: Privileged The SCR controls features of entry to and exit from low power state. Reserved SLEEP SEVON SLEEP PEND DEEP Reserved Res. Res. EXIT Bits 31:5 Reserved, must be kept cleared Bit 4 SEVEONPEND Send Event on Pending bit...
  • Page 230: Configuration And Control Register (Ccr)

    Core peripherals PM0214 4.4.7 Configuration and control register (CCR) Address offset: 0x14 Reset value: 0x0000 0200 Required privilege: Privileged The CCR controls entry to Thread mode and enables: • The handlers for NMI, hard fault and faults escalated by FAULTMASK to ignore bus faults •...
  • Page 231 PM0214 Core peripherals UNALIGN_ TRP Bit 3 Enables unaligned access traps: 0: Do not trap unaligned halfword and word accesses 1: Trap unaligned halfword and word accesses. If this bit is set to 1, an unaligned access generates a usage fault. Unaligned LDM, STM, LDRD, and STRD instructions always fault irrespective of whether UNALIGN_TRP is set to 1.
  • Page 232: System Handler Priority Registers (Shprx)

    Core peripherals PM0214 4.4.8 System handler priority registers (SHPRx) The SHPR1-SHPR3 registers set the priority level, 0 to 255 of the exception handlers that have configurable priority. SHPR1-SHPR3 are byte accessible. The system fault handlers and the priority field and register for each handler are: Table 51.
  • Page 233 PM0214 Core peripherals PRI_11[7:4] PRI_11[3:0] Reserved Reserved Bits 31:24 PRI_11: Priority of system handler 11, SVCall Bits 23:0 Reserved, must be kept cleared System handler priority register 3 (SHPR3) Address: 0xE000 ED20 Reset value: 0x0000 0000 Required privilege: Privileged PRI_15[7:4] PRI_15[3:0] PRI_14[7:4] PRI_14[3:0]...
  • Page 234: System Handler Control And State Register (Shcsr)

    Core peripherals PM0214 4.4.9 System handler control and state register (SHCSR) Address offset: 0x24 Reset value: 0x0000 0000 Required privilege: Privileged The SHCSR enables the system handlers, and indicates: • The pending status of the bus fault, memory management fault, and SVC exceptions •...
  • Page 235 PM0214 Core peripherals Bit 8 MONITORACT: Debug monitor active bit, reads as 1 if Debug monitor is active Bit 7 SVCALLACT: SVC call active bit, reads as 1 if SVC call is active Bits 6:4 Reserved, must be kept cleared Bit 3 USGFAULTACT: Usage fault exception active bit, reads as 1 if exception is active Reserved, must be kept cleared Bit 2...
  • Page 236: Configurable Fault Status Register (Cfsr; Ufsr+Bfsr+Mmfsr)

    Core peripherals PM0214 4.4.10 Configurable fault status register (CFSR; UFSR+BFSR+MMFSR) Address offset: 0x28 Reset value: 0x0000 0000 Required privilege: Privileged The following subsections describe the subregisters that make up the CFSR: • Usage fault status register (UFSR) on page 237 •...
  • Page 237: Usage Fault Status Register (Ufsr)

    PM0214 Core peripherals 4.4.11 Usage fault status register (UFSR) Bits 31:26 Reserved, must be kept cleared Bit 25 DIVBYZERO: Divide by zero usage fault. When the processor sets this bit to 1, the PC value stacked for the exception return points to the instruction that performed the divide by zero. Enable trapping of divide by zero by setting the DIV_0_TRP bit in the CCR to 1, see Configuration and control register (CCR) on page 230.
  • Page 238: Bus Fault Status Register (Bfsr)

    Core peripherals PM0214 4.4.12 Bus fault status register (BFSR) Bit 15 BFARVALID: Bus Fault Address Register (BFAR) valid flag. The processor sets this bit to 1 after a bus fault where the address is known. Other faults can set this bit to 0, such as a memory management fault occurring later.
  • Page 239: Memory Management Fault Address Register (Mmfsr)

    PM0214 Core peripherals 4.4.13 Memory management fault address register (MMFSR) Bit 7 MMARVALID: Memory Management Fault Address Register (MMAR) valid flag. If a memory management fault occurs and is escalated to a hard fault because of priority, the hard fault handler must set this bit to 0.
  • Page 240: Hard Fault Status Register (Hfsr)

    Core peripherals PM0214 4.4.14 Hard fault status register (HFSR) Address offset: 0x2C Reset value: 0x0000 0000 Required privilege: Privileged The HFSR gives information about events that activate the hard fault handler. This register is read, write to clear. This means that bits in the register read normally, but writing 1 to any bit clears that bit to 0.
  • Page 241: Memory Management Fault Address Register (Mmfar)

    PM0214 Core peripherals 4.4.15 Memory management fault address register (MMFAR) Address offset: 0x34 Reset value: undefined Required privilege: Privileged MMFAR[31:16] MMFAR[15:0] Bits 31:0 MMFAR: Memory management fault address When the MMARVALID bit of the MMFSR is set to 1, this field holds the address of the location that generated the memory management fault.
  • Page 242: Auxiliary Fault Status Register (Afsr)

    Core peripherals PM0214 4.4.17 Auxiliary fault status register (AFSR) Address offset: 0x3C Reset value: undefined Required privilege: Privileged IMPDEF[31:16] IMPDEF[15:0] Bits 31:0 IMPDEF: Implementation defined. The AFSR contains additional system fault information. The bits map to the AUXFAULT input signals. This register is read, write to clear.
  • Page 243: Scb Register Map

    PM0214 Core peripherals 4.4.19 SCB register map The table provides shows the System control block register map and reset values. The base address of the SCB register block is 0xE000 ED00 for register described in Table Table 52. SCB register map and reset values Offset Register CPUID...
  • Page 244 Core peripherals PM0214 Table 52. SCB register map and reset values (continued) Offset Register SHPR3 PRI15 PRI14 0x20 Reserved Reset Value 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 SHCRS 0x24 Reserved Reset Value 0 0 0 0 0 0 0 0 0 CFSR...
  • Page 245: Systick Timer (Stk)

    PM0214 Core peripherals SysTick timer (STK) The processor has a 24-bit system timer, SysTick, that counts down from the reload value to zero, reloads (wraps to) the value in the STK_LOAD register on the next clock edge, then counts down on subsequent clocks. When the processor is halted for debugging the counter does not decrement.
  • Page 246: Systick Control And Status Register (Stk_Ctrl)

    Core peripherals PM0214 4.5.1 SysTick control and status register (STK_CTRL) Address offset: 0x00 Reset value: 0x0000 0000 Required privilege: Privileged The SysTick CTRL register enables the SysTick features. COUNT FLAG Reserved CLKSO TICK URCE ABLE Reserved Bits 31:17 Reserved, must be kept cleared. Bit 16 COUNTFLAG: Returns 1 if timer counted to 0 since last time this was read.
  • Page 247: Systick Reload Value Register (Stk_Load)

    PM0214 Core peripherals 4.5.2 SysTick reload value register (STK_LOAD) Address offset: 0x04 Reset value: 0x0000 0000 Required privilege: Privileged RELOAD[23:16] Reserved RELOAD[15:0] Bits 31:24 Reserved, must be kept cleared. Bits 23:0 RELOAD: RELOAD value The LOAD register specifies the start value to load into the STK_VAL register when the counter is enabled and when it reaches 0.
  • Page 248: Systick Current Value Register (Stk_Val)

    Core peripherals PM0214 4.5.3 SysTick current value register (STK_VAL) Address offset: 0x08 Reset value: 0x0000 0000 Required privilege: Privileged CURRENT[23:16] Reserved CURRENT[15:0] Bits 31:24 Reserved, must be kept cleared. Bits 23:0 CURRENT: Current counter value The VAL register contains the current value of the SysTick counter. Reads return the current value of the SysTick counter.
  • Page 249: Systick Calibration Value Register (Stk_Calib)

    PM0214 Core peripherals 4.5.4 SysTick calibration value register (STK_CALIB) Address offset: 0x0C Reset value: 0x0000000 Required privilege: Privileged The CALIB register indicates the SysTick calibration properties. SKEW TENMS[23:16] Reserved TENMS[15:0] Bit 31 NOREF: NOREF flag. Reads as zero. Indicates that a separate reference clock is provided. The frequency of this clock is HCLK/8.
  • Page 250: Systick Register Map

    Core peripherals PM0214 4.5.6 SysTick register map The table provided shows the SysTick register map and reset values. The base address of the SysTick register block is 0xE000 E010. Table 54. SysTick register map and reset values Offset Register STK_CTRL 0x00 Reserved Reserved...
  • Page 251: Floating Point Unit (Fpu)

    The following sections describe the floating-point system registers whose implementation is specific to this processor. Note: For more details on the IEEE standard and floating-point arithmetic (IEEE 754), refer to the AN4044 Application note. Available from website www.st.com. DocID022708 Rev 6 251/260...
  • Page 252: Coprocessor Access Control Register (Cpacr)

    Core peripherals PM0214 4.6.1 Coprocessor access control register (CPACR) Address offset (from SCB): 0x88 Reset value: 0x0000000 Required privilege: Privileged The CPACR register specifies the access privileges for coprocessors. CP11 CP10 Reserved Reserved Reserved Bits 31:24 Reserved. Read as Zero, Write Ignore. Bits 23:20 CPn: [2n+1:2n] for n values 10 and 11.
  • Page 253 PM0214 Core peripherals Bit 31 ASPEN: Enables CONTROL<2> setting on execution of a floating-point instruction. This results in automatic hardware state preservation and restoration, for floating-point context, on exception entry and exit. 0: Disable CONTROL<2> setting on execution of a floating-point instruction. 1: Enable CONTROL<2>...
  • Page 254: Floating-Point Context Address Register (Fpcar)

    Core peripherals PM0214 4.6.3 Floating-point context address register (FPCAR) Address offset: 0x08 Reset value: 0x0000000 Required privilege: Privileged The FPCAR register holds the location of the unpopulated floating-point register space allocated on an exception stack frame. ADDRESS[31:16] ADDRESS[15:3] Reserved Bits 31:3 ADDRESS: Location of unpopulated floating-point register space allocated on an exception stack frame.
  • Page 255: Table 56. Effect Of A Floating-Point Comparison On The Condition Flags

    PM0214 Core peripherals Bit 28 V: Overflow condition code flag. Floating-point comparison operations update this flag. For more details on the result, refer to Table 0: Operation did not result in an overflow 1: Operation resulted in an overflow. Bit 27 Reserved. Bit 26 AHP: Alternative half-precision control bit: 0: IEEE half-precision format selected.
  • Page 256: Floating-Point Default Status Control Register (Fpdscr)

    Core peripherals PM0214 4.6.5 Floating-point default status control register (FPDSCR) Address offset: 0x0C Reset value: 0x0000000 Required privilege: Privileged The FPDSCR register holds the default values for the floating-point status control data. RMode Reserved Reserved Reserved Bits 31:27 Reserved, must be kept cleared. Bit 26 AHP: Default value for FPSCR.AHP Bit 25 DN: Default value for FPSCR.DN Bit 24 FZ: Default value for FPSCR.FZ...
  • Page 257: Enabling And Clearing Fpu Exception Interrupts

    PM0214 Core peripherals 4.6.7 Enabling and clearing FPU exception interrupts The FPU exception flags are generating an interrupt through the interrupt controller. The FPU interrupt is globally controlled through the interrupt controller. A mask bit is also provided in the System Configuration Controller (SYSCFG), allowing to enable/disable individually each FPU flag interrupt generation.
  • Page 258 Core peripherals PM0214 sp = sp + 0x60; else if(lr == 0xFFFFFFED) sp = __get_PSP() + 0x60 ; fpscr_val = *(uint32_t*)sp; { check exception flags } fpscr_val &= (uint32_t)~0x8F ; // Clear all exception flags *(uint32_t*)sp = fpscr_val; __DMB() ; // FPU IRQ Handler void __asm FPU_IRQHandler(void) IMPORT...
  • Page 259: Revision History

    PM0214 Revision history Revision history Table 57. Document revision history Date Revision Changes 20-Feb-2012 Initial release. Changed reset value in Section 4.6.2: Floating-point context control register (FPCCR). 09-Jul-2012 Added Table 1: Applicable products. Added information on the STM32F3xxx Cortex-M4 processor. Added extra part numbers to Table 1: Applicable products.
  • Page 260 ST products and/or to this document at any time without notice. Purchasers should obtain the latest relevant information on ST products before placing orders. ST products are sold pursuant to ST’s terms and conditions of sale in place at the time of order acknowledgement.

This manual is also suitable for:

Stm32l4+ seriesStm32f3 series

Table of Contents

Save PDF