2022年10月13日 星期四

[STM32] M0 series IAP Program Jump-2

In the previous article (M0 series IAP program jump-1), we have completed two projects: IAP and main program. Before completing the IAP download function, is it possible to verify it first? The answer is yes.

First, we need to convert the generated hex file to a bin file before verifying it since we haven't completed the IAP download function yet. During compilation, we can directly set the output format as bin file. In my case, I use the gcc compiler, so I need to set it in the Post-build steps section.


arm-none-eabi-objcopy -S -O binary "${ProjName}.elf" "${ProjName}.bin"

After setting it, the bin file will be automatically generated.

Now, we need a Hex editor tool software (URL: https://mh-nexus.de/en/). Download and install it. Then, we first open the IAP bin file. In File / Open..., load the bin file and scroll down to the last address point. We need to find the last address point.

In this screenshot, it is after 20 and shows an Offset of 1CE8. Because we set the SRAM location to 0h ~ 3FFFh earlier, we need to subtract the two values to get the number of bytes to fill. Here, we get 2318. In Edit / Insert bytes, we can fill up to 3FFFh. Then, save the file with a new name, such as IAPBoot.bin.

At this point, you can close the Hex Editor software and rename the main program as mainAP.bin. Next, open a cmd command line window and enter the following two commands.


copy IAPBoot.bin APALL.bin
type mainAP.bin >> APALL.bin

Create a new APALL.bin file and immediately follow it with the mainAP.bin main program. That's it! Then use ST-LINK to burn the APALL.bin file as the programming file to verify if it will jump to the main program segment.