2021-09-28 07:06 AM
I have a project that uses different MCUs. 99.99% of the code is common for all, so I have different .project, .cproject and .ioc files for each, and use CubeMx to handle the hardware initialization.
Currently, it requires manual building: Close the project, copy and replace the files, open the project, trigger code generation and compile.
Now I'm trying to automate that.
Replacing these files in a script and calling the compiler (headless build) is the easy part.
This compiles correctly when the code was already generated with CubeMX.
org.eclipse.cdt.managedbuilder.core.headlessbuild -import C:\projects\my_project -build my_project/Release
However, I was unable to automate CubeMX generation
I tried using CubeMx from CubeIDE, and also standalone version, with the same results:
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\STM32CubeMX.exe
C:\ST\STM32CubeIDE_1.7.0\STM32CubeIDE\plugins\com.st.stm32cube.common.mx_6.3.0.202107141111\STM32CubeMX.jar
If I only run this, it load the config and I can generate the code manually:
java -jar STM32CubeMX.jar my_project.ioc
If I try using a script:
java -jar STM32CubeMX.jar -q my_script
load STM32F103C(8-B)Tx
load config my_project.ioc
project name my_project
project path C:\projects\my_project
project generate
exit
I always get "Can't create config Project: error when loading config.xml file"
And this line is shown in the cmd window;
[ERROR] ApiDbMcu:562 - C:\ST\STM32CubeIDE_1.7.0\STM32CubeIDE\plugins\com.st.stm32cube.common.mx_6.3.0.202107141111\\db\//mcu/config.xml doesn't exist
I've tried a lot of different commands without success. ST example in manual is unclear.
Also the interactive switch (-i) doesn't work, the application launches normally.
Please, how to trigger code generation from command line or using a script?
Solved! Go to Solution.
2021-10-16 02:18 AM
CubeMx manual is simply terrible.
Maybe some engineers thought throwing a bunch of commands without explaining the relation between them was enough.
After more trial and error, this worked right away:
java -jar cubemx.jar -q my_script
my_script content:
config load my_project.ioc
project generate ./
exit
This also generates an EWARM project folder, but it doesn't cause any problem, as the files are correctly placed in Src, Inc and Drivers folders, CubeIde headless build works perfectly.
The EWARM folder can be deleted before/after building.
2021-09-28 10:01 PM
So this is what I've been able to extract from the help.
There's a lot more than what ST is showing in the manual, which barely includes a quick look over.
Why? Not being able to interface CubeMX in scripts will tie you to manual builds.
log
Usage:
log <level>
set
Usage:
set mode
set mode <Periph> <Mode Name>: set a mode in a peripheral / set mode <Third Party> <Bundle> <Class>
set username
set username <Periph> <User Name>: set a User name for a peripheral
set pin
set pin <pin name> <signal name>
set pinreservation
set pinreservation <pin name>
set gpio
set ip
set AllIpInContext
set AllIpInContext <ContextName>.
On multi-context MCU, Force the selection of all IPs in specified context.
Each IP of current MCU is firstly deselected from all contexts if possible before been selected in <ContextName>.
This command must be used without the UI as it is not refreshed.
set contextProject
set contextProject <mcuRefName> <ContextProjectName>
On multi-context MCU, select the specified contextProject for the current multi-context mcu.
set context
set context <ContextName> <IPInstanceName>
On multi-context MCU, assign the specified IP to the specified context.
set noparam
set noparam <ip regexp>
set userconst
set userconst <userconstant> <value> : add or update a user constant with new value
set bsp
set bsp <middleware> <bsp name> <bsp mode> <solution> [I2C address]
set tpl_path
set tpl_path <path>:set your template source path
set dest_path
set dest_path <path>:set your template destination path
import
Usage:
import hackmxdb
hackmxdb import <pin name> <signal name>: will hack the MxDb by deleting all Alternates Pins for <signal name> except for <pin name>
import openioc
load import ioc file
import set
import try
import GPIOconstraint
constraints on GPIO <constrainedGPIO>: will set the signal from pin origin to pin target
import channelconstraint
constraints on channel <IPOrigin> <channelOrigin> <IPDestination> <channelDestination>: change channel for described IPs
import get
import add_compatibility_rule
hack_rules <file>: open saved config
load
Usage:
load <mcu>: open mcu xml file
get
Usage:
get modes
get modes <peripheral regular expression match (.* for all)>: get a list of all leaf modes in a peripheral
get mapped
get mode
get mode <active|available|all> <peripheral (.* for all)>: get mode(s) for a given peripheral
get mode_param_list
get mode_param_list <peripheral> <active_mode>: get parameter(s) for a given active mode
get mode_param_possvalue
get mode_param_possvalue <peripheral> <active_mode> <parameter>: get parameter possible value(s) for a given active mode parameter
get mode_param_pattern
get mode_param_pattern <peripheral> <active_mode> <pattern>: get all pattern parameter(s) for a given active mode
get available
get signal
get signal <pin>: get the signal set on a pin
get pinout
get pinout: get the mcu pinout
get gpio
get ip
get sub-mode-state
get sub-mode-state <Periph> <moderoot,submode1,submode1.1>
get available-analog-signals
get available-analog-signals <pin name>
get sub-modes
get sub-modes <Periph>
get mcu
get functions
get functions <pin regex>: list all possible functions of a pin
get possible
get codegeneratormode
get codegeneratormode
get bsp
get version
print current version
get tpl_path
get tpl_path:get your template source path
get dest_path
get dest_path:get your template destination path
reset
Usage:
reset pin
reset pin <pin name>
reset pinreservation
reset pinreservation <pin name>
reset signal
reset signal <signal name>
reset pin-signal
reset pin <pin name> <signal name>
reset mode
reset mode <Periph> <Mode Name>: reset a mode in a peripheral
reset noparam
reset noparam <ip regexp>
reset userconst
reset userconst <userconstant> : remove a user constant. No error reporting
pinout
Usage:
pinout check
pinout uncheck
add
Usage:
add mw
add mw name root_dir mode_file config_file template_dir
check
Usage:
check mcu
check mode
check mcus
csv
Usage:
csv pinout
csv pinout <file>
generate
Usage:
generate code
generate code <path>
generate all_code_in_main
generate all code in main.c
generate one_file_per_ip
generate one file per ip
tinyload
Usage:
tinyload <mcu>: load mcu for pinout only
waitclock
Usage:
Wait for a delay in seconds until clock has finished its initialization
switch
Usage:
switch context
switch context <ContextName> <IPInstanceName>
On multi-context MCU, switch the specified IP to the specified context without lost of its configuration.
unset
Usage:
unset context
unset context <ContextName> <IPInstanceName>
On multi-context MCU, remove the specified IP from the specified context.
unset bsp
unset bsp <middleware> <bsp name>
export
Usage:
export script
export configAsScript <outputscript>
list
Usage:
list ipdependencies
list ipdependencies
loadboard
Usage:
loadboard <boardname> <allmodes>]|<nomode> load a board with or without modes
project
Usage:
project couplefilesbyip
project couplefilesbyip <1/0>: Peripheral initialization done in main or in separate IPs files.
project generateunderroot
project generateunderroot <1/0>: Project files generated under project root directory instead of specific subdir .
project generate
project generate: generates full project
project toolchain
project toolchain <toolchain>: set toolchain
project toolchainlocation
project toolchainlocation <toolchain location>: set toolchainlocation
project set
project get
project path
project path <path>: set project path
project name
project name <name>: set project name
project import
import project setting parameters
project save
save project setting
project setCustomFWPath
project setCustomFWPath <CustomFwLocation>: Set the custome FW Location.
setDriver
Usage:
set Ip driver
setStructure
Usage:
Set Application structure (Advanced/Basic).
SetCopyLibrary
Usage:
Set Copy Library (copy all/ copy only / copy as reference).
pinout
Usage:
pinout check
pinout uncheck
disable
Usage:
disable project
tooltip
Usage:
tooltip log
clock
Usage:
clock resolution
resolve clock issues
updateIpUI
Usage:
update UI <IpName>: update the UI for a given IP
swmgr
Usage:
swmgr hello
swmgr hello : say hello
swmgr getSelectedDB
swmgr getSelectedDB
swmgr refresh
swmgr refresh : Launch a refresh
swmgr set
swmgr connection
swmgr install
swmgr install <full_cmsispack_name | full_firmware_name | full_filepath> <licence_mode (deny|ask)>: install specified Cmsis packname or Cube Firmware with selected license accept mode.
swmgr remove
swmgr remove <full_pack_name | full_firmware_name>: remove specified cmsis packname or Cube Firmware
config
Usage:
config load
load <file>: open saved config
config save
save: save config
config saveas
save <file>: save config
xcopy
Usage:
xcopy
<sw_vendor><sw_version><example_name><example_path><ide:all|iar|keil|swb|cube> default:all
<copy_fw:NONE|LITE|FULL> default:LITE
<opt:user_example_path> default:$HOME/STM32CubEX
<opt:fw_path> default:$HOME/STM32Cube/Repository
<opt:board_name> default: empty
Description: Open cube example test
Example: xcopy "STMicroelectronics" "X-CUBE-BLE2_V3.2.0" "Beacon" "/Projects/NUCLEO-L476RG/Applications/Beacon" "all" "LITE" "" "" "NUCLEO-L476RG"
2021-10-16 02:18 AM
CubeMx manual is simply terrible.
Maybe some engineers thought throwing a bunch of commands without explaining the relation between them was enough.
After more trial and error, this worked right away:
java -jar cubemx.jar -q my_script
my_script content:
config load my_project.ioc
project generate ./
exit
This also generates an EWARM project folder, but it doesn't cause any problem, as the files are correctly placed in Src, Inc and Drivers folders, CubeIde headless build works perfectly.
The EWARM folder can be deleted before/after building.
2022-03-03 03:55 AM
Did you also got it working with complete headless cubemx generation?
Trying your workflow still shows dialogues and is still asking questions whether to migrate to newer versions and stuff.
How did you figure out if there are arguments to commands in the script?
2022-03-03 04:40 AM
No idea.
As you see, ST didn't care much, and the included help is close to nothing.
It seems you have two options: Stay with the cubemx version or manually migrate on every update.
How did I found these commands?
Create a file, ex. script.txt:
help
exit
Open a cmd window or console:
For standalone CubeMX:
cd C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX
java -jar cubemx.jar -q script.txt
For CubeMX included in STM32Cube IDE:
cd c:\ST\STM32CubeIDE\plugins\com.st.stm32cube.common.mx_6.4.0.202111222105
java -jar STM32CubeMX.jar -q script.txt
Watch the cmd window, everything will be printed there.
For more detailed help, you can run "cmd help", ex.:
project help
generate help
exit
Which is what I did, then wrote everything in my previous post.
It seems the only way to interact with cubeMX is using scripts.
Running cubemx.jar -help, --help, /help, -h, --h, etc... never works.
2023-08-03 06:05 AM - edited 2023-08-03 06:05 AM
Hello.
I am working with stmcubemx 6.5 for Linux.
I can't manage going for interactive or script mode, the application always starts UI.
According to UM 1718 §3.3.2, I shall call the binary with '-i' or '-s' argument, but the UI is awlays showing up.
Seems that you do have this working indeed, did you experience the same difficulty as me before ?
Here is the application bootlog. Thanks.
naut@ubuntu:~$ /opt/st/stm32cubemx-lin_v6-5-0/STM32CubeMX -i
Check exe path on linux
FullExe path1 is: /opt/st/stm32cubemx-lin_v6-5-0/STM32CubeMX
Exe path is: /opt/st/stm32cubemx-lin_v6-5-0
Search java from relative path ----
Checking java in /opt/st/stm32cubemx-lin_v6-5-0/./jre/bin/java
current working dir : /home/naut
av[0] /opt/st/stm32cubemx-lin_v6-5-0/STM32CubeMX
chdir to :/opt/st/stm32cubemx-lin_v6-5-0
New current working dir /opt/st/stm32cubemx-lin_v6-5-0
Full command: /opt/st/stm32cubemx-lin_v6-5-0/./jre/bin/java
-args[0] java
-args[1] -jar
-args[2] STM32CubeMX
-args[3] -i
log4j user configuration file not found: /home/naut/.stm32cubemx/log4j.properties
Configure log4j with default settings from jar:file:/opt/st/stm32cubemx-lin_v6-5-0/STM32CubeMX!/log4j/log4j.stm32cubemx.properties
2023-08-03 15:01:21,539 [INFO] MicroXplorer:88 - [MX] MX Start == 17984615708986
2023-08-03 15:01:21,540 [INFO] MicroXplorer:632 - Detected Java Version = 11.0.10
2023-08-03 15:01:21,744 [INFO] ApplicationProperties:181 - Using Application install path: /opt/st/stm32cubemx-lin_v6-5-0
2023-08-03 15:01:21,764 [INFO] DbMcusXml:72 - Set database path to: /opt/st/stm32cubemx-lin_v6-5-0//db//mcu/
2023-08-03 15:01:21,766 [INFO] ApiDb:260 - Set plugin database path to: /opt/st/stm32cubemx-lin_v6-5-0//db//plugins/boardmanager/
2024-08-15 03:21 PM
Hi,
I see that this discussion was years ago, yet I have come across just now. I cannot see the answer to the second half of the question, namely, interactive invocation with "-i". I faced the same behavior today on Windows 11. Eventually, I have managed to enter the interactive mode with the cursor stopping at the STM32CubeMX> prompt.
The thing is, it worked when I appended Project.ioc:
jre\bin\java -jar STM32CubeMX.exe -i Project.ioc
I wonder if this is the intended behavior by design just wrongly documented or bug?