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

OTA DFU with a timer and no button

Hi,

I just learned how to do a OTA DFU. I tried it with nrf52840 DK and was successful in it, but our custom board does not have a button on it.    In production we will like the board to start always in the DFU mode when powered ON and look for new packages for initial 30 sec and then switch back to normal application . 

I was reading a lot about DFU_BUTTONLESS example but could not figure out the right procedure to do so.  

Will I have to change the structure of my application or will this logic be implemented inside the bootloader? 

Can you please provide some guiding steps to do so and if possible a pseudo code .

Thanks

Arshdeep

Parents Reply Children
  • Hi 

    Yes . He says just Enter the DFU mode on startup and then use a timeout  . 

    But how to enter in DFU mode in start up?

    Thanks

  • You don't need to change your application or use the buttonless DFU example in order to enter DFU mode on startup, it can be achieved by modifying the bootloader. I saw that you created a new ticket, where the reset pin is used to enter DFU mode, and I think that is the right approach.

    In order to switch back to the application after 30 seconds you have to set NRF_BL_DFU_INACTIVITY_TIMEOUT_MS equal to 30000.

    Best regards,

    Simon

  • Hi Simon,

    My reset button is not working on custom board. So I tried writing to GPREGRET register to switch to DFU mode. 

    In sdk_config.h I wrote 1 to NRF_BL_DFU_ENTER_METHOD_GPREGRET

    #ifndef NRF_BL_DFU_ENTER_METHOD_GPREGRET
    #define NRF_BL_DFU_ENTER_METHOD_GPREGRET 1
    #endif

    and in the main function wrote sd_power_gpregret_set(0, 0xB1);

    int main(void)
    {
    uint32_t ret_val;


    sd_power_gpregret_set(0, 0xB1);

    ret_val = nrf_bootloader_flash_protect(0, MBR_SIZE, false);
    APP_ERROR_CHECK(ret_val);
    ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE, false);
    APP_ERROR_CHECK(ret_val);

    (void) NRF_LOG_INIT(app_timer_cnt_get);
    NRF_LOG_DEFAULT_BACKENDS_INIT();

    NRF_LOG_INFO("Inside main");

    ret_val = nrf_bootloader_init(dfu_observer);
    APP_ERROR_CHECK(ret_val);
    nrf_bootloader_app_start();
    NRF_LOG_INFO("After main");
    }

    But it is not working . When I Power reset the board, it still remains in the application and does not enter in DFU mode. 

    What am I missing here ?

    Thanks!

  • Try using the call nrf_power_gpregret_set() instead. I tried running sd_power_gpregret_set() similar as you and did not get the return value NRF_SUCCESS. I think this is because the SoftDevice enable function isn't called yet.

    Best regards,

    Simon

  • Hi Simon,

    I tried that: 

     And now when I try to do DFU using nrfconnect mobile app. It goes till 100% but the board remains in DFU mode. May be it does flashes my new application but switches back to DFU mode within milliseconds. What will I have to do stop this ?

    int main(void)

    {

        uint32_t ret_val;

        //  sd_power_gpregret_set(0, 0xB1);

        nrf_power_gpregret_set(0xA5);

        // Protect MBR and bootloader code from being overwritten.

        ret_val = nrf_bootloader_flash_protect(0, MBR_SIZE, false);

        APP_ERROR_CHECK(ret_val);

        ret_val = nrf_bootloader_flash_protect(BOOTLOADER_START_ADDR, BOOTLOADER_SIZE, false);

        APP_ERROR_CHECK(ret_val);

     

        (void) NRF_LOG_INIT(app_timer_cnt_get);

        NRF_LOG_DEFAULT_BACKENDS_INIT();

     

        NRF_LOG_INFO("Inside main");

     

        ret_val = nrf_bootloader_init(dfu_observer);

        APP_ERROR_CHECK(ret_val);

        nrf_bootloader_app_start();

       

        // Should never be reached.

        NRF_LOG_INFO("After main");

    }

    Please suggest

    Thanks

Related