Running STM32CubeMX in command-line mode

STM32CubeMX provides command-line modes to facilitate integration with other tools and automation workflows.

With the commands listed in the table below, it is possible to:

  • load an MCU,

  • load an existing configuration,

  • save the current configuration,

  • set project parameters and generate the corresponding code,

  • generate user code from templates,

  • load a board identified by its part number,

  • refresh the list of embedded software packages and install or remove packages,

  • select additional software pack components to add to the project.

Command-line modes

Three command-line modes are available:

Interactive command-line mode

In interactive mode, STM32CubeMX starts a command prompt where commands can be entered manually.

The prompt displayed is MX>, indicating that the application is ready to accept commands.

Windows:

cd <STM32CubeMX installation path>
jre\bin\java -jar --add-opens java.desktop/java.awt=ALL-UNNAMED -add-exports java.desktop/sun.awt=ALL-UNNAMED -Djavax.net.ssl.trustStoreType=WINDOWS-ROOT STM32CubeMX.exe -i

Linux:

cd <STM32CubeMX installation path>
./STM32CubeMX -i

macOS:

cd <STM32CubeMX installation path>
cd Contents/MacOs
./STM32CubeMX -i

Script mode

In script mode, STM32CubeMX executes commands from a script file.

Windows:

cd <STM32CubeMX installation path>
jre\bin\java -jar STM32CubeMX.exe -s <script filename>

Linux and macOS:

./STM32CubeMX -s <script filename>

The script file must contain one command per line. Example:

load STM32F417VETx
project name MyFirstMXGeneratedProject
project toolchain "MDK-ARM v4"
project path C:\STM32CubeProjects\STM32F417VETx
project generate
exit

Quiet script mode

In quiet mode, STM32CubeMX executes a script without UI interaction.

Windows:

cd <STM32CubeMX installation path>
jre\bin\java -jar STM32CubeMX.exe -q <script filename>

Linux and macOS:

./STM32CubeMX -q <script filename>

As in script mode, commands are provided in a text file. The MX> prompt is displayed when the application is ready to accept commands.

Command line summary

STM32CubeMX command-line reference

Command line

Purpose

Example

help

Displays the list of available commands.

help

swmgr refresh

Refreshes the list of embedded software package versions available for download.

swmgr refresh

swmgr install stm32cube_<series>_<version> ask

Installs the specified STM32Cube MCU package version.

swmgr install stm32cube_f1_1.8.0 ask

swmgr remove stm32cube_<series>_<version>

Removes the specified STM32Cube MCU package version.

swmgr remove stm32cube_f1_1.8.0

swmgr install <packVendor>.<packName>.<packVersion> ask

Installs the specified pack version.

swmgr install STMicroelectronics.X-CUBE-NFC4.1.4.1 ask

swmgr remove <packVendor>.<packName>.<packVersion>

Removes the specified pack version.

swmgr remove STMicroelectronics.X-CUBE-BLE1.4.2.0

pack enable <vendor> <pack>[/bundle] <version> <class> <group>[/subgroup] [variant]

Selects a software pack component to add to the project.

pack enable STMicroelectronics "X-CUBE-BLE1/BlueNRG-MS" 1.0.0 "Wireless" "Controller"

pack validate

Applies in the project all pack components enabled since the last pack validate command.

pack validate

load <mcu>

Loads the selected MCU.

load STM32F101RCTx

load <board part number> <allmodes|nomode>

Loads the selected board with all peripherals configured in default mode or with no configuration.

loadboard NUCLEO-F030R8 allmodes

config load <filename>

Loads a previously saved configuration.

config load "C:\Cube\ccmram\ccmram.ioc"

config save <filename>

Saves the current configuration.

config save "C:\Cube\ccmram\ccmram.ioc"

config saveext <filename>

Saves the current configuration with all parameters, including values kept at default.

config saveext "C:\Cube\ccmram\ccmram.ioc"

config saveas <filename>

Saves the current project under a new name.

config saveas "C:\Cube\ccmram2\ccmram2.ioc"

csv pinout <filename>

Exports the current pin configuration as a CSV file.

csv pinout mypinout.csv

script <filename>

Runs all commands in the script file. There must be one command per line.

script myscript.txt

project couplefilesbyip <0|1>

Chooses whether peripheral initializations are generated in the main file or in dedicated .c/.h files.

project couplefilesbyip 1

setDriver <Peripheral Name> <HAL | LL>

Selects HAL-or LL-based peripheral initialization code generation.

setDriver ADC LL

generate code <path>

Generates only the STM32CubeMX-generated code, not a complete project.

generate code C:\mypath

set tpl_path <path>

Sets the path to the source folder containing .ftl user template files.

set tpl_path C:\myTemplates\

set dest_path <path>

Sets the destination folder used for code generated from user templates.

set dest_path C:\myMXProject\inc\

get tpl_path

Retrieves the current user template source folder path.

get tpl_path

get dest_path

Retrieves the current user template destination folder path.

get dest_path

SetStructure <Advanced/Basic>

Selects the project structure to generate.

SetStructure Basic

SetCopyLibrary <copy all / copy only / copy as reference>

Selects how reference libraries are copied to the project.

SetCopyLibrary "copy all"

project setCustomFWPath <CustomFwLocation>

Specifies an alternative STM32Cube firmware library path.

project SetCustomFWPath "F:/SharedRepository/STM32Cube_FW_F0_V1.11.0"

project toolchain <toolchain>

Specifies the project toolchain.

project toolchain STM32CubeIDE

project name <name>

Specifies the project name.

project name ccmram

project path <path>

Specifies the path where the project is generated.

project path C:\Cube\ccmram

project compiler <compiler/linker>

Sets the compiler/linker.

project compiler "GCC"

project generate

Generates the full project.

project generate

login <email_address> <password> <remember_me>

Allows you to log in to download software packages.

login john.smith@st.com mypassword y

exit

Ends the STM32CubeMX process.

exit

Notes

  • Use the login command before commands that require downloading software packages.

  • The available toolchains may include EWARM, MDK-Arm, STM32CubeIDE, Makefile, and CMake.

  • For script files, ensure there is exactly one command per line.

Example script

load STM32F417VETx
project name MyFirstMXGeneratedProject
project toolchain "MDK-ARM v4"
project path C:\STM32CubeProjects\STM32F417VETx
project generate
exit