Adding crc32 in the last 4 bytes of flash

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello everyone,,

I'm trying to understand if is possible to add crc32 in the last 4 bytes of my program.

Now I have modified my project options adding the "srec_cat" in the post build command line and this work fine but in this way I can add the CRC32 only in bin, intel etc, but when start a debug session the debugger load my program without the last 4 bytes.
Can someone help me to understand where I'm wrong ?

Thanks in advance.

Last Edited: Tue. Feb 4, 2020 - 03:46 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Been there, done that, worn the T-shirt...

 

https://github.com/wrightflyer/sdbootloader

 

In:

 

https://github.com/wrightflyer/sdbootloader/blob/master/main.c#L355

 

you can see the correct implementation in code to reconstruct the same CRC16LE that srec_cat generates. Of course this is only 16 bit little endian. It might be sufficient for your needs or perhaps you really do need CRC32? If the latter hope you find it easier to work out what the decode is than I found it working out the 16bit LE one. The "trick" was that I missed the fact that it uses an augmented CRC. That is why there is:

    // augment
    crc = updcrc(0, updcrc(0, crc));

which feeds in another two 0x00 bytes at the very end of the process. Took me ages to realise that this was needed for the srec_cat CRC to match!!

 

For the record (as my notes on the bootloader say) I invoke srec_cat as:

srec_cat $(MSBuildProjectDirectory)\$(Configuration)\$(Output File Name).hex -intel -fill 0xFF 0x0000 0x37FE --l-e-crc16 0x37FE -o AVRAP001.bin -binary

so this particular example is for a 16K (mega16) micro and it fills the unused space from the end of the app code to the byte before the CRC with 0xFF (that is "-fill 0xFF 0x0000 0x37FE") and then it performs the 16 bit little endian CRC over the entire 0xFF padded data and then writes the CRC one to the end at 0x37FE/37FF with "--l-e-crc16 0x37FE"

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Tue. Feb 4, 2020 - 03:31 PM
Topic locked