2021-02-16 03:23 AM
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.
It 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
Solved! Go to Solution.
2021-02-18 12:05 AM
okay im giving this a try:
So first im looking where to add Pre-Build commands
project>properties>C/C++ buildShould 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.
2021-06-07 02:44 AM
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
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";