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?