Skip to content

Commit 8ff2da7

Browse files
authored
fix(HardwareSerial): fix pin remapping in begin() (#10380)
The pin remapping functions have to be called as early as possible in the begin() function, to immediately convert the input parameters to the GPIO numbers used everywhere in the core. This issue has always been dormant since the introduction of pin remapping in 9b4622d, but was exposed by the recent UART pin detach support, which actually disabled the original Serial0 pins. Move the pin remapping function calls earlier in the begin() function to fix this issue.
1 parent f23914e commit 8ff2da7

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

cores/esp32/HardwareSerial.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
282282
}
283283
#endif
284284

285+
// map logical pins to GPIO numbers
286+
rxPin = digitalPinToGPIONumber(rxPin);
287+
txPin = digitalPinToGPIONumber(txPin);
288+
285289
HSERIAL_MUTEX_LOCK();
286290
// First Time or after end() --> set default Pins
287291
if (!uartIsDriverInstalled(_uart)) {
@@ -317,9 +321,6 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
317321
}
318322
}
319323

320-
// map logical pins to GPIO numbers
321-
rxPin = digitalPinToGPIONumber(rxPin);
322-
txPin = digitalPinToGPIONumber(txPin);
323324
// IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified.
324325
// it will detach previous UART attached pins
325326

0 commit comments

Comments
 (0)