Skip to content

Commit

Permalink
fix(serial): use defined pins when not mapped on Serial
Browse files Browse the repository at this point in the history
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
  • Loading branch information
fpistm committed Dec 6, 2022
1 parent 865e554 commit 6fd974e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions cores/arduino/HardwareSerial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6fd974e

Please sign in to comment.