Skip to content

Commit 6fd974e

Browse files
committed
fix(serial): use defined pins when not mapped on Serial
Signed-off-by: Frederic Pillon <[email protected]>
1 parent 865e554 commit 6fd974e

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

cores/arduino/HardwareSerial.cpp

+16-5
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,22 @@ HardwareSerial::HardwareSerial(void *peripheral, HalfDuplexMode_t halfDuplex)
265265
setTx(PIN_SERIALLP2_TX);
266266
} else
267267
#endif
268-
// else get the pins of the first peripheral occurrence in PinMap
269-
{
270-
_serial.pin_rx = pinmap_pin(peripheral, PinMap_UART_RX);
271-
_serial.pin_tx = pinmap_pin(peripheral, PinMap_UART_TX);
272-
}
268+
#if defined(PIN_SERIAL_TX)
269+
// If PIN_SERIAL_TX is defined but Serial is mapped on other peripheral
270+
// (usually SerialUSB) use the pins defined for specified peripheral
271+
// instead of the first one found
272+
if ((pinmap_peripheral(digitalPinToPinName(PIN_SERIAL_TX), PinMap_UART_TX) == peripheral)) {
273+
#if defined(PIN_SERIAL_RX)
274+
setRx(PIN_SERIAL_RX);
275+
#endif
276+
setTx(PIN_SERIAL_TX);
277+
} else
278+
#endif
279+
{
280+
// else get the pins of the first peripheral occurrence in PinMap
281+
_serial.pin_rx = pinmap_pin(peripheral, PinMap_UART_RX);
282+
_serial.pin_tx = pinmap_pin(peripheral, PinMap_UART_TX);
283+
}
273284
if (halfDuplex == HALF_DUPLEX_ENABLED) {
274285
_serial.pin_rx = NC;
275286
}

0 commit comments

Comments
 (0)