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

Jump to bootloader from application code based on customer register data

Hello Everyone,

I am using nrf51822 256Kb Flash and 32KB RAM Raytac's BLE module with SDK11, S130 with over the air Bootloader (16Kb).

So the aim is that when a particular condition is true, data "1" is written to Customer [0] register. So next time when the module is powered ON or whenever, the application is running, the application code reads the data "1" from customer[0] and the device should advertise as "DFUtarg" (i.e., jump to bootloader). I am using arduino for programming with repo from sandeep mistry, so there are quite constraint to use readily available API's. I have tried writing data to customer register using arduino, it works.

Question:

In the below pseudo code, once the data "1" is written, the module keep resetting everytime and its not advertising as "DFUtarg" Am I going wrong somewhere?

This a random observation, Once I tried writing random data to 0x3c000 (I think bootloader location), the BLE starts advertising as "DFUtarg". Can someone explain me why it happened? Can this method can be used for switching to "DFUtarg"?

If I erase the application code, will the module start will advertise as "DFUtarg" when it is powered next time? I think of this idea because when we try to program the device (softdevice and bootloader without application code), the device advertise as "DFUtarg". Maybe completely incorrect :p

Thanks

Link: github.com/.../arduino-BLEPeripheral

pseudo code below



    #define BOOTLOADER_DFU_START 0xB1
    
    void loop()
    {


 if (particular condition is true)
{  
  write "1" to the customer[0] register 
}
.
.
.
.
.

int x = read data from the UICR register customer[0];
    
      if (customer[0] == "1") {
        {
        sd_power_gpregret_set(BOOTLOADER_DFU_START);
    
        NVIC_SystemReset();   
    
       //OR set the register directly and then call NVIC_SystemReset(); 
    
        NRF_POWER->GPREGRET = BOOTLOADER_DFU_START;
    
        NVIC_SystemReset();
      } 
    }
}
Related