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

Enter bootloader from app on stock nRF52840 dongle

Hi, 

using a stock nRF52840 dongle and willing to enter bootloader (same as pushing the relevant button on the dongle) from app. How can that be done, using stock bootloader? 

Regards,

Andrea

Parents
  • HI Andrea

    in the dfu_enter_check() function, which is called by nrf_bootloader_init(), the bootloader checks if one of the NRF_BL_DFU_ENTER_METHOD_xxxx has been used to trigger the device to stay in bootloader mode and not start the application( if there is a valid one).

    static bool dfu_enter_check(void)
    {
        if (!app_is_valid(crc_on_valid_app_required()))
        {
            NRF_LOG_DEBUG("DFU mode because app is not valid.");
            return true;
        }
    
        if (NRF_BL_DFU_ENTER_METHOD_BUTTON &&
           (nrf_gpio_pin_read(NRF_BL_DFU_ENTER_METHOD_BUTTON_PIN) == 0))
        {
            NRF_LOG_DEBUG("DFU mode requested via button.");
            return true;
        }
    
        if (NRF_BL_DFU_ENTER_METHOD_PINRESET &&
           (NRF_POWER->RESETREAS & POWER_RESETREAS_RESETPIN_Msk))
        {
            NRF_LOG_DEBUG("DFU mode requested via pin-reset.");
            return true;
        }
    
        if (NRF_BL_DFU_ENTER_METHOD_GPREGRET &&
           (nrf_power_gpregret_get() & BOOTLOADER_DFU_START))
        {
            NRF_LOG_DEBUG("DFU mode requested via GPREGRET.");
            return true;
        }
    
        if (NRF_BL_DFU_ENTER_METHOD_BUTTONLESS &&
           (s_dfu_settings.enter_buttonless_dfu == 1))
        {
            NRF_LOG_DEBUG("DFU mode requested via bootloader settings.");
            return true;
        }
    
        return false;
    }
    

    The method used in our buttonless DFU application example is the NRF_BL_DFU_ENTER_METHOD_GPREGRET, see the ble_dfu_buttonless_bootloader_start_finalize() function below.

    uint32_t ble_dfu_buttonless_bootloader_start_finalize(void)
    {
        uint32_t err_code;
    
        NRF_LOG_DEBUG("In ble_dfu_buttonless_bootloader_start_finalize\r\n");
    
        err_code = sd_power_gpregret_clr(0, 0xffffffff);
        VERIFY_SUCCESS(err_code);
    
        err_code = sd_power_gpregret_set(0, BOOTLOADER_DFU_START);
        VERIFY_SUCCESS(err_code);
    
        // Indicate that the Secure DFU bootloader will be entered
        m_dfu.evt_handler(BLE_DFU_EVT_BOOTLOADER_ENTER);
    
        // Signal that DFU mode is to be enter to the power management module
        nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU);
    
        return NRF_SUCCESS;
    }

  • Hi, 

    thanks for the clarification, but my question is not yet answered. When I use a factory new (stock) dongle, bought on Mouser, what code should I use to enter bootloader from the APP? 

    The code above seems not to work. Could it be the bootloader which is flashed from factory does not have NRF_BL_DFU_ENTER_METHOD_GPREGRET enabled?

    Regards,

    Andrea

Reply Children
Related