From 6845c79ee15f7ee27941fc84e4e715eb95c5ef17 Mon Sep 17 00:00:00 2001 From: Frederic Pillon Date: Tue, 6 Dec 2022 10:29:43 +0100 Subject: [PATCH] fix(serial): use defined pins when not mapped on Serial Signed-off-by: Frederic Pillon --- cores/arduino/HardwareSerial.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/cores/arduino/HardwareSerial.cpp b/cores/arduino/HardwareSerial.cpp index 20d2a99377..3aba60253d 100644 --- a/cores/arduino/HardwareSerial.cpp +++ b/cores/arduino/HardwareSerial.cpp @@ -265,11 +265,22 @@ HardwareSerial::HardwareSerial(void *peripheral, HalfDuplexMode_t halfDuplex) setTx(PIN_SERIALLP2_TX); } else #endif - // else get the pins of the first peripheral occurrence in PinMap - { - _serial.pin_rx = pinmap_pin(peripheral, PinMap_UART_RX); - _serial.pin_tx = pinmap_pin(peripheral, PinMap_UART_TX); - } +#if defined(PIN_SERIAL_TX) + // If PIN_SERIAL_TX is defined but Serial is mapped on other peripheral + // (usually SerialUSB) use the pins defined for specified peripheral + // instead of the first one found + if ((pinmap_peripheral(digitalPinToPinName(PIN_SERIAL_TX), PinMap_UART_TX) == peripheral)) { +#if defined(PIN_SERIAL_RX) + setRx(PIN_SERIAL_RX); +#endif + setTx(PIN_SERIAL_TX); + } else +#endif + { + // else get the pins of the first peripheral occurrence in PinMap + _serial.pin_rx = pinmap_pin(peripheral, PinMap_UART_RX); + _serial.pin_tx = pinmap_pin(peripheral, PinMap_UART_TX); + } if (halfDuplex == HALF_DUPLEX_ENABLED) { _serial.pin_rx = NC; } pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy