cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMX Code generator creates no region for user function implementation

k.cheung
Associate

So I have used STM32CubeIDE to setup a custom BLE service. This creates the files custom_stm.c and custom_stm.h.

So now I need to add my own public functions to custom_stm. I add functions into the USER CODE BEGIN EF, USER CODE END EF region of custom_stm.h, so far so good.

I then look into custom_stm.c to implement these functions, and find that there's just no USER CODE region available to implement these public functions. So I guess I just can't do that?

I don't understand the intended workflow of this IDE. Why not generate self-contained modules instead of half user-source, half generated files with 50000 undocumented regions I need to figure out and hook onto if I want any control over my project structure.

The .ioc should go in SCM, I should then be able to neatly ignore the output of that file which is essentially a compiler output and #include it's functionality from my own application. 

I have been considering deleting the .ioc now and taking ownership of the generated code, deleting the user blocks etc. But I wanted to see if there was something I was missing about this workflow. As far as I can tell I now literally don't have a choice because the generator will delete the code I need to add to proceed

 

3 REPLIES 3
Johi
Senior III

Have you considered adding your implementation in your own .c and .h files and put your own code there?

Then include your own headers in the automatically generated ones.

You can of course work without the MX part, but certainly for prototyping it has its advantages.

I have considered this, however I don't like the idea of the code-generator dictating my project structure to that degree, which is on me. 

I'm probably going to switch to using HAL and documented libraries, and treat CubeMX as an example generator instead of a dependency.

It would be nice if there were settings to make it's output produce files intended for you to use in a project structure you design and maintain, rather than it being more oriented towards generating a full project and getting the user to fill in the blanks, which works well for getting something working quick, but is limiting in terms of making a readable, modular project.

Pavel A.
Evangelist III

 I don't like the idea of the code-generator dictating my project structure to that degree, which is on me. 

This is even better! Create your code structure as you like it; copy only relevant snippets from the cube-generated code. Keep the .ioc in your SCM, as it contains important details on the MCU configuration.

>I'm probably going to switch to using HAL and documented libraries, and treat CubeMX as an example generator instead of a dependency.

Exactly this.

> It would be nice if there were settings to make it's output produce files intended for you to use in a project structure you design and maintain

There already are user templates and configuration files - but why to invest in learning these obscure details if we can just write our code in a conventional way.

However, the trend is that we'll see more AI coding assistance in the near future. Part of it likely will come from Microsoft, Github, Eclipse CDT and so on.