-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Fix pad assignments on atmel-samd UART #7616
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
Conversation
2a1d19a
to
6d51356
Compare
Thanks @dhalbert. I'll try this out out SAMD21 and SAM5x boards I have which expose the right pins for flow control. |
Test program I used to find working combinations, a variation on https://learn.adafruit.com/circuitpython-essentials/circuitpython-uart-serial#wheres-my-uart-2985036. Generates thousands of combinations, and takes a while to run. Includes cases where pins are import board
import busio
from microcontroller import Pin
def is_hardware_uart(tx, rx, rts, cts):
try:
p = busio.UART(tx, rx, rts=rts, cts=cts)
p.deinit()
return True
except ValueError:
return False
def get_unique_pins():
exclude = ['NEOPIXEL', 'APA102_MOSI', 'APA102_SCK']
pins = [pin for pin in [
getattr(board, p) for p in dir(board) if p not in exclude]
if isinstance(pin, Pin)]
unique = []
for p in pins:
if p not in unique:
unique.append(p)
return [None] + unique
for tx_pin in get_unique_pins():
for rx_pin in get_unique_pins():
if is_hardware_uart(tx_pin, rx_pin, None, None):
print(f"TX: {tx_pin}\tRX: {rx_pin}")
for rts_pin in get_unique_pins():
for cts_pin in get_unique_pins():
if is_hardware_uart(tx_pin, rx_pin, rts_pin, cts_pin):
print(f"\tRTS: {rts_pin}\tCTS: {cts_pin}") |
a3e7fab
to
2684aeb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Thank you for the quick fix
Will wait for @stonehippo to test before merging. |
Will merge for now since this is an 8.0.0 regression on a number of boards, breaking UART. @stonehippo we are still interested in your test results, of course! |
@dhalbert I finally got around to testing this out and RTS/CTS flow control seems to work as expected on both SAMD21 and SAMD51 boards where I could get at the correct pins for hardware flow control on a given board (e.g. Feather M0 Adalogger, MicroMod SAMD51). |
@stonehippo glad to hear it's working for you |
Fixes UART write does not work on QT Py SAMD21 with CircuitPython 8.x #7612.
SERCOM USART TXPO computation was not correct on SAMD21 for TX pins using pad 2, due to changes introduced in Implement hardware flow control on SAMD busio.UART #6434. SAMD21 and SAMx5x are different: SAMx5x does not allow pad 2 for TX. In addition, checking for allowed pins based on their pads was not as rigorous as it should have been. Code is somewhat restructured.
Signature for
busio.UART()
was missing several arguments and did not account forNone
values.Did more pin validation in
shared-bindings
busio.UART()
. Ensure pins are distinct, and that both TX and RX are not None. Removed now-redundant checks for TX and RX both being none inports/*/common-hal/busio/UART.c
.Tested that original bug (#7612) is now fixed. Did not test that flow control is working. Did verify that TXPO and RXPO are correct for a variety of pin choices, with and without RTS/CTS. It's not clear whether TXPO 0x2 is OK on SAMD51 if RTS and CTS are not used, but did the safe thing.
Also tested on a Metro M4, confirming that the standard TX and RX still work in both directions.
@stonehippo You may want to re-test with these changes.