on
2022-07-26
05:48 AM
- edited on
2024-01-03
09:17 AM
by
Laurids_PETERSE
Cyclic Redundancy Check (CRC) is an error detection method for digital data based on binary division.
CRC algorithm generates a fixed checksum code length.
Post build CRC are mainly used for flash integrity.
This section describes how to generate it with mainly toolchains.
IAR EWARM provides a way to generate checksum in Project--> Options:
STM32CubeIDE doesn’t have this property as IAR EWARM, an external tool is mandatory to generate a post build CRC.
Srec_cat is a tool available in SRecord utility package which is a standalone utility for memory manipulation.
Features:
Srec_cat can be used for example to generate a CRC at the end of binary file after build by calling it in your toolchain.
This utility and all information about it are available at Peter Miller’s webpage: http://srecord.sourceforge.net/.
In the download page in the “SourceForge Downloads” section, select the “1.64 release .zip file” link.
Click on it and download the SRecord 1.64 package.
The downloaded ZIP folder contains these items:
• srec_cat.exe: The srec_cat program may be used to catenate (join) EPROM load files, or portions of EPROM load files, together. Because it understands all the input and output formats, it can also be used to convert files from one format to another.
• srec_cmp.exe: The srec_cmp program may be used to compare EPROM load files, or portions of EPROM load files, for equality.
• srec_info.exe: The srec_info program may be used to print summary information about EPROM load files.
• Reference manual srecord-1.63.pdf
• Readme files
This online workshop gives the process to use srec_cat with STM32CubeIDE:
STM32CubeIDE-Workshop-2019/hands-on/06_F746-DISCO-CRC at master · ethanhuanginst/STM32CubeIDE-Workshop-2019 · GitHub
It is possible to use srec_cat in the same way with Keil MDK.
To add a CRC after build, it is necessary to enable option “After Build/Rebuild” in User tab and call Srecord commands:
.\bin\srec_cat .\Debug\OEM_Dev.hex -intel -crop 0x08000000 0x08002F02 -fill 0xFF 0x08000000 0x08002F10 -CRC16_Little_Endian 0x08002F10 -o .\Debug\OEM_Dev_CRC16.hex -intel
This command isolates section data from address 0x08000000 to 0x08002F02, fill unused datas of this sector with 0xFF, calculate CRC of the isolate section and place it at address 0x08002F10.
These operations are saved in the output hex file: OEM_Dev_CRC16.hex
You can adapt this command to your own usage.
Refer to srecord-1.63.pdf for more information about the Srecord commands.
The edited hex file generated in post-build step will be then used for programming and debugging.
Create a text file, rename it as “Initialize.ini”.
Save it in the root of the project.
Write this command to the file and save it: LOAD .\debug\ OEM_Dev_CRC16.hex INCREMENTAL
Enter this file in Debug tab:
And in “Utilities” tab: