
February 2014 DocID025776 Rev 1 1/127
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 STM32Cube initiative (see
Section 1) and is available either as a standalone
application or as an Eclipse plug-in for integration in Integrated Development Environments
(IDEs).
STM32CubeMX has the following key features:
• Easy microcontroller selection covering whole STM32 portfolio.
• 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.
• Downloading and updating STM32Cube
™
firmware packages allowing the
download from www.st.com of the MCU firmware package required for the
development of the user application (see Appendix E: STM32Cube embedded
software packages for details on the STM32Cube package).
Although STM32CubeMX offers a user interface and generates a C code compliant with
STM32 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 http//:www.st.com:
• STM32 microcontroller reference manuals
• STM32 microcontroller datasheets
• Description of STM32F4xx HAL driver user manual (UM1725)
www.st.com

Contents UM1718
2/127 DocID025776 Rev 1
Contents
1 STM32Cube™ overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
2 Getting started with STM32CubeMX . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
2.1 Principles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
2.2 Key features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.3 Rules and limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3 Installing and running STM32CubeMX . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1 System requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1.1 Supported operating systems and architectures . . . . . . . . . . . . . . . . . . 15
3.1.2 Memory prerequisites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.1.3 Software requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
3.2 Installing/uninstalling STM32CubeMX standalone version . . . . . . . . . . . 15
3.2.1 Installing STM32CubeMX standalone version . . . . . . . . . . . . . . . . . . . . 15
3.2.2 Uninstalling STM32CubeMX standalone version . . . . . . . . . . . . . . . . . . 16
3.3 Installing STM32CubeMX plug-in version . . . . . . . . . . . . . . . . . . . . . . . . 16
3.3.1 Downloading STM32CubeMX plug-in installation package . . . . . . . . . . 16
3.3.2 Installing STM32CubeMX as an Eclipse IDE plug-in . . . . . . . . . . . . . . . 16
3.3.3 Uninstalling STM32CubeMX as an Eclipse IDE plug-in . . . . . . . . . . . . . 18
3.4 Launching STM32CubeMX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.4.1 Running STM32CubeMX as standalone application . . . . . . . . . . . . . . . 19
3.4.2 Running STM32CubeMX plug-in from Eclipse IDE . . . . . . . . . . . . . . . . 19
3.5 Getting STM32Cube updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.5.1 Updater configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
3.5.2 Downloading new libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.5.3 Checking for updates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
4 STM32CubeMX User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.1 Welcome page . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
4.2 Main window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
4.3 Toolbar and menus . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.3.1 File menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.3.2 Project menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30

DocID025776 Rev 1 3/127
UM1718 Contents
5
4.3.3 Pinout menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31
4.3.4 Window menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.3.5 Help menu . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.4 New project window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.5 MCUs selection window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.6 Set unused / Reset used GPIOs windows . . . . . . . . . . . . . . . . . . . . . . . . 34
4.7 Project Settings Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.8 Update Manager Windows . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.9 About Window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.10 Pinout view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.10.1 IP tree pane . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.10.2 Chip view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.10.3 Chip view advanced actions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.10.4 Keep Current Signals Placement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.11 Configuration view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.11.1 IP and Middleware Configuration window (for STM32F4 series only) . . 49
4.11.2 GPIO Configuration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
4.11.3 DMA Configuration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
4.11.4 NVIC Configuration window . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55
4.12 Clock tree configuration view . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.12.1 Clock tree configuration functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.12.2 Recommendations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
4.12.3 STM32F43x/42x power-over drive feature . . . . . . . . . . . . . . . . . . . . . . 59
4.12.4 Clock tree glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
4.13 Power Consumption Calculator (PCC) view . . . . . . . . . . . . . . . . . . . . . . . 61
4.13.1 Building a power consumption sequence . . . . . . . . . . . . . . . . . . . . . . . 62
4.13.2 User-defined power sequence and results . . . . . . . . . . . . . . . . . . . . . . 63
4.13.3 Power sequence step parameters glossary . . . . . . . . . . . . . . . . . . . . . . 67
4.13.4 Battery glossary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5 STM32CubeMX C Code generation overview . . . . . . . . . . . . . . . . . . . . 70
6 Tutorial 1: From pinout to project C code generation
using an STM32F4 MCU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.1 Creating a new STM32CubeMX Project . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.2 Configuring the MCU pinout . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

Contents UM1718
4/127 DocID025776 Rev 1
6.3 Saving the project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6.4 Generating the report . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6.5 Configuring the MCU Clock tree . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.6 Configuring the MCU initialization parameters . . . . . . . . . . . . . . . . . . . . 79
6.6.1 Initial conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6.6.2 Configuring the peripherals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.6.3 Configuring the GPIOs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6.6.4 Configuring the DMAs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
6.6.5 Configuring the middleware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
6.7 Generating GPIO initialization C code (except STM32F4) . . . . . . . . . . . . 86
6.8 Generating a complete C project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
6.8.1 Setting project options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
6.8.2 Downloading firmware package and generating the C code . . . . . . . . . 90
6.9 Building and updating the C code project . . . . . . . . . . . . . . . . . . . . . . . . . 94
7 Tutorial 2 - Getting power consumption results
for a user-defined sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7.1 Creating a new power sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
7.1.1 Adding a step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
7.1.2 Moving a step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
7.1.3 Deleting a step . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
7.2 Configuring a step in the power sequence . . . . . . . . . . . . . . . . . . . . . . . 100
7.3 Reviewing results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
8 FAQ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
8.1 On the Pinout configuration panel, why does STM32CubeMX
move some functions when I add a new peripheral mode? . . . . . . . . . . 104
8.2 How can I manually force a function remapping? . . . . . . . . . . . . . . . . . 104
8.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)? . . . . . . . . . . . . . . . . . . 104
Appendix A STM32CubeMX pin assignment rules . . . . . . . . . . . . . . . . . . . . . . 105
A.1 Block consistency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
A.2 Block inter-dependency. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108
A.3 One block = one peripheral mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .111

DocID025776 Rev 1 5/127
UM1718 Contents
5
A.4 Block remapping (STM32F10x only). . . . . . . . . . . . . . . . . . . . . . . . . . . . .111
A.5 Function remapping. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .112
A.6 Block shifting (only for STM32F10x and when
“Keep Current Signals placement” is unchecked). . . . . . . . . . . . . . . . . . .113
A.7 Setting and clearing a peripheral mode. . . . . . . . . . . . . . . . . . . . . . . . . . .114
A.8 Mapping a function individually . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
A.9 GPIO signals mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .114
Appendix B STM32CubeMX C code generation design
choices and limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
B.1 STM32CubeMX generated C C code and user sections . . . . . . . . . . . . .115
B.2 STM32CubeMX design choices for peripheral initialization . . . . . . . . . . .115
B.3 STM32CubeMX design choices and limitations for
middleware initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .116
B.3.1 Overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
B.3.2 USB Host . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
B.3.3 USB Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116
B.3.4 FATFS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
B.3.5 FreeRTOS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
B.3.6 LwIP . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118
Appendix C STM32 microcontrollers naming conventions . . . . . . . . . . . . . . . 120
Appendix D STM32 microcontrollers power consumption parameters . . . . . 121
D.1 Power modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
D.1.1 STM32L1 series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
D.1.2 STM32F4 series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122
D.2 Power consumption ranges. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
D.2.1 STM32L1 series feature 3 VCORE ranges. . . . . . . . . . . . . . . . . . . . . . 123
D.2.2 STM32F4 series feature several VCORE scales . . . . . . . . . . . . . . . . . 123
Appendix E STM32Cube embedded software packages . . . . . . . . . . . . . . . . . 125
9 Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126