English
Language : 

PIC32MX795F512L-80IPT Datasheet, PDF (47/68 Pages) Microchip Technology – PIC32 Flash Programming Specification
PIC32
The formula to calculate the checksum for a PIC32
device is provided in Equation 17-1.
EQUATION 17-1: CHECKSUM FORMULA
Checksum = 2s complement PF + BF + DCR + DIR
Where,
PF = 32-bit summation of all bytes in Program Flash
BF = 32-bit summation of all bytes in boot Flash, except device Configuration registers
3
DCR =  32-bit summation of bytes MASKDEVCFGX & DEVCFGx
X=0
DIR = 32-bit summation of bytes MASKDEVID & DEVID
MASKDEVCFGX = mask value from Table 17-1
MASKDEVID = mask value from Table 17-1
17.4 Example of Checksum Calculation
The following five sections demonstrate a checksum
calculation for the PIC32MX360F512L device using
Equation 17-1.
The following assumptions are made for the purpose of
this checksum calculation example:
• Program Flash and boot Flash are in the erased
state (all bytes are 0xFF)
• Device Configuration is in the default state of the
device (no configuration changes are made)
To begin, each item on the right-hand side of the equa-
tion (PF, BF, DCR, DIR) is individually calculated. After
those values have been derived, the final value of the
checksum can be determined.
17.4.1 CALCULATING FOR “PF” IN THE
CHECKSUM FORMULA
The size of Program Flash is 512 KB, which equals
524288 bytes. Since the program Flash is assumed to
be in erased state, the value of “PF” is resolved through
the following calculation:
PF = 0xFF + 0xFF + … 524288 times
PF = 0x7F80000 (32-bit number)
17.4.2 CALCULATING FOR “BF” IN THE
CHECKSUM FORMULA
The size of the boot Flash is 12 KB, which equals
12288 bytes. However, the last 16 bytes are device
Configuration registers, which are treated separately.
Therefore, the number of bytes in boot Flash that we
consider in this step is 12272. Since the boot Flash is
assumed to be in erased state, the value of “BF” is
resolved through the following calculation:
BF = 0xFF + 0xFF + … 12272 times
BF = 0x002FC010 (32-bit number)
17.4.3 CALCULATING FOR “DCR” IN THE
CHECKSUM FORMULA
Since the device Configuration registers are left in their
default state, the value of the appropriate DEVCFG
register – as read by the PIC32 core, its respective
mask value, the value derived from applying the mask,
and the 32-bit summation of bytes (all as shown in
Table 17-2) provide the total of the 32-bit summation of
bytes.
From Table 17-2, the value of “DCR” is:
DCR = 0x000003D6 (32-bit number)
TABLE 17-2: DCR CALCULATION EXAMPLE
Register
POR Default Value
Mask
POR Default Value & 32-Bit Summation of
Mask
Bytes
DEVCFG0
DEVCFG1
0x7FFFFFFF
0xFFFFFFFF
0x110FF00B
0x009FF7A7
0x110FF00B
0x009FF7A7
0x0000011B
0x0000023D
DEVCFG2
DEVCFG3
0xFFFFFFFF
0xFFFFFFFF
0x00070077
0x00070077
0x00000000
0x00000000
Total of the 32-bit Summation of Bytes =
0x0000007E
0x00000000
0x000003D6
 2007-2013 Microchip Technology Inc.
DS61145L-page 47