2020-08-31 02:08 AM
I'm using STM32CubeIDE, Settings ->Tool Settings->MCU Post build outputs-> Choose "Convert to binary file(-O binary)", I found that the generated bin file was not the right size. The elf and hex is correct.
.elf: 5902KB
.hex:2327KB
.bin: 655390KB
Obviously the bin file size is wrong.
Solved! Go to Solution.
2020-08-31 02:32 AM
Hi Lliba.1
One reason that the bin file is so big can be that the project contains code split to several memory areas. The bin file does not contain any address information so if the project is mapped to several memory areas it will become big as unused memory needs to be filled by zero in the bin file.
Please let me know if this is the case for your project.
You can disable the generation of the binary file in Project Properties. "C/C++ Build" -> Settings . In the Tool Settings tab you will find settings for "MCU Post build outputs"
2020-08-31 02:29 AM
Please note that, unlike ELF and HEX, BIN files do not contain address information, so you get a lot of empty space at the beginning of the BIN, as you can easily see with a hex editor.
In general, ELF and HEX files are more flexible, e.g. to program external memory from a single firmware file.
Good luck!
/Peter
2020-08-31 02:32 AM
Hi Lliba.1
One reason that the bin file is so big can be that the project contains code split to several memory areas. The bin file does not contain any address information so if the project is mapped to several memory areas it will become big as unused memory needs to be filled by zero in the bin file.
Please let me know if this is the case for your project.
You can disable the generation of the binary file in Project Properties. "C/C++ Build" -> Settings . In the Tool Settings tab you will find settings for "MCU Post build outputs"
2020-08-31 02:57 AM
Thanks.
2020-08-31 03:01 AM
Thanks. Make sure it's for that reason. For STM32, isn't the actual code it runs in bin format? If I want to upgrade STM32 programe from UART, but the generated bin file is the wrong size, so what should I do?
2020-08-31 03:12 AM
You will be able to upgrade the STM32 program from UART using Intel hex file or Motorola srecord file using the bootloader. Both Intel and Motorola format contains the binary program with detailed address information. You can probably investigate how to use STM32CubeProgrammer to download code using UART.
2020-08-31 03:32 AM
Thanks, EJOHA. I am considering using X-CUBE-SBSFU to upgrade programmer, but the generated bin size is too big, my chip can't store it. I don't care about the transfer process, I care about the executable stored in the chip. My chip divides into three block, bootloader+application+download. This bin file should store in "download" region, but now it is to big. I don't know how to do with it.
2020-08-31 06:15 AM
Hi Lliba.1
I hope that there are some misunderstanding. Normally when programming a file into the embedded system the file is sent and programmed in many small sections from the PC to the embedded system. So the complete file does not need to be placed in system RAM before flashing.
Have you tried to use stand-alone STM32CubeProgrammer tool and flash the file. You can try to use via ST-LINK or via UART. I normally prefer to use the elf file or srec or hex file when using ST-LINK and CubeProgrammer. I have not tried to use UART but I assume CubeProgrammer in this case also support srec or hex files. Normally srec or hex files are preferred as these files includes address information which makes them much smaller if your program is split into different memory areas.
2020-08-31 06:25 PM
Thanks, EJOHA. I have tried to use stand-alone STM32CubeProgrammer tool and flash elf/hex/srec file, it's OK. For STM32 upgrade, we needn't include address information, as I will personalize address information, all I need be a clean bin file. But my program is split into different memory areas, this causes bin file to be too large. Srec or HEX files are preferred as these files include addreess information, I use software upgrade to download execute file, let's say my program has one bootloader programe, it will download execute file to STM32 application address, the starting address is determined, srec ot hex is too large for STM32 Chip. I wanted to use a smaller bin file, but my programe is split into diffrent memory areas, this results in a larger bin file. How do I upgrade through the application except for ST-LINK or STM32CubeProgrammer Tools.
2020-08-31 10:52 PM
Hi Lliba.1,
It is good to hear that it works with STM32CubeProgrammer.
In case you want to use a small clean bin file you will need to split the binary file into several binary files. It should be possible to do so by using GNU Binary Utilities included in the toolchain. Documentation of binutils can be found from STM32CubeIDE "Information Center". E,g, objcopy can be used with parameters to include only-section patterns from the elf file. When you have made separate bin files for the different memory areas you can add your address information somewhere and then embed your own bootloader in the device to handle flash upgrade.
I would recommend you to look into STM32 Bootloader also for a possible other solution, Please consider boot mode appnote found here and bootloader protocol here.