cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX code generation from command line

dvescovi
Senior

I would like to automate code generation of my .ioc file using CubeMX from command line or PowerShell.

AI says its possible with the -q (quiet mode) option but it does not seem to work.

14 REPLIES 14
Souhaib MAZHOUD
ST Employee

Hello @dvescovi 

Yes, as stated in UM1718 "3.3.2 Running STM32CubeMX in command-line mode" you can run STM32CubeMX in command-line mode without UI:

– On Windows:
cd <STM32CubeMX installation path>
jre\bin\java -jar STM32CubeMX.exe –q <script filename>
– On Linux and macOS:
./STM32CubeMX –q <script filename


 

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.

Andrew Neil
Super User

@dvescovi wrote:

AI says its possible with the -q (quiet mode) option but it does not seem to work.


What version are you using?

Please show the command you actually used, and the results you got.

 

How to write your question to maximize your chances to find a solution

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.
dvescovi
Senior

can you show me what a powershell script would look like if I have CubeMX installed at:

C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX

and my .ioc at:

C:\GitHub\STM32\debug\tester\test.ioc

I tried:

# Path to CubeMX executable
$CubeMX = "C:\Program Files\STMicroelectronics\STM32Cube\STM32CubeMX\STM32CubeMX.exe"

# Path to your .ioc project file
$Project = "C:\GitHub\STM32\debug\tester\test.ioc"

# Run CubeMX in quiet mode (-q) to generate code without opening the GUI
Start-Process -FilePath $CubeMX -ArgumentList "-q `"$Project`"" -Wait

but I know that is wrong ...

Show me formatted correctly


@dvescovi wrote:

but I know that is wrong ...


So, again, what response do you get when you run that command?

 


@dvescovi wrote:

Show me formatted correctly


Did you try what @Souhaib MAZHOUD already showed you:

 


@Souhaib MAZHOUD wrote:

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

If that doesn't work for you, show what result you get.

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.

I suggest you actually try it before offering it as a solution.

Here is what I get:

dvescovi_0-1765279585768.png

Dumps a lot of *** ... opens the CubeMX IDE ... which I do not want ... does nothing no code generated!

 

So I tried to launch in interactive mode copying the line from UM1718

I get:

dvescovi_0-1765282716809.png

Tried several variations assuming it was the CR/LF in copy/paste causing problems ... sill cannot get it right.

So next I tried launching a simple script. ...

I know the .ioc file at C:\GitHub\STM32\debug\DCC_tester\DCC_tester.ioc is perfectly valid as I can just click on it in Windows Explorer and CubeMX launches and loads it just fine.

I created a simple script named CubeMXGenerateCode.txt with the following two line:

config load "C:\GitHub\STM32\debug\DCC_tester\DCC_tester.ioc"
exit

I placed it in the same folder as my other project and .ioc files.

Tried to launch it with:

dvescovi_0-1765284229047.png

I get:

dvescovi_1-1765284321040.png

dump window:

 

dvescovi_2-1765284371114.png

 

??

 

Hello @dvescovi 

It seems that your IOC is corrupted or you tried to open it with a non-compatible version. Could you attach your ioc to investigate the problem?
Otherwise, to generate code you should add a line in your script as bellow:
generate code <path>

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.

Duh .. as I stated before "I know the .ioc file at C:\GitHub\STM32\debug\DCC_tester\DCC_tester.ioc is perfectly valid as I can just click on it in Windows Explorer and CubeMX launches and loads it just fine."