Skip to content

feat(uart): support UART Tx, Rx and Data invert function #2701

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

Merged
merged 1 commit into from
Mar 31, 2025

Conversation

ndoo
Copy link
Contributor

@ndoo ndoo commented Mar 27, 2025

Fixes:
See also: #1418

Summary

This enables UART Tx, Rx and data invert function on STM32 families that support it.

In order to enable Tx, Rx and/or data invert, call respectively:

Serial1.setTxInvert();
Serial1.setRxInvert();
Serial1.setDataInvert();

This PR fixes/implements the following bugs/features

This adds a feature exposed by the native STM32 HAL & (some) hardware.

Validation

  • Ensure CI build is passed.
  • Tested a sketch with following lines of code:
    HardwareSerial sdiSerial = HardwareSerial(PA2);
    sdiSerial.setTxInvert();
    sdiSerial.begin(1200, SERIAL_7E1);
    

Closing issues

Closes #1160 #2669

@ndoo ndoo marked this pull request as ready for review March 27, 2025 15:14
@ndoo
Copy link
Contributor Author

ndoo commented Mar 27, 2025

@ndoo ndoo marked this pull request as draft March 28, 2025 02:07
@ndoo
Copy link
Contributor Author

ndoo commented Mar 28, 2025

Not sure if it actually works, marking as Draft again.

Squashed in a fixup for missing

    huart->AdvancedInit.RxPinLevelInvert = UART_ADVFEATURE_RXINV_ENABLE;
    huart->AdvancedInit.TxPinLevelInvert = UART_ADVFEATURE_TXINV_ENABLE;

@ndoo
Copy link
Contributor Author

ndoo commented Mar 28, 2025

Please let me know if the code flow makes sense in uart.c. Thank you.

@fpistm
Copy link
Member

fpistm commented Mar 28, 2025

Hi @ndoo
Thanks for the PR.
Will review it soon.

@fpistm fpistm added the enhancement New feature or request label Mar 28, 2025
@fpistm fpistm added this to the 2.11.0 milestone Mar 28, 2025
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ndoo
Thanks for this PR (well made 😉)
Some comments to address (open to discussion).
In addition, it would be fine to add new methods in the keywords.txt.
Could you also write doc about its usage to be added in the Wiki ?

@github-project-automation github-project-automation bot moved this from In progress to Needs review in STM32 core based on ST HAL Mar 28, 2025
@ndoo
Copy link
Contributor Author

ndoo commented Mar 28, 2025

Thanks for the review. Since I seem to be headed in the right direction, I will extend this to invert data as well, for completeness.

FWIW, I had my sketch freeze trying to read from serial, but let me debug over SWD after everything is done.

@ndoo
Copy link
Contributor Author

ndoo commented Mar 28, 2025

Force-pushed with the requested code changes. Workflows are still running.

I have to go to bed, but I will take a look at keywords.txt (which?) and updating the Wiki tomorrow.

@ndoo ndoo requested a review from fpistm March 28, 2025 16:52
This enables UART Tx, Rx and data invert function on STM32 families that support it.

In order to enable Tx, Rx and/or data invert, call respectively:

```c++
Serial1.setTxInvert();
Serial1.setRxInvert();
Serial1.setDataInvert();
```

Fixes: stm32duino#1160 stm32duino#2669
See also: stm32duino#1418

Signed-off-by: Andrew Yong <[email protected]>
@ndoo
Copy link
Contributor Author

ndoo commented Mar 29, 2025

Done updating keywords.txt - now having a look at writing for the Wiki.

ndoo added a commit to ndoo/stm32duino_wiki_contrib that referenced this pull request Mar 29, 2025
@ndoo ndoo marked this pull request as ready for review March 29, 2025 06:33
@ndoo
Copy link
Contributor Author

ndoo commented Mar 29, 2025

Wiki PR: stm32duino/wiki_contrib#2

Taking PR out of draft. Do let me know if anything was missed. Cheers!

ndoo added a commit to ndoo/stm32duino_wiki_contrib that referenced this pull request Mar 29, 2025
@ndoo ndoo changed the title feat(uart): support UART Tx Rx invert function feat(uart): support UART Tx, Rx & Data invert function Mar 30, 2025
@ndoo ndoo changed the title feat(uart): support UART Tx, Rx & Data invert function feat(uart): support UART Tx, Rx and Data invert function Mar 30, 2025
Copy link
Member

@fpistm fpistm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ndoo

@github-project-automation github-project-automation bot moved this from Needs review to Reviewer approved in STM32 core based on ST HAL Mar 31, 2025
@fpistm fpistm linked an issue Mar 31, 2025 that may be closed by this pull request
@fpistm fpistm merged commit 3a60776 into stm32duino:main Mar 31, 2025
24 checks passed
@github-project-automation github-project-automation bot moved this from Reviewer approved to Done in STM32 core based on ST HAL Mar 31, 2025
@fpistm fpistm mentioned this pull request Mar 4, 2025
4 tasks
fpistm pushed a commit to stm32duino/wiki_contrib that referenced this pull request Mar 31, 2025
@fpistm fpistm mentioned this pull request Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

Support U[S]ART Inversion on STM32U0 Support for UART RX/TX level inversion on F3/F7 platforms
2 participants