一、我用过的
软件版本一般是用空定义,记录内部版本、外部版本;
日期、时间:printf("CompileDate: %s %s\r\n",__DATE__,__TIME__);
二、指定存储区域(Flash)中写入软件版本信息
#define VERINFO_ADDR_BASE (0x0800FF00) //存放FLASH的地址
const char Software_Ver[] __attribute__((at(VERINFO_ADDR_BASE + 0x00))) = "Software: 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__;
attribute,翻译为“属性”,在C语言中,是一个关键字,语法格式为:__attribute__ ((attribute-list))
__attribute__ 可以设置函数属性(Function Attribute )、变量属性(Variable Attribute )和类型属性(Type Attribute )。