2025-12-11 3:49 AM - last edited on 2025-12-11 4:11 AM by Andrew Neil
Follow-on from CubeMX code generation from command line.
I am posting again in hopes of getting meaningful answer.
I tried creating a simple script text file to automate code generation for my project. The script file has all of three lines:
config load DCC_tester.ioc
generate code .
exit
The feedback I got on why it did not work was my .ico file was corrupted. To prove this was not the case I used a very simple project file using one of your example projects from one of your released STM32H5 bundles.
The only modification I made was changing the name and making it a cmake project.
I am running on Windows 11 with CubeMX installed using all defaults.
I can click on the .ioc file from Windows Explorer and the MX IDE opens just fine. I can click the "GENERATE CODE" button and that also works just fine. All the files are generated as expected.
I try launching using the -q using ether a PowerShell script or a command line batch file and neither completes although it looks like its trying. Seems to stall leaving a MXTmpFiles folder. cmake and other files like startup and linker file are not generated.
I have attached the .ioc the script text file as well as PowerShell and batch file ... none work as expected.
Solved! Go to Solution.
2025-12-12 6:40 AM - edited 2025-12-12 6:42 AM
Hello @dvescovi
Just use "exit" instead of "exit_mx"
Please remember to mark the reply that helped you as the Best Answer so that other users can more easily find this solution.
THX
Ghofrane
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-12-11 3:54 AM - edited 2025-12-11 4:55 AM
Hello @dvescovi
In your script , just do the following modification :
config load <filename>
generate code <path>
exit_mx
Example
config load "C:\Users\gsourigh\OneDrive - STMicroelectronics\Desktop\Thread\testcodegen\DCC_tester.ioc"
generate code "C:\Users\gsourigh\OneDrive - STMicroelectronics\Desktop\Thread\testcodegen"
exit_mx
Then launch the following command after cd the installation path of MX6.16.0
jre\bin\java -jar .\STM32CubeMX.exe -q "script path"
example
jre\bin\java -jar .\STM32CubeMX.exe -q "C:\Users\gsourigh\OneDrive - STMicroelectronics\Desktop\Thread\testcodegen\generatecode.txt"
As you can see , the code will be generated successfully.
THX
Ghofrane
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-12-11 11:40 AM
looks like you have cubemx installed in a different location. I have mine at:
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\STM32CubeMX.exe
which is Windows standard location for everyone.
I have ioc and script in my c:/tmp/testcodegen
generatecode.txt now looks like:
config load C:\tmp\testcodegen\DCC_tester.ioc
generate code C:\tmp\testcodegen
exit_mx
launched by cd to
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX>
then
C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX>jre\bin\java -jar .\STM32CubeMX.exe -q "C:\tmp\testcodegen\generatecode.txt"
Tried again using my correct full paths and I get some source code generated but not cmake, linker startup etc.
you can src and inc folders and files created within but NO cmake, linker, or start up files.
2025-12-11 11:50 AM
did not have quotes around path in generatecode.txt but even after adding them ... same results.
2025-12-11 11:23 PM - edited 2025-12-11 11:24 PM
Hello @dvescovi
In your script , let's try to use "project generate" instead of "generate code"
THX
Ghofrane
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.
2025-12-12 5:05 AM
2025-12-12 6:40 AM - edited 2025-12-12 6:42 AM
Hello @dvescovi
Just use "exit" instead of "exit_mx"
Please remember to mark the reply that helped you as the Best Answer so that other users can more easily find this solution.
THX
Ghofrane
To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.