Some customers want to generate CRC checksum during compile project, while the GUN tool chain in MCUXpresso IDE doesn’t include CRC checksum calculation function, so we need the help of CRC checksum tools. In this article, use SRecord.
About detail theoretical knowledge of SRecord, please refer to
https://mcuoneclipse.com/2015/04/26/crc-checksum-generation-with-srecord-tools-for-gnu-and-eclipse/
In this thread, mainly describe the steps about how to generate CRC checksum with MCUXpresso IDE post-build, through a hands on.
Environment:
LPC54S018 chip
MCUXpresso IDE
SRecord tool
(http://srecord.sourceforge.net/)
Purpose:
Generate and place CRC checksum to 0x10000170 of LPC54s018 after compile project.
In image header for LPC540xx devices, the offset 0x10 is crc_value, in LPC54s018 , the address is 0x10000170. so we need save CRC checksum value in this place.
Steps:
Can check from S19 file:
When choose no CRC computation (no defined “ ADD_CRC “ symbol), the data in address 0x0164 bit0 is 1,
When choose compute CRC, the data in address 0x0164 bit0 is 0,
After download, srec_cat.exe is the main program we used.
(About detail commands, please refer to SRecord Reference Manual.)
# srec_cat command file to add the CRC and produce application file to be flashed
# Usage: srec_cat @filename
#first: create CRC checksum
lpcxpresso54s018m_led_blinky.srec # input file
-fill 0xFF 0x10000180 0x10010000 # fill code area with 0xff
-crop 0x10000180 0x10010000 # just keep code area for CRC
calculation below (CRC will be at 0x1FFFE..0x1FFFF)
-CRC16_Big_Endian 0x10000170 -CCITT # calculate big endian CCITT
CRC16 at given address.
-crop 0x10000170 0x10000172 # keep the CRC itself
#second: add application file
lpcxpresso54s018m_led_blinky.srec # input file
-fill 0xFF 0x10000180 0x10010000 # fill code area with 0xff
-crop 0x10000000 0x10000170 0x10000172 0x10010000 #keep all except CRC
#finally, produce the output file
-Output # produce output
lpcxpresso54s018m_led_blinky_crc.srec
arm-none-eabi-objcopy -v -O srec "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.srec" & srec_cat.exe @CRC_add.txt
7) Build project, the .srec with CRC checksum file will under Debug folder:
Pay attention:
For the format of image header of LPC540xx devices, we need enable compute CRC and put the CRC value in the specific address. while for other chips, maybe do not need enable, and also can place it in your own address.
Reference:
https://mcuoneclipse.com/2015/04/26/crc-checksum-generation-with-srecord-tools-for-gnu-and-eclipse/