This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to jump from Bootloader to Application (nrf51822)

Currently, I am trying to develop nrf51822 (MDBT40) using Nordic SDK v12 (S130). The programmer I used is DAPLink from RedBear.

I am wondering how to make program to jump from bootloader to application code.

This is what I have don:

  • Flash bootloader_secure example as my bootloader program:

    • Go to bootloader_secure/pca10028/armgcc/ and type "make clean; make";

    • Copy the generated .hex file in _build directory;

    • Merge the provided s130_nrf51_2.0.1_softdevice.hex with .hex file using:

      ./mergehex -m s130_nrf51_2.0.1_softdevice.hex nrf51422_xxac.hex -o bootloaderout.hex

    • Drag bootloaderout.hex file into virtual file system created by DAPLink for flashing bootloader;

  • Flash Beacon Example as Application Firmware:

    • Similar to previous steps, get .hex file by making the program;

    • Merge the provided s130_nrf51_2.0.1_softdevice.hex with .hex file using:

      ./mergehex -m s130_nrf51_2.0.1_softdevice.hex nrf51422_xxac.hex -o appout.hex

    • Drag appout.hex file into virtual file system created by DAPLink for flashing application code;

From what I observed, my nrf51822 only execute the beacon app, with the secure DFU bootloader being ignore. However, from what I think, the nrf51822 should execute bootloader code, after which the application code will be executed. This can be explained by following statement in main.c from bootloader:

nrf_bootloader_app_start(MAIN_APPLICATION_START_ADDR); // the MAIN_APPLICATION_START_ADDR looks like the increment of SoftDevice

Can anyone suggest me where the mistake I may make. Thanks!

  • You need to generate a bootloader settings page, please see Appendix 1 in this blog post.

  • Thanks for your suggestion Bjørn. As the guide indicated by you. Currently I got 4 hex files, which are application.hex, bootloader.hex, bootloader_setting.hex, softdevice.hex. I am wondering how shall I merge them together.

    This is how I did currently, but it looks like it doesn't work property. The device just step into application code directly with bootloading/secure DFU part being passed.. Could you please indicate me where the the mistake I made

    • Merge bootloader.hex and bootloader_setting.hex using following command:

      ./mergehex -m bootloader.hex bootloader_setting.hex -o outputbootloader.hex

    • Merge application code and softdevice using following command:

      ./mergehex -m application.hex s130_nrf51_2.0.1_softdevice.hex -o outputapp.hex

    • Drag outputbootloader.hex into virtual file system generated by DAPLink. And wait until it is finished;

    • Drag outputapp.hex into virtual file system generated by DAPLink. Wait until it is finished.

  • If you have flashed both outputapp.hex and outputbootloader.hex to the board and it is jumping to the application then that is the correct behaviour. The bootloader will check if the application CRC on the bootloader settings page matches the CRC of the application hex in flash. If this is the case, then it will jump to the application.

  • Thanks Bjørn! However in this case, it looks like the code in bootloader is not executed at all.. I planned to put dfu OTA code in bootloader, such that during initial start-up, there are few seconds for users being able to update their firmware. That is:

    • execute bootloader code which contains DFU update code. In this stage users is able to do OTA
    • jump to application if users are not doing anything during boot loading stage.

    Would you mind indicating me how to do that?

  • Could you try to merge outputapp.hex and outputbootloader.hex using mergehex? If you get an error, then you're most likely overwritting the bootloader when you're flashing outputapp.hex

Related