From dbac2b1cadb7a4e114fedb665beb4646436719b1 Mon Sep 17 00:00:00 2001 From: Ben Meadors Date: Wed, 27 Dec 2023 14:26:40 -0600 Subject: [PATCH] Implemented enter (Uf2 usb) DFU mode admin message on NRF52 (#3045) * Added enter DFU mode admin message * Trunk --- protobufs | 2 +- src/main.h | 2 +- src/mesh/generated/meshtastic/admin.pb.h | 2 +- src/modules/AdminModule.cpp | 7 +++++++ src/platform/nrf52/main-nrf52.cpp | 6 ++++++ 5 files changed, 16 insertions(+), 3 deletions(-) diff --git a/protobufs b/protobufs index 8e84c2f95f..4a1d3766e8 160000 --- a/protobufs +++ b/protobufs @@ -1 +1 @@ -Subproject commit 8e84c2f95fcc7f0e88a80645d3a88812adbda841 +Subproject commit 4a1d3766e888d3dd7d1acda817083295fb054c92 diff --git a/src/main.h b/src/main.h index 52e9a42715..8a646c80b2 100644 --- a/src/main.h +++ b/src/main.h @@ -77,7 +77,7 @@ extern int heltec_version; // This will suppress the current delay and instead try to run ASAP. extern bool runASAP; -void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(), rp2040Setup(), clearBonds(); +void nrf52Setup(), esp32Setup(), nrf52Loop(), esp32Loop(), rp2040Setup(), clearBonds(), enterDfuMode(); meshtastic_DeviceMetadata getDeviceMetadata(); diff --git a/src/mesh/generated/meshtastic/admin.pb.h b/src/mesh/generated/meshtastic/admin.pb.h index 198a076fdb..48df9ba56c 100644 --- a/src/mesh/generated/meshtastic/admin.pb.h +++ b/src/mesh/generated/meshtastic/admin.pb.h @@ -131,7 +131,7 @@ typedef struct _meshtastic_AdminMessage { bool get_node_remote_hardware_pins_request; /* Respond with the mesh's nodes with their available gpio pins for RemoteHardware module use */ meshtastic_NodeRemoteHardwarePinsResponse get_node_remote_hardware_pins_response; - /* Enter (serial) DFU mode + /* Enter (UF2) DFU mode Only implemented on NRF52 currently */ bool enter_dfu_mode_request; /* Set the owner for this node */ diff --git a/src/modules/AdminModule.cpp b/src/modules/AdminModule.cpp index b33877b8d5..e2ec0c699b 100644 --- a/src/modules/AdminModule.cpp +++ b/src/modules/AdminModule.cpp @@ -188,6 +188,13 @@ bool AdminModule::handleReceivedProtobuf(const meshtastic_MeshPacket &mp, meshta reboot(DEFAULT_REBOOT_SECONDS); break; } + case meshtastic_AdminMessage_enter_dfu_mode_request_tag: { + LOG_INFO("Client is requesting to enter DFU mode.\n"); +#ifdef ARCH_NRF52 + enterDfuMode(); +#endif + break; + } #ifdef ARCH_PORTDUINO case meshtastic_AdminMessage_exit_simulator_tag: LOG_INFO("Exiting simulator\n"); diff --git a/src/platform/nrf52/main-nrf52.cpp b/src/platform/nrf52/main-nrf52.cpp index cab6a63b9e..c1d3e93fb8 100644 --- a/src/platform/nrf52/main-nrf52.cpp +++ b/src/platform/nrf52/main-nrf52.cpp @@ -1,4 +1,5 @@ #include "configuration.h" +#include #include #include #include @@ -214,4 +215,9 @@ void clearBonds() nrf52Bluetooth->setup(); } nrf52Bluetooth->clearBonds(); +} + +void enterDfuMode() +{ + enterUf2Dfu(); } \ No newline at end of file