cancel
Showing results for 
Search instead for 
Did you mean: 

How to customize a STM32CubeIDE code generator for my board?

HTD
Senior III

It's been quite a while since I started to work on various MCUs with STM32CubeIDE.

As it was quite magical at the start, now I roughly understand how a project is configured, especially what files are needed for what, where are they located, how they are compiled, linked and downloaded to the device.

What I don't know and I'm very curious about almost from the start is: how the IDE knows how to configure the files in the project, what include directories does it need, how to perform actual code generation by setting macros depending on the settings made in IOC file.

I'm interested in it because of it just fails miserably very, very often. The parts that commonly fail are:

  • link generation (links are not generated properly on configuration change)
  • Include directories update (I change FreeRTOS CMSIS from V2 to V1, the include paths are still set to V2)
  • Copying necessary firmware / middleware files (rarely I had to get them from GitHub and add manually).

When this happens, I got a special gift of `mx.scratch` file, a XML where I see what should I change manually in order for the project to work. Roughly.

Also, generated projects often have invalid paths (or links) to IOC file, debug configurations, external loaders and so on.

I learned to fix all those issues and it takes less and less time for me to do so, but well, the next time I change something in IOC or generate a new project - I repeat the same fixes over and over again. I wonder if I can get my hands on some configuration scripts to actually fix the issues permanently. Like to make my own modified code generation template that applies changes not only correctly, but let's say, even differently, I would gladly customize it to change the include directory order, change the directory structure and so on.

Where is this information located? Is it all in IOC file, or is it also somewhere else?

2 REPLIES 2
Pavel A.
Evangelist III

You can customize the Cube project with .extSettings file. This file can be dropped in the project directory before creating new .ioc.  Please see the CubeMX user manual (UM1718), 6.4.

Cube packages for new STM32s already come with examples of these.

Next, if you feel adventurous, look at software packs: UM2739.

Neat. I see I already have .extSettings file in my project, it seems like it adds some include directories and project files. I checked UM2739 and I learned I can create my own software pack, like middleware or a driver. Seems very complicated at first, but to just pack some files without dependencies is simple.

Still, whenever I change something in my IOC file - the code generation fails to touch project files and include directories. Luckily it modifies files like various `*conf.h`. I suspect it fails to modify the project because I customized it. I was fed up with links to individual files, so I replaced them with links to folders.

I tried to copy my existing project's IOC file to an empty directory, launch it with CubeMX and generate code to see what would happen. Not much happened, I ended up with almost empty project. My guess it just generated bare MCU startup without any custom code. I could probably add my files starting from there.

BTW, can I download an original project for a generic board that is available in STM32CubeIDE? I mean to have the project source with the ".pack" file to modify it with STM32PackageCreator?

I recently started a cooperation with ST partner, I have some HMI boards from them to test. I found a lot of bugs in the published projects, I fixed them for myself so I could test the boards, but I'd like to contribute and fix the original package so it would just work after creating a new project.

I mean it looks like this: I create a new project with TouchGFX Designer. It doesn't work in Designer, because it's missing an external loader path. It doesn't work in STM32CubeIDE, because many various paths and names are invalid and require manual changes to the correct locations. After fixing all this I end up with an empty project that can be built and uploaded to the device. Now I would like to implement the changes I made into the software pack that created the empty project for the board.