SLAU358Q September 2011 – October 2019
The checksum (CS) that is displayed on the side of the code file name is used for internal verification. The CS is calculated as the 32-bit arithmetic sum of the 16-bit unsigned words in the code file, without considering the flash memory size or location. If any portion of the code file specifies only one byte instead of a 16-bit word, the missing byte is defined as 0xFF for the CS calculation.
The following formula is used.
DWORD CS;
DWORD XL, XH;
CS = 0;
for( addr = 0; addr < ADDR_MAX; addr = addr + 2 )
{
if(( valid_code[ addr ] ) || ( valid_code[ addr+1 ]))
{
if( valid_code[ addr ] )
XL = (DWORD) code[ addr ];
else
XL = 0xFF;
if( valid_code[ addr+1 ] )
XH = ((DWORD) code[ addr+1 ])<<8;
else
XH = 0xFF00;
CS = CS + XH + XL;
}
}
As an example, refer to the code file below, which is in the TI hex file (*.txt format).
----------------------------------------
@FC00
F2 40
@FC90
28 02 68 92 DB 3B 38 80 05 00 58
@FFFC
4E F9 B6 FA
q
----------------------------------------
The CS is calculated as shown below:
CS = 0x40F2 + 0x0228 + 0x9268 + 0x3BDB + 0x8038 + 0x0005 + 0xFF58 = 0x000290F2