Skip to main content
Kmax18
Senior II
September 2, 2025
Solved

Integrating hierarchical state machines (C-code) in STM32CubeIDE projects?

  • September 2, 2025
  • 2 replies
  • 2843 views

Does anyone have experience with integrating hierarchical state machines (C-code) with a STM32CubeIDE project?

For example, the QP/C software by Quantum Leaps generates state machine C-code based on a graphical modeling tool. If the state machine diagram changes the C-code is re-generated: https://www.state-machine.com/qpc/index.html

How can this capability be integrated with the STM32CubeIDE?

  • In particular, if the state machine code is updated, how is the project source updated?
  • Also, if the STM32CubeMX files (.ioc) is updated and the project source is re-generated, how can the state machine code be protected? (I assume the IDE's USER CODE section can be used for that...)

Any feedback will be appreciated. Thank you!

Best answer by Andrew Neil

As far as CubeIDE is concerned, it's all just source files - it neither knows nor cares how those files were created.

So it's no different to files that you create manually yourself.

 

Place the files in a folder away from the CubeMX stuff to be sure that CubeMX won't mess with it.

 

PS:

for example, see:

https://community.st.com/t5/stm32cubeide-mcus/project-organisation-in-cubeide-how-to-go-about-libraries/m-p/734773/highlight/true#M31820

and:

https://community.st.com/t5/stm32cubeide-mcus/project-organisation-in-cubeide-how-to-go-about-libraries/m-p/734778/highlight/true#M31821

2 replies

Andrew Neil
Andrew NeilBest answer
Super User
September 3, 2025

As far as CubeIDE is concerned, it's all just source files - it neither knows nor cares how those files were created.

So it's no different to files that you create manually yourself.

 

Place the files in a folder away from the CubeMX stuff to be sure that CubeMX won't mess with it.

 

PS:

for example, see:

https://community.st.com/t5/stm32cubeide-mcus/project-organisation-in-cubeide-how-to-go-about-libraries/m-p/734773/highlight/true#M31820

and:

https://community.st.com/t5/stm32cubeide-mcus/project-organisation-in-cubeide-how-to-go-about-libraries/m-p/734778/highlight/true#M31821

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.
Kmax18
Kmax18Author
Senior II
September 4, 2025

Thank you, @Andrew Neil ! Your articles are very helpful.

Pavel A.
Super User
September 3, 2025

@Kmax18 IMHO your question basically is: how to integrate Cube-generated code with your own code and/or code generated by other tools.

As @Andrew Neil wrote, there are BKMs for that. Unfortunate glitches in the Cube re-regeneration may happen, so keep your valuable code protected by version control.

 

Kmax18
Kmax18Author
Senior II
September 4, 2025

Thank you @Pavel A., much appreciated. ("BKM" is Best Known Method, right?) 

Pavel A.
Super User
September 4, 2025

Correct!