...
9.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 109.1). These values are always calculated and the type of checksum algorithm cannot be changed. These are the Source, Code, and Memory values.
...
Anchor |
---|
| _Toc452148563 |
---|
| _Toc452148563 |
---|
|
Figure 109.1: Check Sum information compared between the file and MCU memory. Anchor |
---|
| _Toc452148509 |
---|
| _Toc452148509 |
---|
|
...
9.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 109.2) is selected from following pull down menu:
Setup→ChecksumOptions
...
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 109.3.
The type of algorithm used to calculated the CS can be selected from the following list shown in Figure 109.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 109.5.
CS result can be used As Is or can be inverted as shown in Figure 109.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 109.2). Polynomial contents (if required) can be specified in the POLY edit line in HEX format ( eg. 0x1234 ).
...
Anchor |
---|
| _Toc452148564 |
---|
| _Toc452148564 |
---|
|
Figure 109.2: Check Sum Options. Anchor |
---|
| _Toc452148565 |
---|
| _Toc452148565 |
---|
|
Figure 109.3: Check Sum Report. Anchor |
---|
| _Toc452148566 |
---|
| _Toc452148566 |
---|
|
Figure 109.4: Check Sum Type.
Anchor |
---|
| _Toc452148567 |
---|
| _Toc452148567 |
---|
|
Figure 109.5: Check Sum Initial Value....
Anchor |
---|
| _Toc452148568 |
---|
| _Toc452148568 |
---|
|
Figure 109.6: Check Sum Inverted Option.
The following checksum algorithms are implemented (as shown in Figure 109.4).
Anchor |
---|
| _Toc452148510 |
---|
| _Toc452148510 |
---|
|
...
9.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:
Code Block |
---|
|
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; |
Anchor |
---|
| _Toc452148511 |
---|
| _Toc452148511 |
---|
|
...
9.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:
Code Block |
---|
|
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; |
Anchor |
---|
| _Toc452148512 |
---|
| _Toc452148512 |
---|
|
...
9.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:
Code Block |
---|
|
unsigned int CS = CS_initial_value;
for ( addr = StartAddress; addr <= EndAddress; addr=addr+2 )
{
CS = CS + data[addr] + data[addr+1];
}
CS = 0xFFFF & CS;
if( cs_inverted )
CS = 0xFFFF ^ CS; |
Anchor |
---|
| _Toc452148513 |
---|
| _Toc452148513 |
---|
|
...
9.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:
Code Block |
---|
|
unsigned int CS = CS_initial_value;
for ( addr = StartAddress; addr <= EndAddress; addr=addr+2 )
{
CS = CS + data[addr] + data[addr+1];
}
CS = 0xFFFFFFFF & CS;
if( cs_inverted )
CS = 0xFFFFFFFF ^ CS; |
Anchor |
---|
| _Toc452148514 |
---|
| _Toc452148514 |
---|
|
...
9.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:
...
Code Block |
---|
|
void CS_init_crc16_tab( unsigned short poly )
{
int i, j;
unsigned short crc, c;
for (i=0; i<256; i++)
{
crc = 0;
c = ((unsigned short) i) << 8;
for (j=0; j<8; j++)
{
if ( (crc ^ c) & 0x8000 )
crc = ( crc << 1 ) ^ poly;
else
crc = crc << 1;
c = c << 1;
}
crc_tab32[i] = (unsigned int)(0xFFFF & crc);
}
} |
Anchor |
---|
| _Toc452148515 |
---|
| _Toc452148515 |
---|
|
...
9.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:
...