Make uf2reset available across nRF52 CLI roles
This commit is contained in:
1 parent
a8cf4fd12f
commit
69d9d9e62a
14 files changed
+154
-34
No files matched your search
@@ -137,6 +137,10 @@ public:
|
||||
virtual void onBeforeTransmit() { }
|
||||
virtual void onAfterTransmit() { }
|
||||
virtual void reboot() = 0;
|
||||
// Reboot into a UF2-capable bootloader when the platform supports the
|
||||
// retained reset request. Returns false only when unsupported or rejected;
|
||||
// a successful implementation resets and does not return.
|
||||
virtual bool rebootToUf2Bootloader() { return false; }
|
||||
virtual void powerOff() { /* no op */ }
|
||||
// Reload an already-running system watchdog without enabling one. Long,
|
||||
// internally bounded operations can use this while retaining their own
|
||||
|
||||
@@ -517,6 +517,10 @@ inline NoArgCommandMatch matchNoArgCommand(const char* command,
|
||||
: NoArgCommandMatch::HasArguments;
|
||||
}
|
||||
|
||||
inline bool isUf2ResetCommand(const char* command) {
|
||||
return matchNoArgCommand(command, "uf2reset") == NoArgCommandMatch::Exact;
|
||||
}
|
||||
|
||||
inline void formatUnknownSetting(char* reply, size_t capacity,
|
||||
const char* setting) {
|
||||
if (reply == nullptr || capacity == 0) return;
|
||||
|
||||
@@ -18,29 +18,6 @@
|
||||
#include <new>
|
||||
#include <stddef.h>
|
||||
|
||||
#if defined(NRF52_PLATFORM)
|
||||
#include <nrf.h>
|
||||
#include <nrf_soc.h>
|
||||
|
||||
#ifndef DFU_MAGIC_UF2_RESET
|
||||
#define DFU_MAGIC_UF2_RESET 0x57
|
||||
#endif
|
||||
|
||||
static void resetToUf2Bootloader() {
|
||||
uint8_t sd_enabled = 0;
|
||||
sd_softdevice_is_enabled(&sd_enabled);
|
||||
|
||||
if (sd_enabled) {
|
||||
sd_power_gpregret_clr(0, 0xFF);
|
||||
sd_power_gpregret_set(0, DFU_MAGIC_UF2_RESET);
|
||||
} else {
|
||||
NRF_POWER->GPREGRET = DFU_MAGIC_UF2_RESET;
|
||||
}
|
||||
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
#endif
|
||||
|
||||
#define STR_HELPER(x) #x
|
||||
#define STR(x) STR_HELPER(x)
|
||||
#if defined(ENABLE_OTA)
|
||||
@@ -2486,12 +2463,11 @@ void CommonCLI::handleCommand(uint32_t sender_timestamp, char* command, char* re
|
||||
_board->powerOff(); // doesn't return
|
||||
} else if (memcmp(command, "reboot", 6) == 0) {
|
||||
_board->reboot(); // doesn't return
|
||||
} else if (sender_timestamp == 0 && memcmp(command, "uf2reset", 8) == 0 && (command[8] == 0 || command[8] == ' ')) {
|
||||
#if defined(NRF52_PLATFORM)
|
||||
resetToUf2Bootloader(); // doesn't return
|
||||
#else
|
||||
strcpy(reply, "ERR: unsupported");
|
||||
#endif
|
||||
} else if (sender_timestamp == 0
|
||||
&& mesh::cli::isUf2ResetCommand(command)) {
|
||||
if (!_board->rebootToUf2Bootloader()) {
|
||||
strcpy(reply, "ERR: unsupported");
|
||||
}
|
||||
} else if (memcmp(command, "clkreboot", 9) == 0) {
|
||||
// Reset clock
|
||||
getRTCClock()->setCurrentTime(1715770351); // 15 May 2024, 8:50pm
|
||||
|
||||
@@ -33,6 +33,10 @@ static bool ota_ble_started = false;
|
||||
#define NRF52_WATCHDOG_TIMEOUT_SECONDS 60UL
|
||||
#endif
|
||||
|
||||
#ifndef DFU_MAGIC_UF2_RESET
|
||||
#define DFU_MAGIC_UF2_RESET 0x57
|
||||
#endif
|
||||
|
||||
#if NRF52_WATCHDOG_TIMEOUT_SECONDS > 131071UL
|
||||
#error "NRF52_WATCHDOG_TIMEOUT_SECONDS exceeds the nRF52 WDT counter range"
|
||||
#endif
|
||||
@@ -96,6 +100,23 @@ bool NRF52Board::isUserGpioAvailable(uint8_t pin) const {
|
||||
#endif
|
||||
}
|
||||
|
||||
bool NRF52Board::rebootToUf2Bootloader() {
|
||||
uint8_t sd_enabled = 0;
|
||||
if (sd_softdevice_is_enabled(&sd_enabled) != NRF_SUCCESS) return false;
|
||||
|
||||
if (sd_enabled) {
|
||||
if (sd_power_gpregret_clr(0, 0xFF) != NRF_SUCCESS
|
||||
|| sd_power_gpregret_set(0, DFU_MAGIC_UF2_RESET) != NRF_SUCCESS) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
NRF_POWER->GPREGRET = DFU_MAGIC_UF2_RESET;
|
||||
}
|
||||
|
||||
NVIC_SystemReset();
|
||||
return true;
|
||||
}
|
||||
|
||||
static void connect_callback(uint16_t conn_handle) {
|
||||
ota_conn_handle = conn_handle;
|
||||
MESH_DEBUG_PRINTLN("BLE client connected");
|
||||
|
||||
@@ -63,6 +63,7 @@ public:
|
||||
virtual uint8_t getStartupReason() const override { return startup_reason; }
|
||||
virtual float getMCUTemperature() override;
|
||||
virtual void reboot() override { NVIC_SystemReset(); }
|
||||
bool rebootToUf2Bootloader() override;
|
||||
virtual void shutdownPeripherals();
|
||||
virtual void powerOff() override;
|
||||
virtual bool getBootloaderVersion(char* version, size_t max_len) override;
|
||||
|
||||
Reference in new issue
Block a user