Showing results for 
Search instead for 
Did you mean: 

How to write .Bin /.ELF file for External Flash loader

Associate II

I have a project with a large number of image bitmaps I want to draw to a screen, so have set up an external FLASH IC for storing the majority of these images.

I've verified my flash driver works and created an external loader for use in STM32CubeProgrammer. I've verified that this loader can read and erase sections of the external flash after I get the microcontroller to write to the flash, so now all I need to do is save the images to the flash from the CubeProgrammer but I'm unsure on what the best route to do this is.

I understand CubeProgrammer accepts .Bin and .Elf files to program to the uC/flash but how do I create a .Bin/.Elf file with just images in them at specified memory addresses?

Thank you for any help


Got a working understanding of STDIO file functions?

How do propose communicating the files and addresses?

The .ELF format is well documented and in use for many decades. You could use this object file format to describe multiple sections, one for each image describing the address and size, and position within the file itself.

Personally I think writing a packaging tool might be simpler than using the linker.

You could create a .S assembler file and use .INCBIN, use the linker and linker script to generate a .ELF

A .HEX might be simpler to pull-off, as you can just dump out each file in a hexadecimal format, with the address attribute you want, and the address space can be sparse.

For a .BIN you have to make a large linear image, big enough to hold all of the files, with the gaps/spacing or address offsets you want. Allocate this large region, chose your pad-fill byte (0xFF or 0x00, or whatever), then enumerate through your file list, offsetting into this buffer, and once done write the whole buffer to a new, singular, .BIN file

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

To program any binary file (bmp, gif...)  with the CubeProgrammer: first, determine the sector size of your external flash. Choose the start address aligned on the sector size. Then rename your file to .bin, click "open file" in Cube Programmer, type the start address in and click DOWNLOAD.

To choose external loaders click on "EL" button at the left bottom side.