Some Tips on Adding Version Number of SCM

2023-04-13

Share this article :

Usually we write a program, usually note the software version, then, how to save the version information in the microcontroller?


There are many methods, but the basic principle is to write in the specified storage area (Flash).Software versionInformation.


Implementation method


Here is one of the most common and basic tips:inKeil MDKUnder the environment, through software code, directly mapped to and stored to the Flash specified address.

Include: software version, compile date, compile time ,Here's the code:





# define  VERINFO_ADDR_BASE   (0x0800FF00) / / The address where the flash is stored
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__;

Can anyone understand this code?
The principle is simple, and there are similar ways to write Flash addresses (not described here).

This contains several important knowledge points, which are described below.

Key words _ _ attribute _ _ _


Attribute, translated as "attribute," in C, is a keyword with the grammatical form of :

__attribute__ ((attribute-  list  ))

_ _ attribute _ _ Function attribute, variable attribute, and type attribute can be set.

This part of the content, we can do not have to understand in depth, know that this can be used. To understand deeply, there are also a lot of learning resources on the Internet.

C language standard definition


In the code:


const char Compiler_Date[] __attribute__((at(VERINFO_ADDR_BASE +  0x40  ))) =  "Date: "  __DATE__;const char Compiler_Time[] __attribute__((at(VERINFO_ADDR_BASE +  0x60  ))) =  "Time: "  __TIME__;

You will see_ _ DATE _ _ andThe date and time represented by _ _ TIME _ _.

In fact, these two are special standard definitions of C language.
__DATE__: Compile the date character string of the moment as in "Apr13 2021"
__TIME__Compile time character string as "20: 00: 00"

In addition to these two, there are actually many similar standard definitions, such as:
__FILE__ : The file name of the file being compiled
__LINE__ : The line number of the file being compiled
__STDC__: Determine if the document is standard C procedure

You can see this in my article:Definition and Usage of Several Special Standards of C Language

Always compile version files


In the Keil MDK, by default, the source file is not modified and is compiled only once.

Therefore, to compile the version, date, and time correctly, you need to set this: Always compile .

Set as follows:
图片

Firmware size


The generated Hex file will fill in the unused Falsh with 0x00, for example:
图片

After padding 0x00, the hex is relatively large, so there are two ways to reduce the hex firmware size.

1. Store FLASH address, to set in the appropriate location, if the amount of code is only 1K, you only in the offset 50K address, so too much offset.

#  define   VERINFO_ADDR_BASE   (0x0800FF00) / / The address where the flash is stored

2. There is also a way online to modify the "ROM size":
图片

After the small, I found that I really removed 0x00:
图片

These two methods, in fact, have a certain risk, if the amount of code is increasing, there may be problems. So, we have to set the main flash address.

Hot items in stock

MJW21195
CDCLVD1212RHAR
AD8224BCPZ
S912ZVCA19F0MLFR
MCIMX6U1AVM08ADR
XCVU7P-2FLVB2104
LTC6244HVCMS8#PBF
SN65DSI84TPAPRQ1
STM32F334C6T7
ADS1299IPAGR
NRVBS360T3G
PCF85176T/1
R5F363AMDFB#30
PIC12F510-I
MICRF211AYQS
DS21458N
XC2238N40F80LRABKXUMA1
TLE9879QXA40
AD534JHZ
MICRF211AYQS
PIC12F635-I/SN
PIC12F510-I/SN
MAX267BENG
UCC2806DW
EPM7128STC100-10N
MIC5233-3.3YM5-TR
ATA5781-WNQW-VAO
PIC16LF1559T-I/SS
LTC1387CG
IRG4PC50UDPBF
PIC18F67K40-I/MR
NH82580DBSLH5U
AD5422ACPZ-REEL
TMS320F28377SPTPS
TPS54260DGQR
APT30D120BG
TLE4286G
TPS6281120QWRWYRQ1
STM32F429IET6
STM32G070RBT6
TLE9877QXW40
STM32F743IIT6
SIR871DP-T1-GE3
SI7625DN-T1-GE3
SI7129DN-T1-GE3
SI7101DN-T1-GE3
STM32H743IGT6
AD8139ARDZ
PIC12LF1840-I/SN
ATXMEGA64A3U-AUR
MAX3222EEWN+T
MC34PF3000A2EP
XC7K325T-FFG900
STM32F429IGH6
AD215BY
PIC24HJ128GP202-I/MM
UCC28C45DGKR
MC9S08PA8AVTG
PTV05010WAH
STM32L071CBT6
TPS53353DQPR
SAK-C167CS-L40M CA
KSZ8895RQXI-TR
TPS6208812YFPT
S912ZVC12F0MLF
TMS320F28066PZT
DS2502P-E48+
XCVU13P-L2FHGC2104E
ATMEGA640-16CU
TPS53353DQPR
ICL7665SACBA
LT3502EMS#PBF
PIC18F45K20-E/PT
STM32F427IGT6
HGTG18N120BND
AM3505AZCN
STD18N55M5
MCIMX6U1AVM08ADR
TCAN1145DRQ1
OPA277UG4 
DP83822IRHBR
MAX3232ECDWR 
DPS310
VNV35N07TR-E
STM32L151VCH6
QCC3020-0-CSP90-TR-00-0 
LT3517EUF#TRPBF
VND810PTR-E
SAK-TC1796-256F150E
HUF75545S3ST  
TLC2274AIPWR
SAK-TC277TP-64F200S DC

#Intel
#Symantec
#AdvancedMicroDevices
#Microsoft
#NVIDIA
#Samsung
#TexasInstruments
#Qualcomm
#Huawei
#TSMC
#NXP
#Freescale
#Broadcom
#AnalogDevices
#MicronTechnology
#STMicroelectronics
#Sony
#Toshiba
#SMIC
#RenesasElectronics
#MOSFET #PowerIC #IntergratedCircuits #LogicChip #Memory #MCU

------------ END ------------