static void ble_dfu_buttonless_evt_handler(ble_dfu_buttonless_evt_type_t event) { switch (event) { case BLE_DFU_EVT_BOOTLOADER_ENTER_PREPARE: NRF_LOG_INFO("Device is preparing to enter bootloader mode\r\n"); break; case BLE_DFU_EVT_BOOTLOADER_ENTER: NRF_LOG_INFO("Device will enter bootloader mode\r\n"); break; case BLE_DFU_EVT_BOOTLOADER_ENTER_FAILED: NRF_LOG_ERROR("Device failed to enter bootloader mode\r\n"); break; default: NRF_LOG_INFO("Unknown event from ble_dfu.\r\n"); break; } }
加一个重启进bootloader去DFU前的关机函数:
static bool app_shutdown_handler(nrf_pwr_mgmt_evt_t event) { switch (event) { case NRF_PWR_MGMT_EVT_PREPARE_DFU: NRF_LOG_INFO("Power management wants to reset to DFU mode\r\n"); // Change this code to tailor to your reset strategy. // Returning false here means that the device is not ready // to jump to DFU mode yet. // // Here is an example using a variable to delay resetting the device: // /* if (!im_ready_for_reset) { return false; } */ break; default: // Implement any of the other events available // from the power management module: // -NRF_PWR_MGMT_EVT_PREPARE_SYSOFF // -NRF_PWR_MGMT_EVT_PREPARE_WAKEUP // -NRF_PWR_MGMT_EVT_PREPARE_RESET return true; } NRF_LOG_INFO("Power management allowed to reset to DFU mode\r\n"); return true;