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

Implement hardware flow control on SAMD busio.UART #6434

Merged
merged 3 commits into from
May 26, 2022
Merged

Implement hardware flow control on SAMD busio.UART #6434

merged 3 commits into from
May 26, 2022

Conversation

stonehippo
Copy link

@stonehippo stonehippo commented May 25, 2022

The current atmel-samd port does not support RTS/CTS for hardware flow control, even though the underlying SAMx2x/SAMx5x chips are capable of using this mode on async UARTs. This change enables hardware flow control by allowing assignment of pins to RTS/CTS, and enabling selection of the correct pad configuration for the pinout via the CTRLA.TXPO register.

An example of working code looks like this (using the pin configs on the Sparkfun SAMD51 MicroMod):

import board
import busio

# On the SAMD51 MicroMod, SERCOM5 is used for UART1, and the pins that would be assigned to RTS/CTS are PB00/PB001
uart = busio.UART(board.UART_TX1, board.UART_RX1, cts=board.PWM0, rts=board.A1)
uart.write(bytearray("hello")) # Write 'hello' to the UART
uart.readline() # gets whatever is being written from the other side

I have tested this with on the MicroMod, and it works as expected when the other side is set up for hardware flow control. To fully confirm it, I disabled hardware flow control in picocom, attached to an FTDI USB-to-serial board wired to the UART RX/TX/RTS/CTS lines on the MicroMod, then used picocom's toggle features to assert RTS and CTS to prevent reads or writes as desired. I also confirmed that normal operation of the UART when hardware flow control is not specified works as it did prior to this change.

A note re confirming this PR: while RTS/CTS flow control is available on the SAMx2x/SAMx5x chips, it's only happenstance that a given dev board exposes the correct pins used for the given SERCOM underlying the UART(s) exposed via hardware. I found that several boards did not have the pins I need even connected. The MicroMod was one where I was able to find the right pads connected to pins.

tannewt
tannewt previously approved these changes May 25, 2022
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Code looks good! Thank you! 🤞 all of the builds fit.

ports/atmel-samd/common-hal/busio/UART.c Outdated Show resolved Hide resolved
Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

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

Thanks for the update!

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.

2 participants