cancel
Showing results for 
Search instead for 
Did you mean: 

A solution to adding CRC32 to the end of the Binary file after build

MStra.3
Associate III

I spend a lot of time looking and never could find an easy way to do this. I came up with a solution and thought I would post it.

I am using the STM32F407. The F4 series only has one way of calculating the CRC in hardware and that is what I chose to use in the Binary file. This way, the F4 can easily verify a file when it is uploaded to it for a firmware update.

I have attached a Zip file with an EXE in it called CRC32. It requires one parameter - the name of the file to add a CRC32 to. It assumes the file size will be a multiple of 4 bytes. It then reads the file and calculates the CRC. When it reaches the EOF it inverts the CRC and appends it to the end of the file. This way when the whole file with added CRC32 is CRC'd again on upload, the result should be 0xFFFFFFFF. If CRC32 is run on the same file multiple times, it will continue to add CRC32's to it - probably not what you want, but if you make this automatically run each time you build, that should never happen.

You can make this run automatically after your build by adding a command in the Post-build steps: Project Properies >> C/C++ Build >> Settings >> Build Steps:

"<path to crc32>\crc32" "${PWD}\${ProjName}.bin"

The quotes are necessary because of possible blanks in the path and to correctly get the filename to add the CRC to.

Mike.

3 REPLIES 3
HHa.1
Associate

hi @MStra.3​ , may you share the source code of crc32 tool?

MStra.3
Associate III

I found the code in the public domain and modified the File I/O slightly to add the CRC to the file.

Mike.