From 5970edc99c2786d2318ea4fbf2c8ec3370343524 Mon Sep 17 00:00:00 2001 From: TeTeHacko Date: Sat, 14 Nov 2026 10:42:33 +0100 Subject: [PATCH] NmeaGpsDriver: close the UART while `gps duty` keeps the GPS off (nRF52) Co-Authored-By: Claude Opus 5.5 --- src/helpers/sensors/NmeaGpsDriver.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/helpers/sensors/NmeaGpsDriver.h b/src/helpers/sensors/NmeaGpsDriver.h index 9beacdc2..baafc571 100644 --- a/src/helpers/sensors/NmeaGpsDriver.h +++ b/src/helpers/sensors/NmeaGpsDriver.h @@ -198,6 +198,14 @@ class NmeaGpsDriver : public GpsDriver { if (_resetPin != -1) digitalWrite(_resetPin, _resetActive); if (_peripheralPower != nullptr) _peripheralPower->release(); +#if defined(NRF52_PLATFORM) + // CUSTOM (TeTeHacko): close the UART that startHardware() opened. Left open, + // an nRF52 UARTE keeps its receiver and the HF clock running (~900 uA per the + // core's own Uart::end()) for all the hours `gps duty` keeps the GPS off, and + // its idle-high TX line feeds the unpowered module. sendNmeaSentence() is + // gated on _started: a write to a closed Uart takes a deleted semaphore. + if (_hardwareSerial != nullptr) _hardwareSerial->end(); +#endif _started = false; } @@ -333,6 +341,7 @@ public: void sendNmeaSentence(const char* sentence) { if (_hardwareSerial == nullptr || sentence == nullptr || sentence[0] != '$') return; + if (!_started) return; // CUSTOM (TeTeHacko): the UART is closed, see stopHardware() uint8_t checksum = 0; const char* p = sentence + 1;