Skip to main content
Visitor II
June 9, 2022
Solved

How to write plain intel hex to flash?

  • June 9, 2022
  • 5 replies
  • 6786 views

Hi,

I would like to copy the exact contents of a hex file to the flash memory of my f446 nucleo, complete with byte count, address info ....

Is there any way to do this? Using ST-Link I can only find options to actually flash the hex file or manually alter single hex addresses.

Thanks!

    This topic has been closed for replies.
    Best answer by waclawek.jan

    Concocted a simple utility for this. Convert your eo.hex file into eo_sample.hex by running

    stringify.exe eo.hex eo_sample.hex

    Usage is then

    const char * eo_sample_hex = 
     #include "eo_sample.hex"
    ;

    JW

    5 replies

    Super User
    June 9, 2022

    Tell the programmer that it's a binary file?

    It's an odd request - if you explain what you're actually trying to achieve, people might be able to give better suggestions...

    Super User
    June 9, 2022

    Treat it as a binary file.

    One way to do this is to convert it into C source, using utilities e.g. https://www.segger.com/free-utilities/bin2c/ and then use it accordingly.

    JW

    Super User
    June 9, 2022

    @Community member​ "One way to do this is to convert it into C source"

    I don't think that should be necessary?

    As far as the programmer is concerned, a "binary" file is just a sequence of arbitrary bytes - it does not interpret the values, just dumps them verbatim into the target?

    Of course, if the Hex needs to be part of a bigger application, it can easily be included as something like

    char hex_file[] = {
    ":10010000214601360121470136007EFE09D2190140\n"
    ":100110002146017E17C20001FF5F16002148011928\n"
    ":10012000194E79234623965778239EDA3F01B2CAA7\n"
    ":100130003F0156702B5E712B722B732146013421C7\n"
    ":00000001FF\n"
    };

    Super User
    June 9, 2022

    >Of course, if the Hex needs to be part of a bigger application, it can easily be included as something like

    That would require stringification per line. Doable manually, but I assumed this is to be part of an automated translation process.

    But maybe there is some appropriate tool for this. And it's trivial to write one; I just pointed out an existing tool.

    I don't intend to discuss the merits of this whole thing, it's highly context dependent.

    JW

    gfxfloroAuthor
    Visitor II
    June 9, 2022

    I would like to simulate transferring a hex file to another uC via SPI or I2C. For this I have set up 2 Nucleos. One which sends the hex file and one to receive. The master in this case needs to have the data in intel hex format.

    Super User
    June 9, 2022

    "transferring a hex file to another uC"

    This is (probably) a bad idea.

    This means that you are going to have to write an Intel Hex parser in the receiving uC - which is a non-trivial exercise with lots of pitfalls and traps for the unwary.

    Why not just transmit the binary?

    Graduate II
    June 9, 2022

    >>Why not just transmit the binary?

    Or regenerate a Motorola, Intel or Tektronix HEX file data stream on-the-fly?

    gfxfloroAuthor
    Visitor II
    June 9, 2022

    So this is an attempt at IAP. The hex file would be a new firmware.

    I figured with the hex info I'd have the destination addresses built into the file and only need to copy accordingly.

    I am not familiar with the format of a binary, how would this be possible with a binary?

    Super User
    June 9, 2022

    As noted above, a binary is just a verbatim stream of raw bytes; it doesn't really have a "format" at all - the 1st byte in the file just goes into the 1st byte of the target memory range, next byte in the file just goes into the next byte of the target memory, etc, etc...

    Of course, this means that you need to separately define where within the Target memory this should start.

    That would be handled by your bootloader.

    gfxfloroAuthor
    Visitor II
    June 9, 2022

    Thank you all for your answers, I think I will implement some form of the AN4286 protocol after all, this also leaves it up to the master to interpret the file type and it's a well documented protocol.

    Picking JWs answer as best, since this is what comes closest to be the solution for my original problem.