diff --git a/examples/ble_peripheral/ble_app_buttonless_dfu/main.c b/examples/ble_peripheral/ble_app_buttonless_dfu/main.c index 2b99a42..ff2a66b 100644 --- a/examples/ble_peripheral/ble_app_buttonless_dfu/main.c +++ b/examples/ble_peripheral/ble_app_buttonless_dfu/main.c @@ -126,6 +126,20 @@ static void advertising_start(bool erase_bonds); // YOUR_JOB: Use UUIDs for service(s) used in your application. static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUID_TYPE_BLE}}; + +/**@brief Set register to start DFU on power-up and reset. + * + */ +static void enter_dfu(void) +{ + uint32_t old; + + (void)sd_power_gpregret_get(0, &old); + (void)sd_power_gpregret_set(0, old | BOOTLOADER_DFU_START); + NVIC_SystemReset(); +} + + /**@brief Handler for shutdown preparation. * * @details During shutdown procedures, this function will be called at a 1 second interval @@ -138,31 +152,22 @@ static ble_uuid_t m_adv_uuids[] = {{BLE_UUID_DEVICE_INFORMATION_SERVICE, BLE_UUI */ static bool app_shutdown_handler(nrf_pwr_mgmt_evt_t event) { + static int count = 0; + switch (event) { case NRF_PWR_MGMT_EVT_PREPARE_DFU: NRF_LOG_INFO("Power management wants to reset to DFU mode."); - // YOUR_JOB: Get ready to reset into DFU mode - // - // If you aren't finished with any ongoing tasks, return "false" to - // signal to the system that reset is impossible at this stage. - // - // Here is an example using a variable to delay resetting the device. - // - // if (!m_ready_for_reset) - // { - // return false; - // } - // else - //{ - // - // // Device ready to enter - // uint32_t err_code; - // err_code = sd_softdevice_disable(); - // APP_ERROR_CHECK(err_code); - // err_code = app_timer_stop_all(); - // APP_ERROR_CHECK(err_code); - //} + if (++count > 10) + { + enter_dfu(); // This is not needed! + return true; + } + else + { + NRF_LOG_INFO("Not entering DFU mode yet..."); + return false; + } break; default: @@ -833,7 +838,7 @@ static void power_management_init(void) */ static void idle_state_handle(void) { - if (NRF_LOG_PROCESS() == false) + //if (NRF_LOG_PROCESS() == false) { nrf_pwr_mgmt_run(); }