PM0214 Programming Manual - STMicroelectronics

Transcription

PM0214Programming manualSTM32 Cortex -M4 MCUs and MPUs programming manualIntroductionThis programming manual provides information for application and system-level softwaredevelopers. It gives a full description of the STM32 Cortex -M4 processor programmingmodel, instruction set and core peripherals. The applicable products are listed in the tablebelow.The Cortex -M4 processor used in STM32F3 Series, STM32F4 Series, STM32G4 Series,STM32H745/755 and STM32H747/757 Lines, STM32L4 Series, STM32L4 Series,STM32WB Series, STM32WL Series and STM32MP1 Series, is a high performance 32-bitprocessor designed for the microcontroller and microprocessor market. It offers significantbenefits 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 securityTable 1. Applicable productsTypeProduct Series and LinesMicrocontrollersSTM32F3 Series, STM32F4 Series, STM32G4 Series, STM32L4 Series,STM32L4 Series, STM32WB Series, STM32WL SeriesSTM32H745/755 and STM32H747/757 LinesMicroprocessorsSTM32MP1 SeriesReference documentsAvailable from STMicroelectronics web site www.st.com: Datasheets of STM32F3 Series, STM32F4 Series, STM32G4 Series, STM32H745/755and STM32H747/757 Lines, STM32L4 Series, STM32L4 Series, STM32MP1 Series,STM32WB Series and STM32WL Series Reference manuals of STM32F3 Series, STM32F4 Series, STM32G4 Series,STM32H745/755 and STM32H747/757 Lines, STM32L4 Series, STM32L4 Series,STM32MP1 Series, STM32WB Series and STM32WL SeriesMarch 2020PM0214 Rev 101/262www.st.com1

ContentsPM0214Contents12About this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.1Typographical conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.2List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121.3About the STM32 Cortex-M4 processor and core peripherals . . . . . . . . . 13System level interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.3.2Integrated configurable debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141.3.3Cortex-M4 processor features and benefits summary . . . . . . . . . . . . . . 151.3.4Cortex-M4 core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16The Cortex-M4 processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.12.22.32/2621.3.1Programmers model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.1.1Processor mode and privilege levels for software execution . . . . . . . . . 172.1.2Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.1.3Core registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182.1.4Exceptions and interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262.1.5Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262.1.6The Cortex microcontroller software interface standard (CMSIS) . . . . . 26Memory model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 282.2.1Memory regions, types and attributes . . . . . . . . . . . . . . . . . . . . . . . . . . 292.2.2Memory system ordering of memory accesses . . . . . . . . . . . . . . . . . . . 292.2.3Behavior of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 302.2.4Software ordering of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . 312.2.5Bit-banding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 322.2.6Memory endianness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342.2.7Synchronization primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 342.2.8Programming hints for the synchronization primitives . . . . . . . . . . . . . . 36Exception model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.3.1Exception states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.3.2Exception types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 372.3.3Exception handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392.3.4Vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402.3.5Exception priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.3.6Interrupt priority grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 412.3.7Exception entry and return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42PM0214 Rev 10

PM0214Contents2.42.53Fault handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442.4.1Fault types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452.4.2Fault escalation and hard faults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462.4.3Fault status registers and fault address registers . . . . . . . . . . . . . . . . . 472.4.4Lockup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472.5.1Entering sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482.5.2Wakeup from sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 482.5.3External event input / extended interrupt and event input . . . . . . . . . . . 492.5.4Power management programming hints . . . . . . . . . . . . . . . . . . . . . . . . 49The STM32 Cortex-M4 instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . 503.1Instruction set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 503.2CMSIS intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 583.3About the instruction descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603.43.53.3.1Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603.3.2Restrictions when using PC or SP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603.3.3Flexible second operand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 603.3.4Shift operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 623.3.5Address alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653.3.6PC-relative expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653.3.7Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 653.3.8Instruction width selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68Memory access instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693.4.1ADR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703.4.2LDR and STR, immediate offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 713.4.3LDR and STR, register offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733.4.4LDR and STR, unprivileged . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743.4.5LDR, PC-relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753.4.6LDM and STM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 763.4.7PUSH and POP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783.4.8LDREX and STREX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 793.4.9CLREX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80General data processing instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 813.5.1ADD, ADC, SUB, SBC, and RSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 833.5.2AND, ORR, EOR, BIC, and ORN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85PM0214 Rev 103/2628

ContentsPM02143.63.73.5.3ASR, LSL, LSR, ROR, and RRX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 863.5.4CLZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873.5.5CMP and CMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883.5.6MOV and MVN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 893.5.7MOVT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913.5.8REV, REV16, REVSH, and RBIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923.5.9SADD16 and SADD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933.5.10SHADD16 and SHADD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943.5.11SHASX and SHSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953.5.12SHSUB16 and SHSUB8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963.5.13SSUB16 and SSUB8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973.5.14SASX and SSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983.5.15TST and TEQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993.5.16UADD16 and UADD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1003.5.17UASX and USAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1013.5.18UHADD16 and UHADD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023.5.19UHASX and UHSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033.5.20UHSUB16 and UHSUB8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043.5.21SEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053.5.22USAD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063.5.23USADA8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1073.5.24USUB16 and USUB8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108Multiply and divide instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1093.6.1MUL, MLA, and MLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1103.6.2UMULL, UMAAL and UMLAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1113.6.3SMLA and SMLAW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1123.6.4SMLAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1143.6.5SMLAL and SMLALD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1153.6.6SMLSD and SMLSLD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1173.6.7SMMLA and SMMLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1193.6.8SMMUL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1203.6.9SMUAD and SMUSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1213.6.10SMUL and SMULW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1223.6.11UMULL, UMLAL, SMULL, and SMLAL . . . . . . . . . . . . . . . . . . . . . . . . 1233.6.12SDIV and UDIV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124Saturating instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1253.7.14/262SSAT and USAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126PM0214 Rev 10

PM0214Contents3.83.93.103.7.2SSAT16 and USAT16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1273.7.3QADD and QSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1283.7.4QASX and QSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1293.7.5QDADD and QDSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1303.7.6UQASX and UQSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1313.7.7UQADD and UQSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132Packing and unpacking instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1343.8.1PKHBT and PKHTB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1353.8.2SXT and UXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1363.8.3SXTA and UXTA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137Bitfield instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1383.9.1BFC and BFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1393.9.2SBFX and UBFX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1403.9.3SXT and UXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1413.9.4Branch and control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1423.9.5B, BL, BX, and BLX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1423.9.6CBZ and CBNZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1443.9.7IT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1453.9.8TBB and TBH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147Floating-point instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1493.10.1VABS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1513.10.2VADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1523.10.3VCMP, VCMPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1533.10.4VCVT, VCVTR between floating-point and integer . . . . . . . . . . . . . . . 1543.10.5VCVT between floating-point and fixed-point . . . . . . . . . . . . . . . . . . . 1553.10.6VCVTB, VCVTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1563.10.7VDIV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1573.10.8VFMA, VFMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1583.10.9VFNMA, VFNMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1593.10.10 VLDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1603.10.11 VLDR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1613.10.12 VLMA, VLMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1623.10.13 VMOV immediate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1633.10.14 VMOV register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1643.10.15 VMOV scalar to Arm core register . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1653.10.16 VMOV Arm core register to single precision . . . . . . . . . . . . . . . . . . . . 1663.10.17 VMOV two Arm core registers to two single precision . . . . . . . . . . . . . 167PM0214 Rev 105/2628

ContentsPM02143.10.18 VMOV Arm Core register to scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . 1683.10.19 VMRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1693.10.20 VMSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1703.10.21 VMUL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1713.10.22 VNEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1723.10.23 VNMLA, VNMLS, VNMUL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1733.10.24 VPOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1743.10.25 VPUSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1753.10.26 VSQRT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1763.10.27 VSTM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1773.10.28 VSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1783.10.29 VSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1793.11Miscellaneous instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1803.11.1BKPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1813.11.2CPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1823.11.3DMB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1833.11.4DSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1843.11.5ISB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1853.11.6MRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1863.11.7MSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1873.11.8NOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1883.11.9SEV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1893.11.10 SVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1903.11.11WFE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1913.11.12 WFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19246/262Core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1934.1About the STM32 Cortex-M4 core peripherals . . . . . . . . . . . . . . . . . . . . 1934.2Memory protection unit (MPU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1934.2.1MPU access permission attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . 1954.2.2MPU mismatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1964.2.3Updating an MPU region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1964.2.4MPU design hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1994.2.5MPU type register (MPU TYPER) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2004.2.6MPU control register (MPU CTRL) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2014.2.7MPU region number register (MPU RNR) . . . . . . . . . . . . . . . . . . . . . 2024.2.8MPU region base address register (MPU RBAR) . . . . . . . . . . . . . . . . 203PM0214 Rev 10

PM0214Contents4.34.44.54.2.9MPU region attribute and size register (MPU RASR) . . . . . . . . . . . . . 2044.2.10MPU register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 206Nested vectored interrupt controller (NVIC) . . . . . . . . . . . . . . . . . . . . . . 2084.3.1Accessing the Cortex-M4 NVIC registers using CMSIS . . . . . . . . . . . 2094.3.2Interrupt set-enable register x (NVIC ISERx) . . . . . . . . . . . . . . . . . . . 2104.3.3Interrupt clear-enable register x (NVIC ICERx) . . . . . . . . . . . . . . . . . 2114.3.4Interrupt set-pending register x (NVIC ISPRx) . . . . . . . . . . . . . . . . . . 2124.3.5Interrupt clear-pending register x (NVIC ICPRx) . . . . . . . . . . . . . . . . 2134.3.6Interrupt active bit register x (NVIC IABRx) . . . . . . . . . . . . . . . . . . . . 2144.3.7Interrupt priority register x (NVIC IPRx) . . . . . . . . . . . . . . . . . . . . . . . 2154.3.8Software trigger interrupt register (NVIC STIR) . . . . . . . . . . . . . . . . . 2164.3.9Level-sensitive and pulse interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . 2174.3.10NVIC design hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2184.3.11NVIC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219System control block (SCB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2214.4.1Auxiliary control register (ACTLR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2224.4.2CPUID base register (CPUID) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2244.4.3Interrupt control and state register (ICSR) . . . . . . . . . . . . . . . . . . . . . . 2254.4.4Vector table offset register (VTOR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2274.4.5Application interrupt and reset control register (AIRCR) . . . . . . . . . . . 2284.4.6System control register (SCR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2304.4.7Configuration and control register (CCR) . . . . . . . . . . . . . . . . . . . . . . 2314.4.8System handler priority registers (SHPRx) . . . . . . . . . . . . . . . . . . . . . 2334.4.9System handler control and state register (SHCSR) . . . . . . . . . . . . . . 2354.4.10Configurable fault status register (CFSR; UFSR BFSR MMFSR) . . . 2374.4.11Usage fault status register (UFSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2384.4.12Bus fault status register (BFSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2394.4.13Memory management fault address register (MMFSR) . . . . . . . . . . . . 2404.4.14Hard fault status register (HFSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2414.4.15Memory management fault address register (MMFAR) . . . . . . . . . . . . 2424.4.16Bus fault address register (BFAR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2424.4.17Auxiliary fault status register (AFSR) . . . . . . . . . . . . . . . . . . . . . . . . . . 2434.4.18System control block design hints and tips . . . . . . . . . . . . . . . . . . . . . 2434.4.19SCB register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244SysTick timer (STK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2464.5.1SysTick control and status register (STK CTRL) . . . . . . . . . . . . . . . . 2474.5.2SysTick reload value register (STK LOAD) . . . . . . . . . . . . . . . . . . . . . 248PM0214 Rev 107/2628

ContentsPM02144.658/2624.5.3SysTick current value register (STK VAL) . . . . . . . . . . . . . . . . . . . . . . 2494.5.4SysTick calibration value register (STK CALIB) . . . . . . . . . . . . . . . . . 2504.5.5SysTick design hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2504.5.6SysTick register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 251Floating point unit (FPU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2524.6.1Coprocessor access control register (CPACR) . . . . . . . . . . . . . . . . . . 2534.6.2Floating-point context control register (FPCCR) . . . . . . . . . . . . . . . . . 2534.6.3Floating-point context address register (FPCAR) . . . . . . . . . . . . . . . . 2554.6.4Floating-point status control register (FPSCR) . . . . . . . . . . . . . . . . . . 2554.6.5Floating-point default status control register (FPDSCR) . . . . . . . . . . . 2574.6.6Enabling the FPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2574.6.7Enabling and clearing FPU exception interrupts . . . . . . . . . . . . . . . . . 258Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 260PM0214 Rev 10

PM0214List of tablesList of tablesTable 1.Table 2.Table 3.Table 4.Table 5.Table 6.Table 7.Table 8.Table 9.Table 10.Table 11.Table 12.Table 13.Table 14.Table 15.Table 16.Table 17.Table 18.Table 19.Table 20.Table 21.Table 22.Table 23.Table 24.Table 25.Table 26.Table 27.Table 28.Table 29.Table 30.Table 31.Table 32.Table 33.Table 34.Table 35.Table 36.Table 37.Table 38.Table 39.Table 40.Table 41.Table 42.Table 43.Table 44.Table 45.Table 46.Table 47.Table 48.Applicable products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1Summary of processor mode, execution privilege level, and stack usage . . . . . . . . . . . . . 18Core register set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18PSR register combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20APSR bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21IPSR bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22EPSR bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23PRIMASK register bit definitions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24FAULTMASK register bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24BASEPRI register bit assignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25CONTROL register bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25Ordering of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29Memory access behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30SRAM memory bit-banding regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32Peripheral memory bit-banding regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32CMSIS functions for exclusive access instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36Properties of the different exception types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38Exception return behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Faults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45Fault status and fault address registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47Cortex-M4 instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50CMSIS intrinsic functions to generate some Cortex-M4 instructions . . . . . . . . . . . . . . . . . 59CMSIS intrinsic functions to access the special registers. . . . . . . . . . . . . . . . . . . . . . . . . . 59Condition code suffixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Memory access instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69Immediate, pre-indexed and post-indexed offset ranges . . . . . . . . . . . . . . . . . . . . . . . . . . 72label-PC offset ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75Data processing instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81Multiply and divide instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109Saturating instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125Packing and unpacking instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134Instructions that operate on adjacent sets of bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138Branch and control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Branch ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143Floating-point instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Programming manual STM32 Cortex -M4 MCUs and MPUs programming manual Introduction This programming manual provides information for application and system-level software developers. It gives a full description of the STM32 Cortex -M4 processor programming model, instruction set and core peripherals. The applicable products are listed in the table