January 2015 DocID025776 Rev 6 1/165
1
UM1718
User manual
STM32CubeMX for STM32 configuration
and initialization C code generation
Introduction
STM32CubeMX is a graphical tool for 32-bit ARM
®
Cortex
®
STM32 microcontrollers. It is
part of STMCube
™
initiative (see Section 1) and is available either as a standalone
application or as an Eclipse plug-in for integration in Integrated Development Environments
(I
DEs).
STM32CubeMX ha
s the following key features:
• Eas
y microcontroller selection covering whole STM32 portfolio.
• Board selection from a list of STMicroelectronics boards.
• Easy microcontroller configuration (pins, clock tree, peripherals, middleware) and
generation of the corresponding initialization C code.
• Generation of configuration reports.
• Generation of IDE ready projects for a selection of integrated development
environment tool chains.
STM32CubeMX projects include the generated initialization C code, STM32 HAL
drivers, the middleware stacks required for the user configuration, and all the relevant
files needed to open and build the project in the selected IDE.
• Power consumption calculation for a user-defined application sequence.
• Self-updates allowing the user to keep the STM32CubeMX up-to-date.
• Download and update of STM32Cube
™
embedded software required for user
application development (see Appendix E: STM32Cube embedded software packages
for details on STM32Cube embedded software offer).
Although STM32CubeMX offers a user interface and generates a C code compliant with
STM
32 MCU design and firmware solutions, it is recommended to refer to the product
technical documentation for details on actual implementation of microcontroller peripherals
and firmware.
Reference documents
The following documents are available from h
ttp://www.st.com:
• STM32 microcontroller reference manuals
• STM32 microcontroller datasheets
•
STM32Cube HAL driver user manuals for STM32F0xx (UM1785), STM32F1xx
(UM1850), STM32F2xx (UM1742), STM32F3xx (UM1786), STM32F4xx (UM1725),
STM32L0xx (UM1749) and STM32L1xx (UM1816).
www.st.com
Contents UM1718
2/165 DocID025776 Rev 6
Contents
1 STM32Cube overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2 Getting started with STM32CubeMX . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.1 Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Key features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
2.3 Rules and limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3 Installing and running STM32CubeMX . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1 System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1.1 Supported operating systems and architectures . . . . . . . . . . . . . . . . . . 17
3.1.2 Memory prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.1.3 Software requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.2 Installing/uninstalling STM32CubeMX standalone version . . . . . . . . . . . 17
3.2.1 Installing STM32CubeMX standalone version . . . . . . . . . . . . . . . . . . . . 17
3.2.2 Uninstalling STM32CubeMX standalone version . . . . . . . . . . . . . . . . . . 18
3.3 Installing STM32CubeMX plug-in version . . . . . . . . . . . . . . . . . . . . . . . . 18
3.3.1 Downloading STM32CubeMX plug-in installation package . . . . . . . . . . 18
3.3.2 Installing STM32CubeMX as an Eclipse IDE plug-in . . . . . . . . . . . . . . . 18
3.3.3 Uninstalling STM32CubeMX as an Eclipse IDE plug-in . . . . . . . . . . . . . 20
3.4 Launching STM32CubeMX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
3.4.1 Running STM32CubeMX as standalone application . . . . . . . . . . . . . . . 21
3.4.2 Running STM32CubeMX plug-in from Eclipse IDE . . . . . . . . . . . . . . . . 21
3.5 Getting STM32Cube updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.5.1 Updater configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.5.2 Downloading new libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.5.3 Checking for updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4 STM32CubeMX User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.1 Welcome page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.2 New project window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.3 Main window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.4 Toolbar and menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.4.1 File menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
DocID025776 Rev 6 3/165
UM1718 Contents
6
4.4.2 Project menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.4.3 Pinout menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.4.4 Window menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.4.5 Help menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.5 MCUs selection window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.6 Set unused / Reset used GPIOs windows . . . . . . . . . . . . . . . . . . . . . . . . 40
4.7 Project Settings Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
4.8 Update Manager Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.9 About Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.10 Pinout view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.10.1 IP tree pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
4.10.2 Chip view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
4.10.3 Chip view advanced actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.10.4 Keep Current Signals Placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.10.5 Pinning and labeling signals on pins . . . . . . . . . . . . . . . . . . . . . . . . . . . 56
4.11 Configuration view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.11.1 IP and Middleware Configuration window . . . . . . . . . . . . . . . . . . . . . . . 59
4.11.2 GPIO Configuration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.11.3 DMA Configuration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
4.11.4 NVIC Configuration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
4.12 Clock tree configuration view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.12.1 Clock tree configuration functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
4.12.2 Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.12.3 STM32F43x/42x power-over drive feature . . . . . . . . . . . . . . . . . . . . . . 73
4.12.4 Clock tree glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
4.13 Power Consumption Calculator (PCC) view . . . . . . . . . . . . . . . . . . . . . . . 75
4.13.1 Building a power consumption sequence . . . . . . . . . . . . . . . . . . . . . . . 76
4.13.2 User-defined power sequence and results . . . . . . . . . . . . . . . . . . . . . . 79
4.13.3 Power sequence step parameters glossary . . . . . . . . . . . . . . . . . . . . . . 86
4.13.4 Battery glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
5 STM32CubeMX C Code generation overview . . . . . . . . . . . . . . . . . . . . 90
5.1 Standard STM32Cube code generation . . . . . . . . . . . . . . . . . . . . . . . . . . 90
5.2 Custom code generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Contents UM1718
4/165 DocID025776 Rev 6
6 Tutorial 1: From pinout to project C code generation
using an STM32F4 MCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
6.1 Creating a new STM32CubeMX Project . . . . . . . . . . . . . . . . . . . . . . . . . 95
6.2 Configuring the MCU pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
6.3 Saving the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
6.4 Generating the report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
6.5 Configuring the MCU Clock tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
6.6 Configuring the MCU initialization parameters . . . . . . . . . . . . . . . . . . . . 103
6.6.1 Initial conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
6.6.2 Configuring the peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
6.6.3 Configuring the GPIOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107
6.6.4 Configuring the DMAs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
6.6.5 Configuring the middleware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
6.7 Generating a complete C project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112
6.7.1 Setting project options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
6.7.2 Downloading firmware package and generating the C code . . . . . . . . 113
6.8 Building and updating the C code project . . . . . . . . . . . . . . . . . . . . . . . . .117
7 Tutorial 2 - Example of FATFS on an SD card using
STM32F429I-EVAL evaluation board . . . . . . . . . . . . . . . . . . . . . . . . . . 121
8 Tutorial 3- Getting power consumption results
for a user-defined sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.1 Creating a new power sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129
8.1.1 Adding a step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.1.2 Moving a step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.1.3 Deleting a step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
8.2 Configuring a step in the power sequence . . . . . . . . . . . . . . . . . . . . . . . 131
8.3 Reviewing results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
9 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
9.1 On the Pinout configuration pane, why does STM32CubeMX
move some functions when I add a new peripheral mode? . . . . . . . . . . 134
9.2 How can I manually force a function remapping? . . . . . . . . . . . . . . . . . 134
9.3 Why are some pins highlighted in yellow or in light green in
the Chip view? Why cannot I change the function of some
pins (when I click some pins, nothing happens)? . . . . . . . . . . . . . . . . . . 134
DocID025776 Rev 6 5/165
UM1718 Contents
6
9.4 Why do I get the error “Java 7 update 45’ when installing
‘Java 7 update 45’ or a more recent version of the JRE? . . . . . . . . . . . 134
9.5 Why does the RTC multiplexer remain inactive on the Clock tree view? 135
9.6 How can I select LSE and HSE as clock source and
change the frequency? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
9.7 Why STM32CubeMX does not allow me to configure PC13,
PC14, PC15 and PI8 as outputs when one of them
is already configured as an output? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Appendix A STM32CubeMX pin assignment rules . . . . . . . . . . . . . . . . . . . . . . 137
A.1 Block consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
A.2 Block inter-dependency. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141
A.3 One block = one peripheral mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
A.4 Block remapping (STM32F10x only). . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
A.5 Function remapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
A.6 Block shifting (only for STM32F10x and when
“Keep Current Signals placement” is unchecked). . . . . . . . . . . . . . . . . . 146
A.7 Setting and clearing a peripheral mode. . . . . . . . . . . . . . . . . . . . . . . . . . 147
A.8 Mapping a function individually . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
A.9 GPIO signals mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Appendix B STM32CubeMX C code generation design
choices and limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
B.1 STM32CubeMX generated C code and user sections . . . . . . . . . . . . . . 148
B.2 STM32CubeMX design choices for peripheral initialization . . . . . . . . . . 148
B.3 STM32CubeMX design choices and limitations for
middleware initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
B.3.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
B.3.2 USB Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
B.3.3 USB Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
B.3.4 FATFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150
B.3.5 FreeRTOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
B.3.6 LwIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
Appendix C STM32 microcontrollers naming conventions . . . . . . . . . . . . . . . 153
Appendix D STM32 microcontrollers power consumption parameters . . . . . 155
评论0