Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(uart): support UART Tx Rx pin swap function #2601

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

fronders
Copy link

This enables UART Tx and Rx pin swap function on STM32 families that support it (F0, L0, L4, G0, G4, H7 etc.)

In order to enable pin swap, user just needs to swap the pins either when declaring HardwareSerial object:

//                      RX    TX
HardwareSerial Serial1(PA10, PA9); // uses normal pins
//                      RX    TX
HardwareSerial Serial1(PA9, PA10); // uses swapped pins

or by using setTx() and setRx() methods:

Serial1.setRx(PA9);  // normally it is a Tx pin
Serial1.setTx(PA10); // normally it is a Rx pin
Serial1.begin(9600);

If the chip does not support the swap, or the pins are incorrect, the library behaves the same way as before (throws an error for invalid pins).

The cool thing is that it even supports half-duplex mode on the normally Rx pin - the Rx pin is used for transmission and reception then. User can either use Rx == Tx trick as before or just provide a single pin definition

Fixes: #2538
See also: #1418

@fpistm fpistm marked this pull request as ready for review December 11, 2024 19:58
@fronders
Copy link
Author

Hi @fpistm, I'm finishing testing at the moment with different STM32 chips and will report back as soon as I'm done and things are ready to be merged :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

UART Tx/Rx Pin Swap
1 participant