cancel
Showing results for 
Search instead for 
Did you mean: 

IDE script to generate crc at post compilation process

https://stackoverflow.com/questions/24150030/storing-crc-into-an-axf-elf-file

—CHECKSUM=0-FF@100,offset=0xFFFF,algorithm=5,width=-2,polynomial=0x1021

arm-none-eabi-size "${BuildArtifactFileName}"

arm-none-eabi-objcopy -O binary "${BuildArtifactFileName}" "${BuildArtifactFileBaseName}.bin"

checksum -p ${TargetChip} -d "${BuildArtifactFileBaseName}.bin"

../util/srec_cat "${BuildArtifactFileBaseName}.bin" -binary -crop 0 0x3FFFC -fill 0xFF 0x00000 0x3FFFC -crc32-b-e 0x3FFFC -o "${BuildArtifactFileBaseName}.crc.bin" -binary

echo ""

echo "CRC32:"

../util/srec_cat "${BuildArtifactFileBaseName}.crc.bin" -binary -crop 0x3FFFC 0x40000 -o - -hex-dump

similar to above mentioned

I required to embed CRC32 into the .bin file or .hex file generated during compilation process .

does the GCC compiler or the IDE system workbench based on eclipse has any inbuilt compiler libraries that generate CRC during compilation and embed it in the .hex or .bin file .

9 REPLIES 9

Surely can't be that hard to add a CRC to a binary file, even if you had to code a small app to do file IO, demonstrated it before using STM32 HW CRC32​ algorithm.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

srecord used in the above example "knows" the STM32 CRC32 checksum, see srecord manual.

JW

Ethan HUANG
ST Employee

I'm afraid that there is no "inbuild compiler libraries that generate CRC during compilation and embed it in the .hex or .bin file". I made an example based on srecord in the following link:

https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/tree/master/hands-on/06_F746-DISCO-CRC

Key messages in the README.md:

  1. External tool srecord is used.
  2. Because of an bug of sequence between post-build and elf generation in early version (v1.0.0), I used a batch file (checksum.bat) to workaround it. This bug had been fixed from v1.0.2 so a more straightforward approach could be used as shown in the attached PDF.

Sorry that I'm lazy of making complete document to cover those steps in CubeIDE v1.1.0, so please refer to two separate material (README in Github and attached PDF). Hope these help.

Thanks for providing the step by step guide , and this works to generate the required 32bit CRC for the file .

I Modified to generate .bin CRC as we required .bin

# srec cat command file: srec crc dump_to_file.txt _ _ _ 

#Input File 

Companion_Upgradable_BootLoader.bin -Binary 

#CRC Algorithm at given address 

-STM32 0x0009F800 

#Produce output 

-o Companion_Upgradable_BootLoader_output.bin -Binary 

The CRC generator configuration also I have gone through the following documents and it works

http://srecord.sourceforge.net/man/man1/srec_cat.html

http://srecord.sourceforge.net/srecord-1.64.pdf

They mention

The CRC used is documented in “RM0041, STM32F100xx reference manual�?, page 46, chapter

“CRC Calculation Unit�?, which can be found at

http://www.st.com/internet/mcu/product/216844.jsp

CRC main features

• Uses CRC-32 (Ethernet) polynomial: 0x4C11DB7

– X32 + X26 + X23 + X22 + X16 + X12 + X11 + X10 +X8 + X7 + X5 + X4 + X2+ X + 1

• Single input/output 32-bit data register

• CRC computation done in 4 AHB clock cycles (HCLK)

• General-purpose 8-bit register (can be used for temporary storage)

Hello ,

I tried to generate the CRC for .binary file but I did not succeed in getting a proper CRC . Can you help me by providing any example project template for the same .

MStra.3
Associate III

I realize that this is a 2 year old thread, but I am needing the same thing - want to add CRC-32 to the end of the Binary file generated by the STM32CubeIDE. Has anyone come up with a nice (automatic) solution?

Mike.

BareMetalExpert
Associate III

Hi ,

We are following the process from last 24 months to generate 32-Bit CRC , Though It is long and Cumbersome process to generate 32-Bit CRC of the compilation completed and Linking completed .bin file .

TI Code composer studio gives a better CRC generation method embedded into the IDE itself but not any of the STM tools provide this .

We are using this method of generating .bin file CRC POST-BUILD COMPLETION process.

The output file is .bin file with no 0x00's at the end of the file this will cause to generate wrong crc make all the unused ending characters are filled with 0xFF in the linker script and use the following method mentioned by Ethan Huang.

Also follow below my reply in this thread to get more details of how to generate 32-Bit CRC for a Binary file .

Ethan HUANG (ST Employee)

2 years ago

I'm afraid that there is no "inbuild compiler libraries that generate CRC during compilation and embed it in the .hex or .bin file". I made an example based on srecord in the following link:

https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/tree/master/hands-on/06_F746-DISCO-CRC

Key messages in the README.md:

  1. External tool srecord is used.
  2. Because of an bug of sequence between post-build and elf generation in early version (v1.0.0), I used a batch file (checksum.bat) to workaround it. This bug had been fixed from v1.0.2 so a more straightforward approach could be used as shown in the attached PDF.

Sorry that I'm lazy of making complete document to cover those steps in CubeIDE v1.1.0, so please refer to two separate material (README in Github and attached PDF). Hope these help.

Like

Reply

  •  

kalvacherla.chandrashekhar (Community Member)

2 years ago

Actions for this Feed Item Comment

Thanks for providing the step by step guide , and this works to generate the required 32bit CRC for the file .

I Modified to generate .bin CRC as we required .bin

# srec cat command file: srec crc dump_to_file.txt _ _ _ 

#Input File 

Companion_Upgradable_BootLoader.bin -Binary 

#CRC Algorithm at given address 

-STM32 0x0009F800 

#Produce output 

-o Companion_Upgradable_BootLoader_output.bin -Binary 

The CRC generator configuration also I have gone through the following documents and it works

http://srecord.sourceforge.net/man/man1/srec_cat.html

http://srecord.sourceforge.net/srecord-1.64.pdf

They mention

The CRC used is documented in “RM0041, STM32F100xx reference manual�?, page 46, chapter

“CRC Calculation Unit�?, which can be found at

http://www.st.com/internet/mcu/product/216844.jsp

CRC main features

• Uses CRC-32 (Ethernet) polynomial: 0x4C11DB7

– X32 + X26 + X23 + X22 + X16 + X12 + X11 + X10 +X8 + X7 + X5 + X4 + X2+ X + 1

• Single input/output 32-bit data register

• CRC computation done in 4 AHB clock cycles (HCLK)

• General-purpose 8-bit register (can be used for temporary storage)

Alex Golubev
Associate II

Hello.

Tell me how can I download the firmware with the checksum in debug mode via stm32cubeide?

I don't have the "user file" field where I could write the path to the firmware with the checksum.0693W00000JM9x7QAD.png

BareMetalExpert
Associate III

Hi ,

Please follow Steps 7 through STEP 11 to download an HEX file add new line with file and only download the .hex file and for .elf file do not download but "Load Symbols"

https://github.com/ethanhuanginst/STM32CubeIDE-Workshop-2019/tree/master/hands-on/06_F746-DISCO-CRC

Thanks and Regards