Skip to main content
Javier1
Principal
June 2, 2021
Solved

STM32CUBEIDE how to add a custom pre & post scripts

  • June 2, 2021
  • 5 replies
  • 9164 views

From an Idea discussion with @Pavel A.​ https://community.st.com/s/ideazone#0873W000000blKWQAY

StCubeMX should enable your programm to know its own code version.

via the autogenerated linker script or any way .

Related with my old question https://community.st.com/s/question/0D53W00000ZVSgbSAH/git-commit-hash-flashed-along-with-my-code

@Pavel A.​ >In CubeIDE projects you can add a custom pre & post scripts where all this can be easily done.

@Javier Muñoz​ >Where can i find more information?

All system scripting and behind the scenes of cubeIDE is obscure wizardry to me.

So ...i still dont know :(

0693W00000BZrZhQAL.png 

This topic has been closed for replies.
Best answer by Javier1

What ended up working for me: (im using windows STMCUBE IDE 1.5.1)

I struggled with the directories, aparently the build directory is the folder /Debug or /Release but i want to place my script in root project directory so i cd ..;

cd ..;./prebuildJaviscript.sh

0693W00000BaHH0QAN.png 

The script was placed here:

0693W00000BaHI8QAN.png 

Containing;

#!/bin/sh
echo "this is the pre-build script!:D"
 
#variables from git log https://devhints.io/git-log-format
git log --pretty=format:'#define GIT_INFO_PRESENT%n static const char* GIT_INFO = "Commit=%h,CommitDate=%at,CommitSubject=%s";' -n 1 > Core/Inc/gitcommit.h

And the cript creates this:

0693W00000BaHJVQA3.png 

5 replies

TDK
June 2, 2021

Right click project -> Properties -> C/C++ Build -> Settings -> Build Steps.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Pavel A.
June 2, 2021

There's even more reasons to celebrate these scripts. CubeIDE comes with GNU shell (sh) and some GNU tools. You can write portable shell scripts that work both on Windows and Linux. Enough mediocre batch files.

Eclipse variables such as  ${BuildArtifactFileName} can be passed to the script as parameters.

--pa

Javier1
Javier1Author
Principal
June 3, 2021

That sounds fantastic @Pavel A.​ !0693W00000BaFIGQA3.png Im very new in this area, so what is Command expecting from me?

In what languaje should i write the socalled "commands"? shell script?

if i add ./myscript.sh it doesnt find my script and i have no idea where is looking for it. 

If i add echo "the PWD is : ${pwd}"

0693W00000BaFROQA3.png

hit me up in https://www.linkedin.com/in/javiermuñoz/
Javier1
Javier1AuthorBest answer
Principal
June 7, 2021

What ended up working for me: (im using windows STMCUBE IDE 1.5.1)

I struggled with the directories, aparently the build directory is the folder /Debug or /Release but i want to place my script in root project directory so i cd ..;

cd ..;./prebuildJaviscript.sh

0693W00000BaHH0QAN.png 

The script was placed here:

0693W00000BaHI8QAN.png 

Containing;

#!/bin/sh
echo "this is the pre-build script!:D"
 
#variables from git log https://devhints.io/git-log-format
git log --pretty=format:'#define GIT_INFO_PRESENT%n static const char* GIT_INFO = "Commit=%h,CommitDate=%at,CommitSubject=%s";' -n 1 > Core/Inc/gitcommit.h

And the cript creates this:

0693W00000BaHJVQA3.png 

hit me up in https://www.linkedin.com/in/javiermuñoz/