Today I tried to work on a firmware updater using the STM32 Bootloader driver. I’ll post about the program later since it took a while to figure out how to write something in C# to use the preferred STM32 Bootloader driver instead of the outdated DFU Device bootloader.
In any case, this firmware updater programer uses Intel Hex file for the firmware updating. Technically you can use Bin as well, but Intel Hex file is nicer because it already has the memory address mapped out. You need to the Bin file what memory address to start and that invites errors that could potentially brick your device. I worked with a firmware engineer who just quit recently and all he gave us for the firmware was the bin file. I do have the source code so I could technically compile a hex output from the source code, but the IDE environment and settings were not available from this engineer. So the best option is to find a way to covert this working bin firmware to hex so that I can use it to update device firmware with the program.
After doing a bit of search on how to convert bin to hex, I found that SRecord is the best tool to do this. You can download the appropriate installer for your desired OS here: https://srecord.sourceforge.net/download.html
For my use case, I went with the Windows version. It’s actually quite easy to use once you figured out what to do. I mentioned how Bin file doesn’t have the memory address while hex does. If you just do the simple convert like the examples around the web show:
srec_cat.exe "firmware.bin" -binary -output "firmware.hex" -Intel
This didn’t work too well for STM32 since the firmware main program address doesn’t start at 0x00000000 because that’s where the boot loader firmware starts. The actual application memory address starts at 0x08000000. Therefore, we need to shift the data from the binary file to that address. This is easy to do using SRecord. Use the following command instead:
srect_cat.exe "firmware.bin" -binary -offset 0x08000000 -output "firmware.hex" -Intel
Now your newly created .hex file should be useable on STM32Cube Programmer as well.