EW targets: | ARM, RH850, RX, SH, STM8 |
EW component: | General issues |
Last update: | September 6, 2013 |
Below follows the steps needed to set up an CRC16 checksum calcuation, both in the EW-tool-chain and in the application.
This note applies to...
...these versions of the following Embedded Workbenches products:
EWARM 5.11 (and later) - - - EWRX 2.10 (and later)
EWSH 2.10 (and later) - - - EWSTM8 1.10 (and later)
• | The minimum requirement is that your source uses the symbol __checksum. |
• | Note: If your source doesn't use the symbol __checksum you will get an error message from IELFTOOL: "The string '__checksum' was not found in the string table". |
• | To be able to link anyway, you can turn on Project > Options... > Linker > Extra Options > mark "Use command line options" and add the command line option "--keep __checksum". |
Checksum calculation in the application
The supplied example(s) shows how to use the CRC16 checksum calculation. In the C source of the application you need to add the actual generic C source to calculate the same checksum value as EWARM calculates. There are two variants of the calculation:
• | Fast -- Short execution time, but it uses up more ROM/flash for a constant table. |
• | Slow -- It uses less ROM/flash but more execution time. |
Please note:
• | The checksum calculation must not (in order to work) be made over the bytes where the checksum is placed in memory. One solution is to place the checksum at the beginning or end of memory. So the bytes (1, 2 or 4) where the checksum is saved must be excluded from the checksum calculation. |
• | If the slow function is used, you must make a final call to the checksum calculation with the same number of bytes, with value 0x00, as you have bytes (1, 2 or 4) in the checksum. See the 'Example (1 range, 3 diff. locations)' project for details. (Use the link to the upper right.) |
You can use these options either in the Embedded Workbench or on the command line. If using command line the command should first run the linker, then run the IELFTOOL.
In the EW you set up calculation of the checksum in menu Project > Options > Linker > Checksum options tab.
The options used in the (place first) example are:
Fill unused code memory
Fill pattern 0xFF (can be any pattern)
Start address 0x0 (adjust to your application)
End address 0xFFFB (adjust to your application)
Generate checksum; size = 2 bytes; CRC16; Complement = as is; Bit order = MSB first; initial value = 0.
The corresponding command line is:
ielftool --fill 0xFF;0x0-0xfffb --checksum __checksum:2,crc16,0x0;0x0-0xfffb
There are 2 requirements that you have to fulfill to make this work. - See the next 2 parts of the tech note.
• | Select the address range to be checksummed. |
• | Select where the chacksum will be placed. |
The checksum should (normally) cover all non-RAM bytes of the application,excluding the bytes where the checksum is placed.
The way to get knowledge about this is to turn on
• | menu Project > Options... > Linker > Checksum > mark "Fill unused code memory" and mark "Generate checksum" |
• | menu Project > Options... > Linker > List > mark "Generate linker map file" |
• | menu Tools > Options... > Messages > Show build messages > All |
• | Add usage of the symbol __checksum in your application. |
• | Perform one build. |
• | Then look in the .map file to see where the symbol __checksum is placed. |
• | Look in the "Build Window" to see the memory range that will be used in the checksum calculation. |
This is done in the .icf file. The following example will place it at the end of memory.
Add this in the .icf file.
place at end of ROM_region { ro section .checksum };
In the 'Example (1 range, 3 diff. locations)', configuration 'PlaceEndOfROM' , the start address is 0x0 and the end address is 0xFFFB.
Please Note: There are several other solutions on how/where to place the checksum in memory. - These solutions are presented in the Tech Note 62709.
All product names are trademarks or registered trademarks of their respective owners.