In priority mode, CRCSCAN will run a single check of Flash, and the CPU will be stalled until CRCSCAN has completed. In this example, CRCSCAN is configured to run in priority mode on the entire Flash. When CRCSCAN has completed its check, the application code will check the CRC calculation status, which will be reflected by the frequency of LED0 on ATtiny817 Xplained Mini.
Initialization
In this application, all the module configurations exist in the main.c file.
main()
,
set the MODE bit fields (MODE<1:0>) in CRCSCAN CTRLB register equal to
0x0 in order to run a single CRC check where CRCSCAN has priority to Flash.
This will stall the CPU until the scan has finished.1
’ in the CRCSCAN CTRLA register to enable the CRCSCAN
peripheral with the current configurations to start a scan.Program Flow
while(1)
loop.Post-Build Command
Calculating the CRC checksum and storing it in Flash can be done by using a post-build command in Atmel Studio. Follow the instructions in CRC Checksum Setup with the following post-build command:
srec_cat "$(OutputDirectory)\$(OutputFileName).hex" -intel -crop 0 0x1FFE -fill 0xFF 0 0x1FFE -CRC16_Big_Endian 0x1FFE -broken -o "$(OutputFileName)_crc.hex" -intel -line-length=44
Testing the Application
Program the ATtiny817 by clicking Tools→Device programming→(Tool=mEDBG, Device=ATtiny817, Interface=UPDI, Apply)→ Memories →Program.
If the device is programmed with the <program_name>.hex file, the CRC check will fail since there is no CRC checksum added at the end of the Flash, and LED0 will toggle at FAIL_DELAY interval.
If the device is programmed with a <program_name>_crc.hex file, the pre-calculated checksum will be stored at the end of the 8 KB Flash address. The CRCSCAN should run through with no failure and LED0 will toggle at the OK_DELAY interval.