cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 CANBus bootloader - verification errors

Brian Rau
Associate III

Heads up about a problem we discovered, and I think solved.  We're using the built-in STM32L452 bootloader per AN3154 to do in-system firmware updates over CAN bus from an Android host.  We started with the can-prog Python utility (https://github.com/marcinbor85/can-prog), but rewrote it in Java.  The software worked fine, except for consistently failing a readback verification, which always showed a four-byte mismatch at the same location near (but not at) the end of the programmed image.

I'll skip to the solution and avoid boring you with all the trial-and-error: The can-prog utility reads the firmware to be programmed from a .hex file, and the problem occurred wherever there was a short (4 bytes) line of data in the .hex file, like these:

:1017B0006566002B2D00303000785800412D4661C1
:1017C0002D66383930313233343536375D0000001C
:0417D000C501000847
:0417D400A101000867
:1017D8001000000001000000AAAAAAAA00093D0002
:1017E800003C1C46003C1C46F401F401B81E053EB2

With assistance from ST tech support, we finally landed on the problem: The flash must be written 8 bytes at a time (this is buried in the device reference manual).  Modifying our code to always send the data in 8-byte chunks with the Write Memory command (0x31) solved the problem.

This was far from obvious, and ideally would be documented as a limitation (if not a bug) in AN3154.  Figured I'd share it to hopefully spare others from a lot of frustration.

 

1 REPLY 1

>>Modifying our code to always send the data in 8-byte chunks

Yes depends on the specific STM32 and the native flash-line widths, and ECC. So alignment of addresses, and lengths to match.

Topic that's been covered before, and creation of normalization tools for .HEX files, or BIN2HEX type things.

The hex files can be a challenge due to their sparse nature, and that lines can be split. It's probably less of an issue with ARM and the linkers outputting larger linear blocks of code/data, whereas historically the object files for older MCUs and 8-bit ones, had the linkers operate in a minimal passes mode, and interleave different sections of code, data and statics.

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