PM0214 Programming Manual - Cse.scu.edu

Transcription

PM0214Programming manualSTM32F3, STM32F4 and STM32L4 SeriesCortex -M4 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 STM32F3, STM32F4 and STM32L4 Series Cortex -M4 processor is a highperformance 32-bit processor designed for the microcontroller 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 securityReference documentsAvailable from STMicroelectronics web site www.st.com:April 2016 STM32F3, STM32F4 and STM32L4 Series datasheets STM32F3, STM32F4 and STM32L4 Series reference manualsDocID022708 Rev 51/260www.st.com

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 . . . . . . . . . . . . . . 141.3.4Cortex-M4 core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15The Cortex-M4 processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.12.22.32/2601.3.1Programmers model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.1.1Processor mode and privilege levels for software execution . . . . . . . . . 162.1.2Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 162.1.3Core registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172.1.4Exceptions and interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.1.5Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252.1.6The Cortex microcontroller software interface standard (CMSIS) . . . . . 25Memory model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 272.2.1Memory regions, types and attributes . . . . . . . . . . . . . . . . . . . . . . . . . . 282.2.2Memory system ordering of memory accesses . . . . . . . . . . . . . . . . . . . 282.2.3Behavior of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292.2.4Software ordering of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . 302.2.5Bit-banding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312.2.6Memory endianness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.2.7Synchronization primitives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 332.2.8Programming hints for the synchronization primitives . . . . . . . . . . . . . . 35Exception model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.3.1Exception states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.3.2Exception types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 362.3.3Exception handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 382.3.4Vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 392.3.5Exception priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402.3.6Interrupt priority grouping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 402.3.7Exception entry and return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41DocID022708 Rev 5

PM0214Contents2.42.53Fault handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 432.4.1Fault types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 442.4.2Fault escalation and hard faults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 452.4.3Fault status registers and fault address registers . . . . . . . . . . . . . . . . . 462.4.4Lockup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46Power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 462.5.1Entering sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472.5.2Wakeup from sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 472.5.3External event input / extended interrupt and event input . . . . . . . . . . . 482.5.4Power management programming hints . . . . . . . . . . . . . . . . . . . . . . . . 48The STM32 Cortex-M4 instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . 493.1Instruction set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 493.2CMSIS intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 573.3About the instruction descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593.43.53.3.1Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593.3.2Restrictions when using PC or SP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593.3.3Flexible second operand . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 593.3.4Shift operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 613.3.5Address alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643.3.6PC-relative expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643.3.7Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 643.3.8Instruction width selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67Memory access instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 683.4.1ADR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 693.4.2LDR and STR, immediate offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 703.4.3LDR and STR, register offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 723.4.4LDR and STR, unprivileged . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 733.4.5LDR, PC-relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 743.4.6LDM and STM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 753.4.7PUSH and POP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 773.4.8LDREX and STREX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 783.4.9CLREX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79General data processing instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 803.5.1ADD, ADC, SUB, SBC, and RSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 823.5.2AND, ORR, EOR, BIC, and ORN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84DocID022708 Rev 53/2608

ContentsPM02143.63.73.5.3ASR, LSL, LSR, ROR, and RRX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 853.5.4CLZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 863.5.5CMP and CMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 873.5.6MOV and MVN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 883.5.7MOVT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 903.5.8REV, REV16, REVSH, and RBIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 913.5.9SADD16 and SADD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 923.5.10SHADD16 and SHADD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 933.5.11SHASX and SHSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 943.5.12SHSUB16 and SHSUB8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 953.5.13SSUB16 and SSUB8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 963.5.14SASX and SSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 973.5.15TST and TEQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 983.5.16UADD16 and UADD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 993.5.17UASX and USAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1003.5.18UHADD16 and UHADD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1013.5.19UHASX and UHSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1023.5.20UHSUB16 and UHSUB8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1033.5.21SEL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1043.5.22USAD8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1053.5.23USADA8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1063.5.24USUB16 and USUB8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107Multiply and divide instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1083.6.1MUL, MLA, and MLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1093.6.2UMULL, UMAAL and UMLAL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1103.6.3SMLA and SMLAW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1113.6.4SMLAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1133.6.5SMLAL and SMLALD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1143.6.6SMLSD and SMLSLD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1163.6.7SMMLA and SMMLS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1183.6.8SMMUL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1193.6.9SMUAD and SMUSD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1203.6.10SMUL and SMULW . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1213.6.11UMULL, UMLAL, SMULL, and SMLAL . . . . . . . . . . . . . . . . . . . . . . . . 1223.6.12SDIV and UDIV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123Saturating instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1243.7.14/260SSAT and USAT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125DocID022708 Rev 5

PM0214Contents3.83.93.103.7.2SSAT16 and USAT16 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1263.7.3QADD and QSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1273.7.4QASX and QSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1283.7.5QDADD and QDSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1293.7.6UQASX and UQSAX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1303.7.7UQADD and UQSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131Packing and unpacking instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1333.8.1PKHBT and PKHTB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1343.8.2SXT and UXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1353.8.3SXTA and UXTA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136Bitfield instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1373.9.1BFC and BFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1383.9.2SBFX and UBFX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1393.9.3SXT and UXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1403.9.4Branch and control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1413.9.5B, BL, BX, and BLX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1413.9.6CBZ and CBNZ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1433.9.7IT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1443.9.8TBB and TBH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146Floating-point instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1483.10.1VABS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1503.10.2VADD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1513.10.3VCMP, VCMPE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1523.10.4VCVT, VCVTR between floating-point and integer . . . . . . . . . . . . . . . 1533.10.5VCVT between floating-point and fixed-point . . . . . . . . . . . . . . . . . . . 1543.10.6VCVTB, VCVTT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1553.10.7VDIV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1563.10.8VFMA, VFMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1573.10.9VFNMA, VFNMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1583.10.10 VLDM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1593.10.11 VLDR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1603.10.12 VLMA, VLMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1613.10.13 VMOV immediate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1623.10.14 VMOV register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1633.10.15 VMOV scalar to ARM core register . . . . . . . . . . . . . . . . . . . . . . . . . . . 1643.10.16 VMOV ARM core register to single precision . . . . . . . . . . . . . . . . . . . 1653.10.17 VMOV two ARM core registers to two single precision . . . . . . . . . . . . 166DocID022708 Rev 55/2608

ContentsPM02143.10.18 VMOV ARM Core register to scalar . . . . . . . . . . . . . . . . . . . . . . . . . . . 1673.10.19 VMRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1683.10.20 VMSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1693.10.21 VMUL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1703.10.22 VNEG . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1713.10.23 VNMLA, VNMLS, VNMUL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1723.10.24 VPOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1733.10.25 VPUSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1743.10.26 VSQRT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1753.10.27 VSTM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1763.10.28 VSTR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1773.10.29 VSUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1783.11Miscellaneous instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1793.11.1BKPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1803.11.2CPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1813.11.3DMB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1823.11.4DSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1833.11.5ISB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1843.11.6MRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1853.11.7MSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1863.11.8NOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1873.11.9SEV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1883.11.10 SVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1893.11.11WFE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1903.11.12 WFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19146/260Core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1924.1About the STM32 Cortex-M4 core peripherals . . . . . . . . . . . . . . . . . . . . 1924.2Memory protection unit (MPU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1924.2.1MPU access permission attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . 1944.2.2MPU mismatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1954.2.3Updating an MPU region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1954.2.4MPU design hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1984.2.5MPU type register (MPU TYPER) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1994.2.6MPU control register (MPU CTRL) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2004.2.7MPU region number register (MPU RNR) . . . . . . . . . . . . . . . . . . . . . 2014.2.8MPU region base address register (MPU RBAR) . . . . . . . . . . . . . . . . 202DocID022708 Rev 5

PM0214Contents4.34.44.54.2.9MPU region attribute and size register (MPU RASR) . . . . . . . . . . . . . 2034.2.10MPU register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205Nested vectored interrupt controller (NVIC) . . . . . . . . . . . . . . . . . . . . . . 2074.3.1Accessing the Cortex-M4 NVIC registers using CMSIS . . . . . . . . . . . 2084.3.2Interrupt set-enable registers (NVIC ISERx) . . . . . . . . . . . . . . . . . . . . 2094.3.3Interrupt clear-enable registers (NVIC ICERx) . . . . . . . . . . . . . . . . . . 2104.3.4Interrupt set-pending registers (NVIC ISPRx) . . . . . . . . . . . . . . . . . . . 2114.3.5Interrupt clear-pending registers (NVIC ICPRx) . . . . . . . . . . . . . . . . . 2124.3.6Interrupt active bit registers (NVIC IABRx) . . . . . . . . . . . . . . . . . . . . . 2134.3.7Interrupt priority registers (NVIC IPRx) . . . . . . . . . . . . . . . . . . . . . . . . 2144.3.8Software trigger interrupt register (NVIC STIR) . . . . . . . . . . . . . . . . . 2154.3.9Level-sensitive and pulse interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . 2164.3.10NVIC design hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2174.3.11NVIC register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218System control block (SCB) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2204.4.1Auxiliary control register (ACTLR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2214.4.2CPUID base register (CPUID) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2234.4.3Interrupt control and state register (ICSR) . . . . . . . . . . . . . . . . . . . . . . 2244.4.4Vector table offset register (VTOR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2264.4.5Application interrupt and reset control register (AIRCR) . . . . . . . . . . . 2274.4.6System control register (SCR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2294.4.7Configuration and control register (CCR) . . . . . . . . . . . . . . . . . . . . . . 2304.4.8System handler priority registers (SHPRx) . . . . . . . . . . . . . . . . . . . . . 2324.4.9System handler control and state register (SHCSR) . . . . . . . . . . . . . . 2344.4.10Configurable fault status register (CFSR; UFSR BFSR MMFSR) . . . 2364.4.11Usage fault status register (UFSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . 2374.4.12Bus fault status register (BFSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2384.4.13Memory management fault address register (MMFSR) . . . . . . . . . . . . 2394.4.14Hard fault status register (HFSR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2404.4.15Memory management fault address register (MMFAR) . . . . . . . . . . . . 2414.4.16Bus fault address register (BFAR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2414.4.17Auxiliary fault status register (AFSR) . . . . . . . . . . . . . . . . . . . . . . . . . . 2424.4.18System control block design hints and tips . . . . . . . . . . . . . . . . . . . . . 2424.4.19SCB register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243SysTick timer (STK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2454.5.1SysTick control and status register (STK CTRL) . . . . . . . . . . . . . . . . 2464.5.2SysTick reload value register (STK LOAD) . . . . . . . . . . . . . . . . . . . . . 247DocID022708 Rev 57/2608

ContentsPM02144.658/2604.5.3SysTick current value register (STK VAL) . . . . . . . . . . . . . . . . . . . . . . 2484.5.4SysTick calibration value register (STK CALIB) . . . . . . . . . . . . . . . . . 2494.5.5SysTick design hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2494.5.6SysTick register map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 250Floating point unit (FPU) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2514.6.1Coprocessor access control register (CPACR) . . . . . . . . . . . . . . . . . . 2524.6.2Floating-point context control register (FPCCR) . . . . . . . . . . . . . . . . . 2524.6.3Floating-point context address register (FPCAR) . . . . . . . . . . . . . . . . 2544.6.4Floating-point status control register (FPSCR) . . . . . . . . . . . . . . . . . . 2544.6.5Floating-point default status control register (FPDSCR) . . . . . . . . . . . 2564.6.6Enabling the FPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2564.6.7Enabling and clearing FPU exception interrupts . . . . . . . . . . . . . . . . . 257Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 259DocID022708 Rev 5

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.Summary of processor mode, execution privilege level, and stack usage . . . . . . . . . . . . . 17Core register set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17PSR register combinations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19APSR bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20IPSR bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21EPSR bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22PRIMASK register bit definitions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23FAULTMASK register bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23BASEPRI register bit assignments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24CONTROL register bit definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24Ordering of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28Memory access behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29SRAM memory bit-banding regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31Peripheral memory bit-banding regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31CMSIS functions for exclusive access instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35Properties of the different exception types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37Exception return behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43Faults . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44Fault status and fault address registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46Cortex-M4 instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49CMSIS intrinsic functions to generate some Cortex-M4 instructions . . . . . . . . . . . . . . . . . 58CMSIS intrinsic functions to access the special registers. . . . . . . . . . . . . . . . . . . . . . . . . . 58Condition code suffixes. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Memory access instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68Immediate, pre-indexed and post-indexed offset ranges . . . . . . . . . . . . . . . . . . . . . . . . . . 71label-PC offset ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74Data processing instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80Multiply and divide instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108Saturating instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124Packing and unpacking instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133Instructions that operate on adjacent sets of bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137Branch and control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141Branch ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142Floating-point instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148Miscellaneous instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179STM32 core peripheral register regions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192Memory attributes summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193TEX, C, B, and S encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194Cache policy for memory attribute encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194AP encoding . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195Memory region attributes for STM32 . . . . . . . . . . . . . . . . . . . . . . . .

Cortex -M4 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 STM32F3, STM32F4 and STM32L4 Series Cortex -M4 processor is a high