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:

  1. Open the project properties by clicking Project → <project_name> Properties.
  2. Add a post-build command to the project under Build Events → Post-build event command line, as shown in the figure below.
    Figure 2-16. Post-Build Command in Atmel Studio
  3. 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

Note: Take care to program the hex file with the appended CRC checksum to the device. Use the device programming dialog to program the device. The name of the file with the CRC checksum will end with _crc.hex. If the name of the project is left unchanged during creation, the filename will be ATtiny3217FunctionalSafety0_crc.hex.