cancel
Showing results for 
Search instead for 
Did you mean: 

Running STM32CubeMX without GUI

ANath.1
Associate III

Hi All,
I am trying to setup a build pipeline for the STM32 platform to be able to compile projects in an automated fashion. So far, I have an .ioc file which I use the to generate the project using the STM32CubeMX commands which are invoked via the script in the cli mode. The flow works on an Ubuntu machine which supports GUI. However, when I try to containerize the flow into a docker container, the build breaks as the STM32CubeMX tries to render a progress bar for the Loading IOC step followed by a Rendering UI progress bar. It is not possible to load display components on the docker and hence STM32CubeMX code generation fails. Is there any way to launch STM32CubeMX in a headless non-gui mode so that we can run this on headless machines?

ANath1_0-1717562433830.png

This is the UI that pops up.
The following is the contents of my script file

config load <filename>.ioc
project name app
project toolchain STM32CubeIDE
project path <path>
SetCopyLibrary copy all
SetStructure Advanced
project generate
exit

 Command to invoke STM32CubeMX:

java -jar <path_to_CubeMX>/STM32CubeMX -q <scriptfile>

Thanks,

Abhijit Nathwani

15 REPLIES 15

@BarryWhit wrote:

Not to mention, you could customize the templates CubeMX uses to generate the code in the first place.

This is interesting, I've not see reference to this before. Can you point me at how you would do this?

 


@BarryWhit wrote:

So yeah, everything can be worked around, Like you said, What I don't understand is what about the current (admittedly wonky) situation is preventing you from doing any of the things you described. It's just the wonkiness itself that's not great right?


Indeed, there are multiple ways to achieve my end goal. The workarounds that you and others have provided are sufficient for that. To that end I'm not tearing my hair out over this. It's a nice to have and I'm trying to raise awareness of why it would be useful. I am not really expecting it to happen any time soon, but if nobody raised awareness / complained about this it would never get fixed.

 


@BarryWhit wrote:

As an aside, are you aware that ST has a project going centered around providing a parallel development flow using VSCode? I'm not sure how the code generation is worked in (maybe it isn't), but you should have a look - There's a thread about it around here somewhere.


I'll look it up, thanks.

Andrew

Pavel A.
Evangelist III

 but if nobody raised awareness / complained about this it would never get fixed.

This was my point... Nobody raised awareness - because almost nobody (outside ST at least) runs CubeMX in CI environment. Those who do are cut off by Occam blade ))

 


@Pavel A. wrote:

 but if nobody raised awareness / complained about this it would never get fixed.

This was my point... Nobody raised awareness - because almost nobody (outside ST at least) runs CubeMX in CI environment. Those who do are cut off by Occam blade ))


While searching for how to resolve my issues with this I found a handful of posts from over the last 4 or 5 years asking this same question. It's not exactly a hot topic, but it is something that multiple people have asked for, including both OP and myself this month. Then how many others haven't bothered to create an account and post because they found one of those older threads and decided the workarounds were good enough, if a bit wonky.

 

Hi @BarryWhit 
The main reason to raise a concern is because the behavior of the CubeMX tool contradicts the user manual (UM1718). 

ANath1_0-1719393785102.png

It explicitly says to run CubeMX "without UI", use this command. However, the said command pops-up a window which is not expected. 


There's also the issue where if something goes wrong during batch-mode generation, you get a GUI message box and user interaction is required instead of cube exiting with an error code - which is not cool (and andrew said as much in the other thread).

I agree, the tool should exit gracefully with error codes instead of popping up windows when invoked in non-GUI mode. Hopefully the issues are resolved soon 🙂 We can always try !

Thanks,

Abhijit

@BarryWhit wrote:

Not to mention, you could customize the templates CubeMX uses to generate the code in the first place.

This is interesting, I've not see reference to this before. Can you point me at how you would do this?

I've not seen any official docs about it, but I haven't really looked either.

 

If you look in CubeMX GUI under the Project Manager/Code Generator/Template Settings,  you'll see some   things configurables that suggest ST made some consideration for the case of users using custom templates.

 

CubeMX uses the Apache FreeMarker Java Template Engine. The template files are quite dense, but it's not impossible to figure out if you're motivated.  The default location for template files (just text files) is:

STM32CubeIDE\plugins\com.st.stm32cube.common.mx_6.10.0.202311202037\db

 

There are also a handful of user-created CubeMX packs out there which integrate with CubeMX and its code-generator, so it has been done. One example I've used is I-CUBE-USBD-COMPOSITE , which lets you create composite devices with the ST USB Device library for example. Find it on github.

 

UPDATE: If you think about it, the .ioc file must be primarily the context object for the template engine. In theory, you could take the ioc, and the template files bundled with your version, and create an independent CLI java project based on Apache FreeMarker that would generate byte-for-byte the same output. But this seems like a rabbit hole.

 

Also note that you have the option of generating .c/.h file per peripheral instead of the default, which may (or may not) make your life easier with the post-generation patch flow you said you favored.

 

> if nobody raised awareness / complained about this it would never get fixed.

 

fair. But also possible that a few people ask for it and it would never get fixed. No harm in trying though.

 

It just seems that you're asking for a major time investment by ST for relatively little gain by either ST or their customers, so it'd be hard to justify for them. This is precisely because the current situation does do the job, it's just clunky. It's always an uphill struggle to make a business case for investing resources in replacing something that works, with something that works but is also pretty. Even if the ST team member that responds shares your aesthetics and accepts your arguments, they have to sell the required resource investment to their boss - and they probably can't, because it already works kinda.

Asking them to open-source the code-generation plugin component of CubeMX so you, and the group of highly committed hardcore super-developers which you can prove you represent , can take it from there - that'd be a far more attractive ask IMO.

 

- If you feel a post has answered your question, please click "Accept as Solution".
- Once you've solved your issue, please consider posting a summary with any additional details you've learned. Your new knowledge may help others in the future.
BarryWhit
Senior

Late Update:

UM1718: Custom code generation 

 

(I really should google before I claim there are no docs)

 

- If you feel a post has answered your question, please click "Accept as Solution".
- Once you've solved your issue, please consider posting a summary with any additional details you've learned. Your new knowledge may help others in the future.