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-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";
2021-02-16 04:03 AM
Here is a nice idea requiring git only:
Instead of the makefile modification, it can be done in STMCubeIDE as a pre-build command.
hth
KnarfB
2021-02-16 04:58 AM
ill try that out and let you know.
thanks
2021-02-16 12:25 PM
This is what we have inth BMP debugger Makefile:
```
include/version.h: FORCE
$(Q)echo " GIT include/version.h"
$(Q)echo "#define FIRMWARE_VERSION \"$(shell git describe --always --dirty --tags)\"" > $@
```
2021-02-17 01:53 AM
sorry but im a bit new with the makefile structure of stm.
What (where) do you mean with BMP debugger makefile?
2021-02-17 07:18 AM
BMP is some project for a debugger. But that does not matter for your problem, it should only show the principle
2021-02-17 07:39 AM
So youre saying BMP is just the name of your project.
I didnt understand what did you mean with "it should only show the principle"
Ok im diving inside the makefiles :
I am new with makefiles and i dont really know where to stick your code snippet:
include/version.h: FORCE
$(Q)echo " GIT include/version.h"
$(Q)echo "#define FIRMWARE_VERSION \"$(shell git describe --always --dirty --tags)\"" > $@
2021-02-17 08:20 AM
When run in the example above, include/version.h contains something like '#define FIRMWARE_VERSION "v1.7.1-129-g43b79f10-dirty' Then "#include "version.h" in your code and you can access the string as FIRMWARE_VERSION.
2021-02-17 08:22 AM
and i can paste
include/version.h: FORCE
$(Q)echo " GIT include/version.h"
$(Q)echo "#define FIRMWARE_VERSION \"$(shell git describe --always --dirty --tags)\"" > $@
anywhere in my makefile?
Also i noticed the makefiles get autogenerated everytime you rebuild your project in stm32cubeIDE so they overwrite anything i add to them,how are you dealing with this?
2021-02-17 09:08 AM
I do no use CubeIDE.