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!

  • Thanks Bjørn, as you said, I have did following trials:

    • merge outputapp.hex and outputbootloader.hex, for getting a single out.hex. The process of merge completed successfully! However when I flashed to device, only bootloader code can be executed with application code being ignored!

    • The based on previous code, I flash outapp.hex (application code + softDevice) again, only application code works with bootloader being ignored..

    I am guessing the reason is that I didn't configure the linker file. As your reference, here is the linker file of application code, and the device I used is 16KB RAM 256KB Flash nrf51822 chip. Could you please help me check whether this is correct? Thanks!

    MEMORY
    {
        FLASH (rx) : ORIGIN = 0x1b000, LENGTH = 0x25000
        RAM (rwx) :  ORIGIN = 0x200033b0, LENGTH = 0x4c50
    }
    
  • After trying out many parameters, I think the reason is that the application code is flashed to wrong paces. Here is my modified linker file for application code, which I think it is correct for 16KB RAM:

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

    However, it looks like it still doesn't work (the bootloader can be executed successfully, however the it cannot jump to application code). Could you please indicate where the problem might be? Thanks!

  • The length of the application flash section is incorrect, it should be 0x21000 if the bootloader starts at 0x3C000. Could you post the linker script for the bootloader you're using?

  • Thanks Bjørn, as your reference, after double checking the hardware specification an datasheet, the nrf51822 chip I used has 32kB RAM 256KB Flash (RedBear Nano V1.5).

    I used the default bootloader linker scripts in Nordic V12 SDK:

    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
    }
    

    And here are the linker scripts I used for application code:

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

    Could you please help me confirming whether the parameters are correct? And thank you for helping me out these days!

  • You need to adjust the size of the application flash section as 0x1B000 + 0x25000 = 0x40000 (256kB), i.e. there is no room for the bootloader. Adjusting the size to 0x210000, i.e. 0x1B000 + 0x1FC00 = 0x3A000. Also, since you're using the 32kB variant of the nRF51822 you can increase the RAM size to 0x5F00.

Related