We've had so many problem with Bluetooth Smart DFU on nRF52832 that I've decided to write a ticket here and ask for help. We've been reading lots of documentation, following articles and examples, but getting DFU working have been a mess. We have finally been able to do DFU, so now we want to generate a script that uses the compiled bootloader.hex and application.hex to create a fully working hex file ready to be flashed, that is, after flashing the chip shall boot up and run the application as if there is no bootloader, from the very first reset.
We've finally found out that in order to do this, we must merge bootloader.hex, application.hex, nRF52_SDK_16.0.0/components/softdevice/s132/hex/s132_nrf52_7.0.1_softdevice.hex and a generated application_dfu_settings.hex. Using mergehex as suggested did not work, it can only merge 3 hex files, and if we merge two times (3 + 1) the hex will not run if flashed and it is impossible to debug why (I guess it does not place the text properly).
Luckily, we found the very nice nRF Connect Programmer program which lets us add the 4 hex files visually. And it lets us flash the chip and read back the content visually (it looks correct too). And finally the program lets us save the result as a hex file. It turns out that if we flash the chip with this hex file, everything works exactly as we want. Magic.
How do I merge the 4 hex files into 1 hex file from command line exactly as nRF Connect Programmer does? Because we need a script to automatize the process.
We use nRF52 SDK 16.0.0 and Segger Embedded Studio.
PS: The SDK also contains a hex file components/softdevice/mbr/hex/mbr_nrf52_2.4.1_mbr.hex. We did not use that. It seems that nRF Connect Programmer adds a MBR automatically when adding s132_nrf52_7.0.1_softdevice.hex. What is mbr_nrf52_2.4.1_mbr.hex for?
PPS: Our bootloader does actually not work as expected. Instead we had to remove the nrf_bootloader_flash_protect() code before nrf_bootloader_init(), otherwise it hangs in an unknown state.