38.3.2.3 Checksum

The pre-calculated checksum must be present at the end of the section to be scanned. The checksum must be stored in the last bytes of the BOOT section to check the BOOT section and similarly for the APPCODE and APPDATA sections. The checksum for CRC32 has opposite endianness compared to CRC16. Table 1-2 and Table 1-3 show explicitly how to store the checksum for the different sections. For additional information on partitioning the Flash section. Refer to the Configuration of Scan Region section.

Table 38-2. Placement of the Pre-Calculated Checksum for CRC16 in Flash
Section to CheckCHECKSUM[15:8]CHECKSUM[7:0]
BOOTBOOTEND - 1BOOTEND
APPCODEAPPEND - 1APPEND
APPDATAFLASHEND - 1FLASHEND
Table 38-3. Placement of the Pre-Calculated Checksum for CRC32 in Flash
Section to CheckCHECKSUM[7:0]CHECKSUM[15:8]CHECKSUM[23:16]CHECKSUM[31:24]
BOOTBOOTEND - 3BOOTEND - 2BOOTEND - 1BOOTEND
APPCODEAPPEND - 3APPEND - 2APPEND - 1APPEND
APPDATAFLASHEND - 3FLASHEND - 2FLASHEND - 1FLASHEND

Defining the Pre-Calculated Checksum

The pre-calculated checksum can be determined by using a CRC algorithm and the parameters specified in Table 1-4. The calculation should start at the region start and end at the address before the pre-calculated checksum’s placement. Manual mode can be used to compare the checksum at the end of a region with known data, ensuring correctly configured calculation.

Table 38-4. Parameters for Checksum Calculation
CRC SelectedPolynomialInitial ValueWidthXOR Value
CRC160x10210xFFFF2N/A
CRC320x4C11DB70xFFFF_FFFF40xFFFF_FFFF

For more information on Checksum calculation and use, refer to the Hexmate section in the MPLAB® XC8 C Compiler User’s Guide for PIC® MCU document.