Skip to content

Commit 1625385

Browse files
committed
Fix - RP2x Platform
1 parent b26776b commit 1625385

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

src/components/gps/hardware.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,13 @@ bool GPSHardware::DetectMtkUart() {
357357

358358
// Attempt to use Adafruit_GPS
359359
_ada_gps = new Adafruit_GPS(_hw_serial);
360-
if (!_ada_gps->begin(_hw_serial->baudRate())) {
360+
int baud_rate;
361+
#if defined(ARDUINO_RASPBERRY_PI_PICO_W) || defined(ARDUINO_RASPBERRY_PI_PICO_2W)
362+
baud_rate = 9600; // Pico SDK does not support getting baud rate from serial, default to 9600
363+
#else
364+
baud_rate = _hw_serial->baudRate();
365+
#endif
366+
if (!_ada_gps->begin(baud_rate)) {
361367
WS_DEBUG_PRINTLN("[gps] ERROR: Failed to initialize Mediatek!");
362368
return false;
363369
}

src/components/uart/hardware.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,19 @@ bool UARTHardware::ConfigureSerial() {
126126
_baud_rate = _config.baud_rate;
127127
#endif // HAS_SW_SERIAL
128128
} else {
129+
#ifdef ARDUINO_ARCH_RP2040
130+
if (_config.uart_nbr == 1) {
131+
_hwSerial = &Serial1;
132+
} else if (_config.uart_nbr == 2) {
133+
_hwSerial = &Serial2;
134+
} else {
135+
WS_DEBUG_PRINTLN("[uart] ERROR: Invalid UART number for ESP32!");
136+
return false;
137+
}
138+
#else
129139
// Create a new HardwareSerial instance
130140
_hwSerial = new HardwareSerial(_config.uart_nbr);
141+
#endif
131142
if (_hwSerial == nullptr) {
132143
WS_DEBUG_PRINTLN(
133144
"[uart] ERROR: Failed to allocate HardwareSerial instance!");
@@ -138,8 +149,7 @@ bool UARTHardware::ConfigureSerial() {
138149
_hwSerial->begin((unsigned long)_config.baud_rate, (uint32_t)cfg, rx_pin,
139150
tx_pin, false, (unsigned long)_config.timeout);
140151
#elif ARDUINO_ARCH_RP2040
141-
_hwSerial->setRx(rx_pin);
142-
_hwSerial->setTx(tx_pin);
152+
// Pins are already defined by the Serial1/Serial2 instances
143153
_hwSerial->begin((unsigned long)_config.baud_rate, (uint32_t)cfg);
144154
#else
145155
// ESP8266, SAMD, and other platforms

0 commit comments

Comments
 (0)