Skip to content

Commit 2d6fcef

Browse files
committed
fix(HardwareSerial): fix pin remapping in begin()
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 2.x via 9b4622d, but was exposed by the proper pin muxing support that is present in the 3.x core. Move the pin remapping function calls earlier in the begin() function to fix this issue.
1 parent b05f18d commit 2d6fcef

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
@@ -291,6 +291,10 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
291291
}
292292
#endif
293293

294+
// map logical pins to GPIO numbers
295+
rxPin = digitalPinToGPIONumber(rxPin);
296+
txPin = digitalPinToGPIONumber(txPin);
297+
294298
HSERIAL_MUTEX_LOCK();
295299
// First Time or after end() --> set default Pins
296300
if (!uartIsDriverInstalled(_uart)) {
@@ -326,9 +330,6 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in
326330
}
327331
}
328332

329-
// map logical pins to GPIO numbers
330-
rxPin = digitalPinToGPIONumber(rxPin);
331-
txPin = digitalPinToGPIONumber(txPin);
332333
// IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified.
333334
// it will detach previous UART attached pins
334335

0 commit comments

Comments
 (0)