Skip to content

esp32/uart: Add flow keyword argument to enable hardware flow control.#6902

Closed
willsowerbutts wants to merge 2 commits intomicropython:masterfrom
willsowerbutts:master
Closed

esp32/uart: Add flow keyword argument to enable hardware flow control.#6902
willsowerbutts wants to merge 2 commits intomicropython:masterfrom
willsowerbutts:master

Conversation

@willsowerbutts
Copy link
Copy Markdown
Contributor

@willsowerbutts willsowerbutts commented Feb 14, 2021

This enables optional support for the hardware UART to use the RTS
and/or CTS pins for flow control.

The new "flow" constructor keyword specifies a bitmask of RTS and CTS.

Previously it was possible to specify which pins to use for the RTS and
CTS signals, but hardware flow control was never functional: CTS was not
checked before transmitting bytes, and RTS was always driven high
(signalling no buffer space available). With this patch, CTS and RTS
both operate as expected.

Signed-off-by: Will Sowerbutts will@sowerbutts.com

@willsowerbutts
Copy link
Copy Markdown
Contributor Author

This differs from #5608 because flow control is not enabled implicitly when the RTS/CTS pins are specified, only when the caller explicitly requests it with the new "flow" constructor keyword.

@robert-hh
Copy link
Copy Markdown
Contributor

Yes, we had that discussion in the PR. My point was more, that this PR and another one for this feature is stalling since then.

@willsowerbutts
Copy link
Copy Markdown
Contributor Author

Well I hope one of them gets merged, hardware flow control is broken on esp32. I'm open to suggestions for any way that I can help, I'd love to see this fixed as my project depends upon it.

@willsowerbutts willsowerbutts force-pushed the master branch 3 times, most recently from 3fe789d to c1e5be4 Compare February 14, 2021 23:05
@willsowerbutts
Copy link
Copy Markdown
Contributor Author

willsowerbutts commented Feb 14, 2021

I took another look at this, and at the other attempts at hardware flow control (#5608 and #5567), trying to learn from the previous feedback.

I've updated the new "flow" constructor keyword parameter to use constants named "RTS" and "CTS" (without the "FLOW_" prefix I used previously) in order to match what the STM32 port already does as closely as possible.

I've updated the machine.UART documentation to describe the interface offered by both STM32 and ESP32. I also explain briefly how RTS and CTS are used as the signal names alone can be confusing.

#5567 combines both UART modes and hardware flow control. These are two independent issues and I am not addressing UART modes in this patch. I believe many of the comments made about #5567 are addressed in this patch.

I've changed the RTS threshold from 50% to 75% of the UART hardware FIFO size, as recommended in #5608. I would be happy to add an additional keyword parameter to allow the user to specify this, but I believe 75% is a sensible value.

@willsowerbutts willsowerbutts force-pushed the master branch 2 times, most recently from 54bdd26 to 71d2916 Compare February 14, 2021 23:29
This enables optional support for the hardware UART to use the RTS
and/or CTS pins for flow control.

The new "flow" constructor keyword specifies a bitmask of RTS and/or
CTS. This matches the interface used by machine.UART on STM32.

Previously on ESP32 it was possible to specify which pins to use for the
RTS and CTS signals, but hardware flow control was never functional: CTS
was not checked before transmitting bytes, and RTS was always driven
high (signalling no buffer space available). With this patch, CTS and
RTS both operate as expected.

This also includes an update to the machine.UART documentation.

Signed-off-by: Will Sowerbutts <will@sowerbutts.com>
@tve
Copy link
Copy Markdown
Contributor

tve commented Feb 15, 2021

LGTM at a glance...

@dpgeorge
Copy link
Copy Markdown
Member

dpgeorge commented Aug 4, 2021

Thank you for the contribution, this looks really good. Merged in a367529 (with minor change to the docs, because rp2 now also supports flow).

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants