cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CUBEIDE how to add a custom pre & post scripts

Javier1
Principal

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 

we dont need to firmware by ourselves, lets talk
1 ACCEPTED SOLUTION

Accepted Solutions
Javier1
Principal

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 

we dont need to firmware by ourselves, lets talk

View solution in original post

5 REPLIES 5
TDK
Guru

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.
Evangelist III

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

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

we dont need to firmware by ourselves, lets talk

I found the answer online:

No script tough, just the command i needed to create the git header

git log --pretty=format:'#define GIT_INFO_PRESENT%n static const char* GIT_INFO = "Version Information=[%H,%d]\r\n";' -n 1 > ../Core/Inc/gitcommit.h

we dont need to firmware by ourselves, lets talk
Javier1
Principal

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 

we dont need to firmware by ourselves, lets talk