From 8ff2da70e85a46c95964cc873bfbc14767cae6f7 Mon Sep 17 00:00:00 2001 From: Luca Burelli Date: Tue, 1 Oct 2024 10:57:30 +0200 Subject: [PATCH] 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. --- cores/esp32/HardwareSerial.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/cores/esp32/HardwareSerial.cpp b/cores/esp32/HardwareSerial.cpp index 136876d143e..178f69ca9bb 100644 --- a/cores/esp32/HardwareSerial.cpp +++ b/cores/esp32/HardwareSerial.cpp @@ -282,6 +282,10 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in } #endif + // map logical pins to GPIO numbers + rxPin = digitalPinToGPIONumber(rxPin); + txPin = digitalPinToGPIONumber(txPin); + HSERIAL_MUTEX_LOCK(); // First Time or after end() --> set default Pins if (!uartIsDriverInstalled(_uart)) { @@ -317,9 +321,6 @@ void HardwareSerial::begin(unsigned long baud, uint32_t config, int8_t rxPin, in } } - // map logical pins to GPIO numbers - rxPin = digitalPinToGPIONumber(rxPin); - txPin = digitalPinToGPIONumber(txPin); // IDF UART driver keeps Pin setting on restarting. Negative Pin number will keep it unmodified. // it will detach previous UART attached pins