2.10 CRC Checksum Setup
The CRCSCAN peripheral expects a two byte CRC checksum to be located at the end of the area selected for scanning. This means that a CRC checksum needs to be calculated and added to the end of the flash image before the application is programmed to the device.
The tool srec_input can be used to generate the checksum and add it to the hex file. This is done in Atmel Studio, by adding a post-build command for the project. The end result will be a hex file which contains the application code and the CRC checksum. The hex file will be padded with 0xFF to match the size of the device. To add the post-build command, do the following steps:
- Open the project properties by clicking Project → <project_name> Properties.
- Add a post-build command to the project under Build Events → Post-build event command line, as shown in the figure below.
- Rebuild the project by clicking Build → Rebuild <project_name>.
The command to add is:
srec_cat "$(OutputDirectory)\$(OutputFileName).hex" -intel -crop 0 0x7FFE -fill 0xFF 0 0x7FFE -CRC16_Big_Endian 0x7FFE -broken -o "$(OutputFileName)_crc.hex" -intel -line-length=44