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!

  • hi Bjørn, thank you for your response. And sorry for reporting back slightly late.

    It looks like the device is still stuck at bootloading mode , i..e the application code is not executed..

    Here are the linker file I modified according to your suggestion.

    For bootloader part, same as before:

    MEMORY
    {
         FLASH (rx) : ORIGIN = 0x3AC00, LENGTH = 0x5000
         RAM (rwx) :  ORIGIN = 0x20002C00, LENGTH = 0x5380
         NOINIT (rwx) :  ORIGIN = 0x20007F80, LENGTH = 0x80
         BOOTLOADER_SETTINGS (rw) : ORIGIN = 0x0003FC00, LENGTH = 0x0400
         UICR_BOOTLOADER (r) : ORIGIN = 0x10001014, LENGTH = 0x04
    }
    

    For application code part, I did some modification on flash and ram size.

    MEMORY
    {
        FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x1FC00
        RAM (rwx) :  ORIGIN = 0x20002080, LENGTH = 0x5F00
    }
    

    In addition, when I generating bootloader setting file using nrfutil, here are outputs I saw from console.

    Bootloader DFU Settings:
      * File:                 bootloader_setting.hex
      * Family:               nRF51
      * CRC:                  0x40A061E4
      * Settings Version:     0x00000001 (1)
      * App Version:          0x00000000 (0)
      * Bootloader Version:   0x00000000 (0)
      * Bank Layout:          0x00000000
      * Current Bank:         0x00000000
      * Application Size:     0x0000BA24 (47652 bytes)
      * Application CRC:      0x1AF13B5F
      * Bank0 Bank Code:      0x00000001
    

    Do you have any thoughts on what the possible reason may be??

    Thanks!

  • Hi Chen Chen,

    Sorry for the late answer. Bjørn is on vacation.

    My suggestion is to test without any mergehex. I don't see it's a good idea to use mergehex before you test and make sure DFU works as it should.

    My suggestion for you is to follow this guide.

    Make sure everything works. Including jumping from the bootloader to application and vice versa.

Related