Hello community and Nordic support.
Very briefly about my profile: I have worked with NRF52 chips in my previous company for about half a year and have a good understanding and practical experience with the ICs and SeS.
The ultimate goal I try to acheive: Program will print a header message (through UART) based on the last commit (and also uncommited changes).
My setup: nRF52840 DK (PCA10056) + Segger Embedded Studio + GIT + RNG example form SDK (15) to start with.
Description of steps made so far: I have no problem to lunch RNG example (since it contains already UART implementation thorugh NRF_LOG functions). The changes I would like to make are only in the main loop and adding 2 files to a project (version.c and version.h)
while(true){ NRF_LOG_INFO("%s\r\n", build_git_author); NRF_LOG_INFO("Build Time: %s\r\n", build_git_time); NRF_LOG_INFO("Commit: %s\r\n", build_git_sha); NRF_LOG_INFO("Status: %s\r\n", build_git_status); NRF_LOG_FLUSH(); nrf_delay_ms(1000); }
my version.h files looks like:
#ifndef VERSION_H #define VERSION_H extern const char * build_git_sha; extern const char * build_git_time; extern const char * build_git_author; extern const char * build_git_status; #endif /* VERSION_H */
And my version.c looks like:
#include "version.h" //File generated by automatically. Any manual change will be rewritten const char * build_git_sha = "1f68e9e96eab3d729a0050cf110a44f1569258a5"; const char * build_git_time = "sob, 21 lip 2018, 01:24:40 CEST"; const char * build_git_author= "Author: Pawel Krzyzanowski <[email protected]>"; const char * build_git_status= "Clean!";
And As it is written the version.c file should be generated automatically when I click 'build' button. (I have no trouble to add version.c/h files to the project).
I have this solution working in my other project where I have makefile and added few lines to this:
.PHONY: ver version.o ver: git rev-parse HEAD | awk ' BEGIN {print "#include \"version.h\"\r\n\r\n//File generated by automatically. Any manual change will be rewritten"} {print "const char * build_git_sha = \"" $$0"\";"} END {}' > version.c date | awk 'BEGIN {} {print "const char * build_git_time = \""$$0"\";"} END {} ' >> version.c git log -1 | grep Author | awk 'BEGIN {} {print "const char * build_git_author= \""$$0"\";"} END {} ' >> version.c git diff --stat | awk 'BEGIN {} {} END {if(length($0)) {print "const char * build_git_status= \""$$0"\";"} else {print "const char * build_git_status= \"Clean!\";"}} ' >> version.c version.o: version.c $(CC) $(CFLAGS) -c version.c
So each time I do 'make' command, I have my ver running, which just replace my version.c file with the data taken from my GIT (and local time) before compiling.
And my question/challange starts here:
1. How do I acheive simmilar/the same feature inside Segger Embedded Studio?
2. Maybe a Pre-Build command can be used for this (I couldn't find a description how to write a commands there)?
3. Maybe there is other alternative idea how to get data form GIT into a *.c file during building and I can use it?
Any help will be highly appreciated and I with your help I would post my soultion to my Public git repository in case someone would like to use this.