Skip to main content
BCoch
Senior
Mar 5, 2019 12:00 AM UTC
Solved

How to load flash from .hex file using built-in bootloader. Specifically, where to write the start address?

If loading the on-chip flash from a .hex file, the Write Memory command can be used to write the hex file data records. However, what should done with the start address? Where does that get written? (Assumming an STM32G0, in my case.)

This topic has been closed for replies.
MPatt.11
MPatt.11Best answer
Associate II
Mar 5, 2019 1:33 AM UTC

In the HEX files I've used, I've never run across an 05 record. The stack pointer is the first 4 bytes, and the starting address is the next 4 bytes of the data that you are downloading. (Remember, little endian format). Therefore the 05 record wouldn't need to be used.

5 replies

MPatt.11
Associate II
Mar 5, 2019 12:14 AM UTC

I think you are asking about the start address in flash where the bootloader should start writing the data. The start address is contained in the Intel HEX file. The first line of the HEX file is a type 04 record, which is the extended linear starting address. The type 00 (data) records contain the lower bits of the address. I have found this article on Wikipedia useful in learning how to decode Intel HEX files.

https://en.wikipedia.org/wiki/Intel_HEX

BCoch
BCochAuthor
Senior
Mar 5, 2019 12:37 AM UTC

Thanks for the answer. Indeed I found the same Wikipedia article very helpful. I do read and process the type 04 record, using it to modify the type 00 record addresses.

However, my question is regarding the 05 record, which provides the application starting address. Does this also need to be written to a location in flash, or is it already taken care of by the vectors that are presumably part of the rest of the data?

Tesla DeLorean
Guru
Mar 5, 2019 2:03 AM UTC

It is a historic parameter used by debuggers. Here I'd expect it to point to the Reset_Handler where it could place a breakpoint.

​

With. HEX files the address of the data is inferred directly, unlike a .BIN which is just a blob of data.​

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
MPatt.11
MPatt.11Best answer
Associate II
Mar 5, 2019 1:33 AM UTC

In the HEX files I've used, I've never run across an 05 record. The stack pointer is the first 4 bytes, and the starting address is the next 4 bytes of the data that you are downloading. (Remember, little endian format). Therefore the 05 record wouldn't need to be used.

BCoch
BCochAuthor
Senior
Mar 5, 2019 4:58 PM UTC

Ah yes, thanks. I see the same address as the second 4 bytes.