Skip to content

Commit 0f9c0eb

Browse files
committed
Add methods to change Rx/Tx pins
Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
1 parent 15e8bdd commit 0f9c0eb

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

cores/arduino/HardwareSerial.cpp

+16
Original file line numberDiff line numberDiff line change
@@ -338,3 +338,19 @@ size_t HardwareSerial::write(uint8_t c)
338338

339339
return 1;
340340
}
341+
342+
void HardwareSerial::setRx(uint32_t _rx) {
343+
_serial.pin_rx = digitalPinToPinName(_rx);
344+
}
345+
346+
void HardwareSerial::setTx(uint32_t _tx) {
347+
_serial.pin_tx = digitalPinToPinName(_tx);
348+
}
349+
350+
void HardwareSerial::setRx(PinName _rx) {
351+
_serial.pin_rx = _rx;
352+
}
353+
354+
void HardwareSerial::setTx(PinName _tx){
355+
_serial.pin_tx = _tx;
356+
}

cores/arduino/HardwareSerial.h

+5
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ class HardwareSerial : public Stream
119119
using Print::write; // pull in write(str) and write(buf, size) from Print
120120
operator bool() { return true; }
121121

122+
void setRx(uint32_t _rx);
123+
void setTx(uint32_t _tx);
124+
void setRx(PinName _rx);
125+
void setTx(PinName _tx);
126+
122127
// Interrupt handlers
123128
static void _rx_complete_irq(serial_t* obj);
124129
static int _tx_complete_irq(serial_t* obj);

0 commit comments

Comments
 (0)