Hi,
I'm working on a project with the nRF52840 using nRF5 SDK v15.3.0 and have been working on enabling dual-bank DFU in the bootloader. During this process I made several captures of the MCU's reset behavior when installing DFU packages (either with only application images or both bootloader and SoftDevice images) transferred over BLE. My understanding of the installation process is as follows:
- Application image only:
- To start the download the MCU resets and the bootloader enters DFU mod
- After the download is complete the MCU resets and the bootloader starts activating the image in the DFU package
- After the new image has been copied from bank 1 to bank 0 the MCU resets into the bootloader and boots the new application image
- Bootloader + SoftDevice:
- To start the download the MCU resets and the bootloader enters DFU mode
- After the download is complete the MCU resets and the bootloader starts activating the images in the DFU package
- The new SoftDevice is copied and overwrites the old one
- The SD_MBR_COMMAND_COPY_BL command is submitted, the MCU resets and the MBR copies the new bootloader and overwrites the old one
- The MCU boots into the new bootloader and the activation continues
- After the activation is finished the MCU resets into the bootloader and boots the application image
In the described scenarios there's going to be 3 and 4 resets respectively for the installation to complete. However, from my testing I'm consistently seeing 1 additional reset in both scenarios. The additional reset happens during the image_copy function in nrf_bootloader_fw_activation.c (which is called when copying the new application image and when copying the new SoftDevice image). The additional reset happens consistently, and in the same place. The image_copy function is called with arguments that at most allows it to copy 8*4KiB=32KiB at a time, and it's during the 4th of these copies (the 4th iteration of the while-loop in the function) that the reset happens. In both cases the MCU reset an additional time and continues the copying and finishes the whole installation process.
Below are some Saleae captures I hope help illustrate what I'm seeing. The signal POWER_ON indicates MCU resets, with it going low meaning the MCU reset and it going high meaning the bootloader has started running. I've then added additional toggling of the same signal to indicate loops in image_copy.
- Base capture without additional toggling of POWER_ON

- Capture with additional toggling of POWER_ON

It's not visible in the captures, but I can tell the difference between my toggles and MCU resets by how long POWER_ON stays low (my toggles holds POWER_ON low for 300ns while MCU resets holds it low for 700us).
I've tried moving the extra toggling of POWER_ON to after the other function calls in image_copy (nrf_dfu_flash_erase, nrf_dfu_flash_store and nrf_dfu_settings_write_and_backup), but I see the same number of toggles and the behavior is still present. To me this means it's not one of the functions failing. In image_copy there's this line:
//Firmware copying is time consuming operation thus watchdog handling is started nrf_bootloader_wdt_init();
Could there be an issue wrt. the watchdog that's "fixed" when a reset happens and the MCU continues with the same process/code? The above captures are from updating the bootloader+SoftDevice, so the amount of copying isn't that large, but when updating the application there's substantially more data being copied after the additional reset than before, so I don't think it's simply the amount of time spent copying that's potentially resulting in the watchdog timing out.
Unfortunately I don't have logs from the bootloader as building with logs exceeds the amount of flash the bootloader can occupy.
As a whole the update process works, so I'm mostly interested to understand why the additional reset is there.
Thanks,
Daniel

