4.4 Checksum Configuration and Setup
Out of the box, all project configurations except develop_no_cksm
are
set up to use the Hexmate utility included with the XC8 compiler to insert a checksum
into the hex file. The Hexmate command is added to the post-build steps (click Project
Configuration, then click Building) and is shown below.
"hexmate" ${ImagePath} -o${ImagePath} -FILL=0xFFFF@0x0000:0xFFFB
-CK=0x0000-0xFFFB@0xFFFC+0xFFFFFFFFw-4g-5p0x04C11DB7o0xFFFFFFFF
Let’s break down this command. The first parameter specifies the input to Hexmate, while the second specifies the output file. Then, the “-FILL” command is used to fill any unused memory with a known value. Filling the unused memory is required for proper calculation of the checksum.
The checksum portion of the command is interpreted as the following:
0x0000-0xFFFB@0xFFFC
defines the memory range the checksum is computed over (0x0000 to 0xFFFB) and where it is stored (0xFFFC).+0xFFFFFFFF
sets the initial value of the checksumw-4
defines the output with a length of four bytes with little-endian orderingg-5
specifies this is a CRC operation, per the Hexmate user manualp0x04C11DB7
is the polynomial of the CRCo0xFFFFFFFF
XORs the final result by this number