Showing results for 
Search instead for 
Did you mean: 

STM32CubeMX Processing Before and After Code Generation

Associate II

STM32CubeMX release 6.9.0 contained support for processing before and after code generation. The documentation does not appear to be updated to describe how this works.

What kind of file and scripting is expected for this feature?

Associate II

Any luck with this?  I also couldn't find any documentation from STM about this feature, despite them advertising it on the home page of STM32CubeMx.

I tried making both a powershell script and a shell script that would just echo a string into a file.  When I set the After Code Generation path to either of these scripts, it caused CubeMX to freeze up and I had to kill it from the task manager.


I also really need this functionality but I find the current implementation pretty useless:

  • There seems to be no way to specify a relative path to this script (relative to the sourcecode directory). Of course I this script inside my sourcede tree and check it into my version control system together with the sourcecode.
  • Also the working directory of the script seems to be the installation directory of STM32CubeMX. And there is no environment variable or any other way to find the sourcecode directory(!) What good is this script supposed to do if it can't find or access the generated sourcecode?


Associate II

@oskar what language is your script in?


I wrote it in bash. It's on a linux laptop. 

jose luu
Associate III


If the script is within the project, begin the script with the lines below, these will set the current directory to where the script is:





set SCRIPT_DIR=%~dp0%









SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"





The *BAD* news is that the script path must be absolute on Windows (eg C:\Users...) even though is is within the project directory.

Using the Windows utility procmon.exe, I can see that when using relative path, the script is noticed but it is not executed