1、问题背景:如何保证发布出去的bin文件是最终测试通过的版本?
2. 如何获取时间:__DATA__ , __ TIME__
// Example of __DATE__ string: "Dec 27 2017"
// Example of __TIME__ string: "15:06:19"
const char *BuildInfo = "Version: " VERSION " " __DATE__ " " __TIME__;
unsigned int mk_Build_Date(void)
{
int year = 0, month = 0, day = 0;
int hour = 0, minute = 0, seconds = 0;
char m[4] = {0};
sscanf(__DATE__, "%3s %2d %4d", m, &day, &year);
for (month = 0; month < 12; month++)
{
if (strcmp(m, short_char_months[month]) == 0)
{
break;
}
}
sscanf(__TIME__, "%2d:%2d:%2d", &hour, &minute, &seconds);
#ifdef SHORT_DATA_CHAR__
printf("[null] ** Build at:\t%04u-%02u-%02us %02u:%02u:%02u\n",
year, month, day,
hour, minute,seconds);
#else
printf("[null] ** Build at:\t%04u-%02u-%02u %02u:%02u:%02u\n",
year, month, day,
hour, minute,seconds);
#endif
DEBUG("buildDate: %s %s\n", __DATE__, __TIME__);
return 0;
}
3. 如何保证时间每次编译都更新:使用预编译指令,每次更新包含时间宏的文件或对应的链接文件。
https://www.iar.com/support/tech-notes/ide/build-actions-pre-build-and-post-build/
cmd /c "touch /cygdrive/d/test.c"
Cygwin touch command
You can enter "cygwin-application.exe" on the pre- and post-build command lines, if the environment variable PATH includes the directory where the "cygwin-application.exe" is located.
You can run the Cygwin command "touch" on the pre-build command line, but if you add a file path, for example "touch d:/test.c", the file path is not accepted by Cygwin.
Cygwin expects the POSIX path /cygdrive/d/test.c so the resulting command line would be "touch /cygdrive/d/test.c", however this command cannot be executed directly on the pre- and post-build command. Instead you have to run indirectly using:
cmd /c "touch /cygdrive/d/test.c"
The .bat file (located in project directory) alternative would look like:
Pre-build command line:
$PROJ_DIR$\pre-build.bat
File pre-build.bat:
touch /cygdrive/d/test.c
An alternative to the "touch" command is to have a pre-build action that deletes the object file, for example the Pre-build command line:
cmd /c "del "$OBJ_DIR$\test.o""
https://stackoverflow.com/questions/11697820/how-to-use-date-and-time-predefined-macros-in-as-two-integers-then-stri
PS:在SMT32的HEX文件里加入固件版本信息
//------------------------------------------------------------------------------
#include <absacc.h>
//------------------------------------------------------------------------------
#define VERINFO_ADDR_BASE (0x8009F00) // 版本信息在FLASH中的存放地址
const char Hardware_Ver[] __attribute__((at(VERINFO_ADDR_BASE + 0x00))) = "Hardware: 1.0.0";
const char Firmware_Ver[] __attribute__((at(VERINFO_ADDR_BASE + 0x20))) = "Firmware: 1.0.0";
const char Compiler_Date[] __attribute__((at(VERINFO_ADDR_BASE + 0x40))) = "Date: "__DATE__;
const char Compiler_Time[] __attribute__((at(VERINFO_ADDR_BASE + 0x60))) = "Time: "__TIME__;
//------------------------------------------------------------------------------