checksum in hex file/editing hex file manually

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable
        I want my PSoC to be able to perform a crc of its own program space. To do this, I plan to calculate the crc in advance and save it in the last couple of bytes in the hex file before loading the code. Doing this seems to cause some sort of verification in the hex file to fail. Is there a checksum somewhere in the hex file that I can recalculate and edit myself?   
0 Likes
5 Replies
stshc_297956
Level 1
Level 1
        whn you say hex, do you mean hex display of 'binary' or do you mean hex20, where ASCII is used to represent hex records.   
0 Likes
Anonymous
Not applicable
        I mean the hex display of binary.   
0 Likes
Anonymous
Not applicable
        Check out AN2026. In the appendix of this app note, there is a description of the format of the hex file. There is a record called Checksum record, which stores the checksum of all the flash data. During programming, this stored checksum is compared with the checksum calculated on the flash data. So, if you want to change the last two bytes of the flash data, you need to calculate the checksum of the flash and update this checksum record in the hex file for the programming to pass.   
   
Best Regards,   
Ganesh   
0 Likes
Anonymous
Not applicable
        Can anyone tell me how to start writing program since i m beginner.   
please send me some sample program that may help me to write program using assembly as well as using C.   
0 Likes
pala_3991556
Level 1
Level 1

To check program memory means you want to confirm whether the CRC of program Flash in hex file is same as CRC of p-flash after downloading/ flashing hex into controller.

In this way you are checking the physical memory is damaged or not.

Things you need to do is.

Write down your own routine to calculate CRC of p flash with an algorithm (CRC-16 or CRC-32).

Calculate CRC of hex file using srec tool using same algorithm (CRC-16 or CRC-32).

Append CRC at particular address in hex file. (You can place calculated CRC at unused p flash area )

Now at run time your own routine will calculate CRC of p flash. You should have added a logic to compare calculated CRC with stored CRC at particular address.

Refer below link for reference.

Hex file CRC calculation using Srecord tool :
https://embdsysbasics.blogspot.com/2018/12/hex-file-checksum-calculator-using.html?m=1

0 Likes