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

Avoid discarding already read bytes on error #798

Merged
merged 1 commit into from
Jul 27, 2024
Merged

Conversation

jannic
Copy link
Member

@jannic jannic commented May 1, 2024

Closes: #782

It would be preferable to avoid the code duplication between UartPeripheral and Reader. However, before starting a bigger code restructuring, I'd like to get some feedback on the general approach:

  • Is it the right trade-off to reserve some memory in UartPeripheral and Reader to store the read error?
  • What are alternative approaches?
    • Ignore the issue, accept discarding bytes on error. (Might be acceptable, assuming that serial errors are rare and the received message is probably garbled anyway. Should be clearly documented.)
    • Don't implement embedded_io::Read at all. (Breaking change, lost functionality, IMHO not acceptable)
    • Don't implement embedded_io::Read directly on UartPeripheral and Reader, but instead on a separate wrapper type. (Breaking change, slightly less nice API, zero-cost when not using embedded_io::Read)

@jannic jannic marked this pull request as ready for review May 28, 2024 21:57
@thejpster
Copy link
Member

I think this is quite reasonable.

@thejpster
Copy link
Member

Leaving this for a second opinion. @9names ?

@ithinuel
Copy link
Member

If the UART has/is using a FIFO, I’m afraid there’s no way to tell when did the error occur.
So if we get a parity error for example, we cannot tell which byte is corrupted.

@jannic
Copy link
Member Author

jannic commented Jul 20, 2024

IIRC the error bits are also stored in the FIFO, together with the data words they belong to.

@9names
Copy link
Member

9names commented Jul 21, 2024

image

@9names
Copy link
Member

9names commented Jul 21, 2024

image

@jannic jannic merged commit 885de2e into rp-rs:main Jul 27, 2024
6 checks passed
@jannic jannic mentioned this pull request Aug 22, 2024
jannic added a commit to jannic/rp-hal that referenced this pull request Aug 24, 2024
The updates from rp-rs#798, rp-rs#837 and rp-rs#838 were only applied to rp2040-hal.
This patch ports them to rp235x-hal.
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.

embedded_io::serial::Reader implementations drop data on error
4 participants