From 2e96bf642c9ede190a6159ffeb5143876cbcf525 Mon Sep 17 00:00:00 2001 From: MagnusKos Date: Wed, 23 Jul 2025 18:19:33 +0300 Subject: [PATCH] nRF52 pre-sleep main serial check Added another usage check for the main Serial. It could save some nerves in case the port is not in use by any means. Applied trunk fmt to the file. --- src/platform/nrf52/main-nrf52.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platform/nrf52/main-nrf52.cpp b/src/platform/nrf52/main-nrf52.cpp index 6345c79f7..590d2f0ae 100644 --- a/src/platform/nrf52/main-nrf52.cpp +++ b/src/platform/nrf52/main-nrf52.cpp @@ -282,13 +282,13 @@ void cpuDeepSleep(uint32_t msecToWake) #if SPI_INTERFACES_COUNT > 1 SPI1.end(); #endif - // This may cause crashes as debug messages continue to flow. - Serial.end(); + if (Serial) // Another check in case of disabled default serial, does nothing bad + Serial.end(); // This may cause crashes as debug messages continue to flow. - // This causes troubles with waking up on nrf52 (on pro-micro in particular): - // we have no Serial1 in use on nrf52, check Serial and GPS modules. + // This causes troubles with waking up on nrf52 (on pro-micro in particular): + // we have no Serial1 in use on nrf52, check Serial and GPS modules. #ifdef PIN_SERIAL1_RX - if (Serial1) // A straightforward solution to the wake from deepsleep problem + if (Serial1) // A straightforward solution to the wake from deepsleep problem Serial1.end(); #endif setBluetoothEnable(false); @@ -366,7 +366,7 @@ void cpuDeepSleep(uint32_t msecToWake) // Resume on user button press // https://github.com/lyusupov/SoftRF/blob/81c519ca75693b696752235d559e881f2e0511ee/software/firmware/source/SoftRF/src/platform/nRF52.cpp#L1738 constexpr uint32_t DFU_MAGIC_SKIP = 0x6d; - sd_power_gpregret_clr(0, 0xFF); // Clear the register before setting a new values in it for stability reasons + sd_power_gpregret_clr(0, 0xFF); // Clear the register before setting a new values in it for stability reasons sd_power_gpregret_set(0, DFU_MAGIC_SKIP); // Equivalent NRF_POWER->GPREGRET = DFU_MAGIC_SKIP // FIXME, use system off mode with ram retention for key state?