没有合适的资源?快使用搜索试试~ 我知道了~
首页STM32L0和STM32G0单片机编程手册_ENV4.pdf
This programming manual provides information for application and system-level software developers. It gives a full description of the programming model, instruction set, and core peripherals of the Cortex®-M0+ processor used on the STM32L0 Series and STM32G0 Series MCUs
资源详情
资源评论
资源推荐

October 2018 PM0223 Rev 4 1/110
1
PM0223
Programming manual
STM32L0 Series and STM32G0 Series Cortex
®
-M0+ programming
manual
Introduction
This programming manual provides information for application and system-level software
developers. It gives a full description of the programming model, instruction set, and core
peripherals of the Cortex
®
-M0+ processor used on the STM32L0 Series and STM32G0
Series MCUs.
Cortex
®
-M0+ is a high performance 32-bit processor designed for integration in
microcontrollers. It offers significant benefits to developers, including:
• Outstanding processing performance combined with fast interrupt handling
• Enhanced system debug with extensive breakpoint options
• Efficient processor core, system and memories
• Ultra-low power consumption with integrated sleep modes
• Platform security
www.st.com

Contents PM0223
2/110 PM0223 Rev 4
Contents
1 About this document . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.1 Typographical conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 List of abbreviations for registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3 About the Cortex-M0+ processor and core peripherals . . . . . . . . . . . . . . . 9
1.3.1 System-level interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.2 Integrated configurable debug . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.3.3 Cortex-M0+ processor feature summary . . . . . . . . . . . . . . . . . . . . . . . . 11
1.3.4 Cortex-M0+ core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2 Cortex-M0+ processor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1 Programmers model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.1 Processor modes and privilege levels for software execution . . . . . . . . 12
2.1.2 Stacks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.1.3 Core registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1.4 Exceptions and interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.1.5 Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
2.1.6 The Cortex Microcontroller Software Interface Standard . . . . . . . . . . . . 19
2.2 Memory model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2.1 Memory regions, types and attributes . . . . . . . . . . . . . . . . . . . . . . . . . . 20
2.2.2 Memory system ordering of memory accesses . . . . . . . . . . . . . . . . . . . 21
2.2.3 Behavior of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
2.2.4 Additional memory access constraints for caches and shared memory 23
2.2.5 Software ordering of memory accesses . . . . . . . . . . . . . . . . . . . . . . . . 23
2.2.6 Memory endianness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
2.3 Exception model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.3.1 Exception states . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.3.2 Exception types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
2.3.3 Exception handlers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
2.3.4 Vector table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
2.3.5 Exception priorities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.3.6 Exception entry and return . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
2.4 Fault handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.4.1 Lockup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

PM0223 Rev 4 3/110
PM0223 Contents
5
2.5 Power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
2.5.1 Entering sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.5.2 Wakeup from sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
2.5.3 The external event input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
2.5.4 Power management programming hints . . . . . . . . . . . . . . . . . . . . . . . . 35
3 Cortex-M0+ instruction set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.1 Instruction set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3.2 Intrinsic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.3 About the instruction descriptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.3.1 Operands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.3.2 Restrictions when using PC or SP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.3.3 Shift operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
3.3.4 Address alignment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
3.3.5 PC-relative expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.3.6 Conditional execution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
3.4 Memory access instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.4.1 ADR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
3.4.2 LDR and STR, immediate offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
3.4.3 LDR and STR, register offset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
3.4.4 LDR, PC-relative . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.4.5 LDM and STM . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.4.6 PUSH and POP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
3.5 General data processing instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
3.5.1 ADC, ADD, RSB, SBC, and SUB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
3.5.2 AND, ORR, EOR, and BIC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
3.5.3 ASR, LSL, LSR, and ROR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
3.5.4 CMP and CMN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
3.5.5 MOV and MVN . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
3.5.6 MULS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
3.5.7 REV, REV16, and REVSH . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
3.5.8 SXT and UXT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63
3.5.9 TST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
3.6 Branch and control instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
3.6.1 B, BL, BX, and BLX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
3.7 Miscellaneous instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68

Contents PM0223
4/110 PM0223 Rev 4
3.7.1 BKPT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
3.7.2 CPS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
3.7.3 DMB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
3.7.4 DSB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
3.7.5 ISB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
3.7.6 MRS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
3.7.7 MSR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
3.7.8 NOP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
3.7.9 SEV . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77
3.7.10 SVC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
3.7.11 WFE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
3.7.12 WFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
4 Cortex-M0+ core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.1 About the Cortex-M0+ core peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . 81
4.2 Nested vectored interrupt controller . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
4.2.1 Accessing the Cortex-M0+ NVIC registers using CMSIS . . . . . . . . . . . 82
4.2.2 Interrupt Set-enable Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.2.3 Interrupt Clear-enable Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
4.2.4 Interrupt Set-pending Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.2.5 Interrupt Clear-pending Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
4.2.6 Interrupt Priority Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
4.2.7 Level-sensitive and pulse interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
4.2.8 NVIC usage hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
4.3 System Control Block . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.3.1 The CMSIS mapping of the Cortex-M0+ SCB registers . . . . . . . . . . . . 88
4.3.2 CPUID Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88
4.3.3 Interrupt Control and State Register (ICSR) . . . . . . . . . . . . . . . . . . . . . 89
4.3.4 Vector Table Offset Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
4.3.5 Application Interrupt and Reset Control Register . . . . . . . . . . . . . . . . . 91
4.3.6 System Control Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
4.3.7 Configuration and Control Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
4.3.8 System Handler Priority Registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
4.3.9 SCB usage hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.4 SysTick timer (STK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
4.4.1 SysTick Control and Status Register (STK_CSR) . . . . . . . . . . . . . . . . . 96
4.4.2 SysTick Reload Value Register (STK_RVR) . . . . . . . . . . . . . . . . . . . . . 96

PM0223 Rev 4 5/110
PM0223 Contents
5
4.4.3 SysTick Current Value Register (STK_CVR) . . . . . . . . . . . . . . . . . . . . . 97
4.4.4 SysTick Calibration Value Register (STK_CALIB) . . . . . . . . . . . . . . . . . 97
4.4.5 SysTick usage hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.5 Memory Protection Unit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
4.5.1 MPU Type Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
4.5.2 MPU Control Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
4.5.3 MPU Region Number Register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
4.5.4 MPU Region Base Address Register . . . . . . . . . . . . . . . . . . . . . . . . . . 102
4.5.5 MPU Region Attribute and Size Register . . . . . . . . . . . . . . . . . . . . . . . 103
4.5.6 MPU access permission attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
4.5.7 MPU mismatch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
4.5.8 Updating an MPU region . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
4.5.9 MPU design hints and tips . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
4.6 I/O Port . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
5 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
剩余109页未读,继续阅读


















安全验证
文档复制为VIP权益,开通VIP直接复制

评论0