Skip to content

Conversation

@rlevano77
Copy link

Add RS485 half-duplex communication support to the SAM0 UART driver
through optional GPIO-controlled transceiver enable pins.

Changes:

  • Add de-gpios and re-gpios properties to device tree binding for
    controlling RS485 transceiver Driver Enable and Receiver Enable pins
  • Implement GPIO control in poll, interrupt-driven, and async modes
  • Add RS485 flow control mode validation in runtime configuration
  • Automatically manage transmitter/receiver enable state during TX/RX
    operations
  • Initialize transceivers in receive mode by default

The implementation handles transceivers with separate or tied DE/RE pins
(specify only de-gpios when tied together). GPIO polarity is configurable
via device tree flags (GPIO_ACTIVE_HIGH/LOW).

Tested on: same54_xpro board

@github-actions
Copy link

Hello @rlevano77, and thank you very much for your first pull request to the Zephyr project!
Our Continuous Integration pipeline will execute a series of checks on your Pull Request commit messages and code, and you are expected to address any failures by updating the PR. Please take a look at our commit message guidelines to find out how to format your commit messages, and at our contribution workflow to understand how to update your Pull Request. If you haven't already, please make sure to review the project's Contributor Expectations and update (by amending and force-pushing the commits) your pull request if necessary.
If you are stuck or need help please join us on Discord and ask your question there. Additionally, you can escalate the review when applicable. 😊

@zephyrbot zephyrbot added area: Devicetree Bindings area: UART Universal Asynchronous Receiver-Transmitter area: Boards/SoCs platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM) labels Oct 29, 2025
@nandojve nandojve added this to the v4.4.0 milestone Oct 30, 2025
@nandojve
Copy link
Member

nandojve commented Nov 9, 2025

Hi @rlevano77 ,

This "Merge remote-tracking branch 'upstream/main" is not acceptable in Zephyr code base. You need to rebase on top of main only your commits.

This the merge commit, compliance checks and the tests so we can start review your PR.

@rlevano77
Copy link
Author

Hi @nandojve I have rebased my commit on top of main and removed the merge commit.
The PR now contains only RS485 changes with a clean linear history.
Please let me know if this is correct. Thank you!

Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

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

Hi @rlevano77 ,

Interesting work! Do you think it is possible to have a test ?
How do you suggest to validate code ?

@rlevano77
Copy link
Author

Hi @nandojve,

  1. Copyright: Simplified to remove feature descriptions
  2. Conditional compilation: Implemented using DT_ANY_INST_HAS_PROP_STATUS_OKAY(de_gpios) and DT_ANY_INST_HAS_PROP_STATUS_OKAY(re_gpios) - all RS485 code is now conditionally compiled only when these GPIOs are configured in the device tree
  3. Spacing: Added blank line between sections as requested
  4. Testing: Verified on SAME54 Xpro board with RS485 transceiver - functionality confirmed working
    I tested using the Zephyr's samples/drivers/uart/echo_bot. The setup included an RS-485 breakout board and a USB-RS485 adapter for PC connectivity. Tested cases with/without RS485 support.

The conditional compilation ensures zero flash and RAM overhead when RS485 GPIOs are not configured in the device tree.

@nandojve
Copy link
Member

nandojve commented Nov 29, 2025

Hi @rlevano77 ,

Overall changes seems to be OK!

Now,
1- create 1 commit with the atmel,sam0-uart.yaml changes. This should be the first commit.
2- squash all the other 3 commits as the second in the series with the uart_sam0.c changes.

Testing: Verified on SAME54 Xpro board with RS485 transceiver - functionality confirmed working
I tested using the Zephyr's samples/drivers/uart/echo_bot. The setup included an RS-485 breakout board and a USB-RS485 adapter for PC connectivity. Tested cases with/without RS485 support.

I'll ask you to commit in the PR exactly what you need to do. I mean, which is the shield and share any overlay that you create.
This helps in future if someone need to check this or want to test.

BTW, make sure CI is happy : )

Add de-gpios and re-gpios properties to support RS485 transceiver
control. These optional GPIOs control Driver Enable (DE) and
Receiver Enable (RE) pins for half-duplex RS485 communication.

Signed-off-by: Ricardo Levano <rlevano77@gmail.com>
@rlevano77
Copy link
Author

Hi @nandojve ,
The PR now contains the changes and additions requested.
Please let me know if any additional changes are needed.

Add optional RS485 transceiver control using de-gpios and re-gpios
device tree properties. The implementation includes:

- Conditional compilation using DT_ANY_INST_HAS_PROP_STATUS_OKAY
- Helper functions for DE/RE GPIO control
- Integration with UART poll_out and interrupt handlers
- Runtime configuration validation for RS485 flow control
- Zero flash/RAM overhead when GPIOs not configured

Testing: Verified on SAME54 Xpro board with RS485 transceiver using
Zephyr's samples/drivers/uart/echo_bot. Setup included RS-485 breakout
board and USB-RS485 adapter. Tested with and without RS485 support.

Signed-off-by: Ricardo Levano <rlevano77@gmail.com>
Add a sample application demonstrating RS485 transceiver control
using the SAM0 UART driver. The sample shows how to:

- Configure UART in RS485 mode at runtime
- Use de-gpios and re-gpios for transceiver control
- Implement echo bot with interrupt-driven RX and polling TX

The sample includes complete documentation and overlay for
SAME54 Xplained Pro board using SERCOM0 with DE/RE control
on PA22.

Hardware tested:
- SAME54 Xplained Pro board
- SparkFun RS-485 Transceiver Breakout
- DTECH USB-to-RS485 converter

Signed-off-by: Ricardo Levano <rlevano77@gmail.com>
@rlevano77
Copy link
Author

@nandojve
Fixed compliance issues (line spacing and indentation). Ready for re-review.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Dec 5, 2025

Copy link
Member

@nandojve nandojve left a comment

Choose a reason for hiding this comment

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

Very well done!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Boards/SoCs area: Devicetree Bindings area: Samples Samples area: UART Universal Asynchronous Receiver-Transmitter platform: Microchip SAM Microchip SAM Platform (formerly Atmel SAM)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants