Skip to content

make UART.write be blocking on SAMD; add timeout property #2331

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 5 commits into from
Nov 27, 2019

Conversation

dhalbert
Copy link
Collaborator

UART fixes and changes:

  • atmel-samd: UART.write() was inadvertently non-blocking, due to my misunderstanding the (poorly documented) ASF4 API. Fixes busio.UART write sometimes returns None #2263, I believe.
  • The same timeout value was used for read and write. A write timeout is not very useful, because we don't have flow control. Made timeout apply only to read. Note, for instance, that PySerial has separate read, write, and inter-character timeouts.
  • Added a get/set .timeout property so that the timeout can be changed after construction.
  • Fixed default timeout for board.UART(). It was 1000.0 seconds, should have been 1 second (leftover from msecs to msecs API change previously).

Tested on atmel-samd, nrf, and stm32f4. Not tested on spresense because I don't have one yet.

I tried making UART.write interruptible by ctrl-C on atmel-samd, but it causes the ASF4 driver to get irreversibly confused about whether it's completed the write or not, and there's no easy API call to reset it. It's not possible to have ctrl-C interrupts on some other ports anyway, so never mind.

@jepler if you want to review, feel free, but no obligation. Not sure how we should divvy up reviewing in the future.

@dhalbert dhalbert requested a review from tannewt November 27, 2019 18:06
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.

Overall this looks good. Just a couple small things that are related to the build failures.

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.

Looks good! Thank you!

@tannewt tannewt merged commit 83ecb1b into adafruit:master Nov 27, 2019
@dhalbert dhalbert deleted the uart-blocking-and-timeout branch December 12, 2019 21:39
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.

busio.UART write sometimes returns None
2 participants