Skip to content

Commit b9eb9a3

Browse files
committed
Fix GPS UART consuming +8mA when disabled (nRF52)
When GPS is disabled (or not detected), Serial1.begin() was called during initBasicGPS() but never ended. On nRF52840 the UARTE peripheral stays active, drawing ~8mA through the peripheral itself and current leaking via TX pin into the GPS module's ESD diodes. - Call Serial1.end() in initBasicGPS() and stop_gps() to disable UART - Re-initialize Serial1 in start_gps() so GPS can be toggled back on - Gate _location->loop() behind gps_active to prevent accessing ended Serial (and avoid pointless NMEA polling when GPS is off) Fixes #1628
1 parent b1094c2 commit b9eb9a3

1 file changed

Lines changed: 13 additions & 1 deletion

File tree

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,6 +583,7 @@ void EnvironmentSensorManager::initBasicGPS() {
583583
MESH_DEBUG_PRINTLN("No GPS detected");
584584
}
585585
_location->stop();
586+
Serial1.end(); // Disable UART peripheral to save power (significant on nRF52)
586587
gps_active = false; //Set GPS visibility off until setting is changed
587588
}
588589

@@ -680,6 +681,14 @@ void EnvironmentSensorManager::start_gps() {
680681
return;
681682
#endif
682683

684+
// Re-initialize UART (was closed by stop_gps() to save power)
685+
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX);
686+
#ifdef GPS_BAUD_RATE
687+
Serial1.begin(GPS_BAUD_RATE);
688+
#else
689+
Serial1.begin(9600);
690+
#endif
691+
683692
_location->begin();
684693
_location->reset();
685694

@@ -697,6 +706,7 @@ void EnvironmentSensorManager::stop_gps() {
697706
#endif
698707

699708
_location->stop();
709+
Serial1.end(); // Disable UART peripheral to save power (significant on nRF52)
700710

701711
#ifndef PIN_GPS_EN
702712
MESH_DEBUG_PRINTLN("Stop GPS is N/A on this board. Actual GPS state unchanged");
@@ -707,7 +717,9 @@ void EnvironmentSensorManager::loop() {
707717
static long next_gps_update = 0;
708718

709719
#if ENV_INCLUDE_GPS
710-
_location->loop();
720+
if (gps_active) {
721+
_location->loop();
722+
}
711723
if (millis() > next_gps_update) {
712724

713725
if(gps_active){

0 commit comments

Comments
 (0)