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

Bootloader resets after switching to DFU

Hi,

I have a huge issue with NRF52832 and DFU on custom board. I have a custom characteristic in my application to switch to DFU after proper PIN typing. Then I call this function:

uint32_t switch_to_dfu() {

  uint32_t err_code;
  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);

  err_code = sd_power_gpregret_set(1, BOOTLOADER_DFU_SKIP_CRC);
  VERIFY_SUCCESS(err_code);

  nrf_pwr_mgmt_shutdown(NRF_PWR_MGMT_SHUTDOWN_GOTO_DFU);
  return 0;
}

After that device resets to bootloader and there is such a code:

    // Protect MBR and bootloader code from being overwritten.
    uint32_t 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);

    // Either there was no DFU functionality enabled in this project or the DFU module detected
    // no ongoing DFU operation and found a valid main application.
    // Boot the main application.
    nrf_bootloader_app_start();

    // Should never be reached.
    NRF_LOG_INFO("After main");

Unfortunately bootloader stops in  nrf_dfu_req_handler_init  and device resets and after that go to application. 

That all happen when I erase whole code using nrfjprog/nrfconnect and then flash it bl_sd_app_with_settings.hex. When I use OpenOCD 0.10.0 trying to debug and use mo reset halt command problem disappear (but problem isn't in optimization flag). Everything works fine.     

Any thoughts?

Parents
  • Hello,

    I don't know what SDK you are using, but have you tried to run the debug bootloader project? In SDK17.0.2 that would be:

    SDK\examples\dfu\secure_bootloader\pca10040_s132_ble_debug\<your IDE>

    Does the log say anything? 

    If not, try adding the this to the log, after nrf_dfu_req_handler_init(dfu_observer);

        ret_val = nrf_dfu_req_handler_init(dfu_observer);
        NRF_LOG_INFO("nrf_dfu_req_handler_init() returned %02x", ret_val);
        

    What does it return? Are you able to debug and figure out where inside nrf_dfu_req_handler_init() this is returned?

    Best regards,

    Edvin

Reply
  • Hello,

    I don't know what SDK you are using, but have you tried to run the debug bootloader project? In SDK17.0.2 that would be:

    SDK\examples\dfu\secure_bootloader\pca10040_s132_ble_debug\<your IDE>

    Does the log say anything? 

    If not, try adding the this to the log, after nrf_dfu_req_handler_init(dfu_observer);

        ret_val = nrf_dfu_req_handler_init(dfu_observer);
        NRF_LOG_INFO("nrf_dfu_req_handler_init() returned %02x", ret_val);
        

    What does it return? Are you able to debug and figure out where inside nrf_dfu_req_handler_init() this is returned?

    Best regards,

    Edvin

Children
No Data
Related