Skip to content

Commit 71d8e57

Browse files
committed
Replace INPUT_PULLUP with PSEL loopback to fix Serial1.end() hang
The internal pullup (~13kΩ) wasn't strong enough to overcome the GPS module's TX line pulling LOW through ESD diodes when powered off. Instead, redirect UARTE0 PSEL.RXD to its own TXD pin before calling Serial1.end(). The UARTE drives TX HIGH in idle state, so RX reads a guaranteed idle line regardless of GPS module pin state. RXTO fires promptly and end() completes without hanging.
1 parent 59f341c commit 71d8e57

1 file changed

Lines changed: 11 additions & 6 deletions

File tree

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,13 @@ void EnvironmentSensorManager::initBasicGPS() {
583583
MESH_DEBUG_PRINTLN("No GPS detected");
584584
}
585585
_location->stop();
586-
// Pull up MCU's RX pin before ending UART. When GPS powers down, its TX
587-
// line drops LOW (break condition) which prevents nRF52 UARTE's RXTO event
588-
// from firing, causing Serial1.end() to hang indefinitely.
589-
pinMode(PIN_GPS_TX, INPUT_PULLUP); // PIN_GPS_TX = toward CPU = MCU's RX
586+
#ifdef NRF52_PLATFORM
587+
// Redirect UART RX to its own TX pin before ending Serial. When GPS powers
588+
// down its TX drops LOW (break condition), preventing nRF52 UARTE's RXTO
589+
// event from firing and hanging Serial1.end() indefinitely. Looping RX to
590+
// TX guarantees an idle (HIGH) line so RXTO fires promptly.
591+
NRF_UARTE0->PSEL.RXD = NRF_UARTE0->PSEL.TXD;
592+
#endif
590593
Serial1.end(); // Disable UART peripheral to save power (significant on nRF52)
591594
gps_active = false; //Set GPS visibility off until setting is changed
592595
}
@@ -710,8 +713,10 @@ void EnvironmentSensorManager::stop_gps() {
710713
#endif
711714

712715
_location->stop();
713-
// Pull up MCU's RX pin before ending UART - see comment in initBasicGPS()
714-
pinMode(PIN_GPS_TX, INPUT_PULLUP);
716+
#ifdef NRF52_PLATFORM
717+
// Redirect UART RX to TX pin — see comment in initBasicGPS()
718+
NRF_UARTE0->PSEL.RXD = NRF_UARTE0->PSEL.TXD;
719+
#endif
715720
Serial1.end(); // Disable UART peripheral to save power (significant on nRF52)
716721

717722
#ifndef PIN_GPS_EN

0 commit comments

Comments
 (0)