cancel
Showing results for 
Search instead for 
Did you mean: 

Git Commit Hash flashed along with my code?

Javier1
Principal

Howdy everyone.

I need my MCU to be selfaware of what FW version is currently flashed,

so far im just manually typing the git commit hash inside a const string every time i change the FW version.

0693W000008GHL5QAO.pngIt looks to me like a feature that should be supported somewhere but i couldnt find a thing.

Is there a way to automate this process?

cheers

we dont need to firmware by ourselves, lets talk
11 REPLIES 11

okay im giving this a try:

So first im looking where to add Pre-Build commands

project>properties>C/C++ build0693W000008GW1UQAW.pngShould i replace there the build command for:

version.h: git log -n 1 --format=format:"#define GIT_COMMIT \"%h\"%n" HEAD > $@; make -j8

If i do i get some path errors, the ide is not finding version.h.

I tried adding the core/Inc folder to the path but no luck, i think my problem is somewhere else.

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

I found how:

From this post https://stackoverflow.com/questions/44038428/include-git-commit-hash-and-or-branch-name-in-c-c-source

I added the following command inside Pre-build steps:

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

0693W00000BaGGpQAN.png 

Creates the following content inside gitcommit.h

#define GIT_INFO_PRESENT
 static const char* GIT_INFO = "Version Information=[abc493ac20blablablae94a692e68, (HEAD -> master, origin/master, origin/HEAD)]\r\n";

we dont need to firmware by ourselves, lets talk