10. Check Sum Options

10.1 Default Checksum and PSA Calculation Used to Verify Flash Programming

 

The Main GUI has three values for check sum (CS) calculation for programming purposes (Figure 10.1). These values are always calculated and the type of checksum algorithm cannot be changed. These are the Source, Code, and Memory values.

  • The first, Source value, is calculated on the input code file contents that fit within the MCU's memory space.

  • The second, Code value, is calculated based on SetupMemory Options settings. If the Memory Options include the entire code file then the Source and Code values should be identical. The only exception to that is if the user configures serialization in Serialization→Serialization Setup, or custom CS in Setup→Check Sum Options (not related to programming) to be stored in a location occupied by data from the code file. Overlapping words are excluded for purposes of CS calculation and verification. For example, a constantly changing serialization number saved within code contents will not affect the Code and Memory CS values.

  • Lastly, the third, Memory value, is calculated based on MCU memory contents. The PSA for both code and memory contents is also calculated, but is not shown in the GUI. Both the Code and Memory CS and PSA values must match for verification to pass.

The checksum displayed in the Main GUI is the arithmetic sum of the code contents. Arithmetic sum is calculated as the sum of 16-bit unsigned words - result is 32-bit unsigned. Only programmed words are taken for calculation. All other not used words are ignored. All bytes are converted to 16-bits words using Little-Endian byte order when read:

//data[] is a byte array of MCU memory contents, pseudo code omits showing cast of data[] to unsigned short for brevity unsigned short word = data[address] + (data[address + 1] << 8)

where address is even and incremented by 2. The PSA value is also calculated on words. Odd byte boundaries in the code file are filled in with default MCU empty values (0xFF or 0x00 depending on MCU family).

Figure 10.1: Check Sum information compared between the file and MCU memory.

10.2 Custom Checksum Setup for Verification by User Code on Boot

Custom Checksums can be generated and programmed by the flasher to be used by user firmware for code verification on boot. Up to four different CS blocks can be specified and CS results can be saved in the flash for verification. Size of each CS block and CS result location in flash are defined by the user.
The Check Sum Options dialog (Figure 10.2) is selected from following pull down menu:
Setup→Checksum Options

There are several items of note:

  • Start Address should be even, and the Stop Address should be odd. This is because data at both addresses is used inclusively.

  • CS result address in the flash should be even. Make sure that the CS result is saved outside of the code block being counted, otherwise the CS result will modify the contents of the code block itself and further verification will fail.

  • The CS result is displayed in the report window shown in Figure 10.3.

  • The type of algorithm used to calculated the CS can be selected from the following list shown in Figure 10.4. Initial value for CS calculation can be selected as zero, all 0xFFs or as the Start Address from pull down menu shown in Figure 10.5.

  • CS result can be used As Is or can be inverted as shown in Figure 10.6.

  • Data size (byte or 16 bits word) used for calculation and CS result size is displayed in the dialog screen as “Data IN word size” and “CS Result size” (Figure 10.2). Polynomial contents (if required) can be specified in the POLY edit line in HEX format ( eg. 0x1234 ).

Figure 10.2: Check Sum Options.

Figure 10.3: Check Sum Report.

Figure 10.4: Check Sum Type

.

Figure 10.5: Check Sum Initial Value.

Figure 10.6: Check Sum Inverted Option.


The following checksum algorithms are implemented (as shown in Figure 10.4).

10.2.1 Arithmetic Sum (8b/16b)


Checksum is calculated as modulo 16-bits sum of all bytes (unsigned) from Start Address to the End Address as follows:

unsigned int CS = CS_initial_value; for ( addr = StartAddress; addr <= EndAddress; addr++ ) { CS = CS + data[addr]; } CS = 0xFFFF & CS; if( cs_inverted ) CS = 0xFFFF ^ CS;

10.2.2 Arithmetic Sum (8b/32b)


Checksum is calculated as modulo 32-bits sum of all bytes (unsigned) from Start Address to the End Address as follows:

unsigned int CS = CS_initial_value; for ( addr = StartAddress; addr <= EndAddress; addr++ ) { CS = CS + data[addr]; } CS = 0xFFFFFFFF & CS; if( cs_inverted ) CS = 0xFFFFFFFF ^ CS;

10.2.3 Arithmetic Sum (16b/16b)


Checksum is calculated as modulo 16-bits sum of all 2-byte words (unsigned) from Start Address to the End Address as follows:

10.2.4 Arithmetic Sum (16b/32b)


Checksum is calculated as modulo 32-bits sum of all 2-byte words (unsigned) from Start Address to the End Address as follows:

10.2.5 CRC16 (Poly 0x11201) - (8b/16b) (Named as CRCCCITT) and CRC16 defined polynomial - (8b/16b)


Checksum is calculated as CRC16 from each bytes from Start Address to the End Address as follows:

where:

The CRC table is generated first as follows:
CS_init_crc16_tab( 0x1021 ); for CRC CCITT
CS_init_crc16_tab( CRC_def_POLY ); for CRC16 defined polynomial
where:

10.2.6 CRC32 (Poly 0x04C11DB7) - (8b/32b) (Named as IEEE 802-3) and CRC32 defined polynomial - (8b/32b)


Checksum is calculated as CRC32 from each bytes from Start Address to the End Address as follows:

where:

The CRC table is generated first as follows:
CS_init_crc32_tab( 0x04C11DB7 ) for IEEE 802-3
a polynomial of:
x32 + x26 + x23 + x22 + x16 + x12 + x11 + x10 + x8 + x7 + x5 + x4 + x2 + x + 1
and
CS_init_crc32_tab( CRC_def_POLY ) for CRC32 defined polynomial
where: