18.3 Algorithm
Figure 18-1 illustrates an example of a high-level algorithm for calculating the checksum for a PIC32 device to demonstrate one method to derive a checksum. This is merely an example of how to achieve the actual calculations, the method that is ultimately used is left to the discretion of the software developer.
As stated earlier, calculate the PIC32 checksum as the 32-bit summation of all bytes (8-bit quantities) in program Flash, Boot Flash (except device configuration words), the Device ID register with applicable mask, and the device configuration words with applicable masks.
Then, the 2’s complement of the summation is calculated. This final 32-bit number is presented as the checksum.
The mask values of the device Configuration and Device ID registers are derived as described in the previous section, Mask Values.
An arithmetic AND operation of these device Configuration register values is performed with the appropriate mask value, before adding their bytes to the checksum.
Similarly, an arithmetic AND operation of the Device ID register is performed with the appropriate mask value, before adding its bytes to the checksum, see Configuration Memory and Device ID for more information.
Equation 18-1 provides a formula to calculate the checksum for a PIC32 device.
-
For the PIC32MZ family of devices, the Boot Flash memory that resides at 0x1FCxFF00 through 0x1FCxFFFF is not summed, as these memory locations contain the device configuration and CP values. For the PIC32MKXXXXGPD/GPE/MCFXXX family of devices, the Boot Flash memory that resides at 0x1FC03F00 through 0x1FC03FFF is not summed.
-
For the PIC32MZ and the PIC32MKXXXXGPD/GPE/MCFXXX family of devices, the checksum calculated in MPLAB X IDE only uses the primary DEVCFGx registers. Neither the alternate nor second Boot Flash (if available) registers are calculated.