diff --git a/Makefile b/Makefile index 6cd661a..fccbfcf 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,11 @@ endif # Build global options ############################################################################## +ifeq ($(VERSION),) + #VERSION="unknown" + VERSION="$(shell git describe --tags)" +endif + ############################################################################## # Architecture or project specific options # @@ -200,7 +205,7 @@ CPPWARN = -Wall -Wextra -Wundef # # List all user C define here, like -D_DEBUG=1 -UDEFS = -DSHELL_CMD_TEST_ENABLED=FALSE -DSHELL_CMD_MEM_ENABLED=FALSE -DARM_MATH_CM0 +UDEFS = -DSHELL_CMD_TEST_ENABLED=FALSE -DSHELL_CMD_MEM_ENABLED=FALSE -DARM_MATH_CM0 -DVERSION=\"$(VERSION)\" # Define ASM defines here UADEFS = diff --git a/main.c b/main.c index 25a9f20..cbcadb4 100644 --- a/main.c +++ b/main.c @@ -1663,14 +1663,23 @@ static void cmd_stat(BaseSequentialStream *chp, int argc, char *argv[]) } +#ifndef VERSION +#define VERSION "unknown" +#endif - +static void cmd_version(BaseSequentialStream *chp, int argc, char *argv[]) +{ + (void)argc; + (void)argv; + chprintf(chp, VERSION "\r\n"); +} #define SHELL_WA_SIZE THD_WORKING_AREA_SIZE(256) static THD_WORKING_AREA(waThread2, SHELL_WA_SIZE); static const ShellCommand commands[] = { + { "version", cmd_version }, { "reset", cmd_reset }, { "freq", cmd_freq }, { "offset", cmd_offset },