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

usb-device-cdc: Fix lost data in read() path if short reads happened. #886

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

projectgus
Copy link
Contributor

@projectgus projectgus commented Jun 18, 2024

If the CDC receive buffer was full and some code read less than 64 bytes (wMaxTransferSize), the CDC code would submit an OUT transfer with N<64 bytes length to fill the buffer back up.

However if the host had more than N bytes to send then it would still send the full 64 bytes (correctly) in the transfer. The remaining (64-N) bytes would be lost.

Fix is to not send a new transfer until 64 bytes is free. Adds the restriction that CDCInterface rxbuf has to be at least 64 bytes.

Closes #885.

This work was funded through GitHub Sponsors.

If the CDC receive buffer was full and some code read less than 64 bytes
(wMaxTransferSize), the CDC code would submit an OUT transfer with N<64
bytes length to fill the buffer back up.

However if the host had more than N bytes to send then it would still send
the full 64 bytes (correctly) in the transfer. The remaining (64-N) bytes
would be lost.

Adds the restriction that CDCInterface rxbuf has to be at least 64 bytes.

Fixes issue micropython#885.

This work was funded through GitHub Sponsors.

Signed-off-by: Angus Gratton <[email protected]>
@dpgeorge dpgeorge force-pushed the bugfix/usb_cdc_short_reads branch from b43749a to 0a91a37 Compare July 3, 2024 07:18
@dpgeorge dpgeorge merged commit 0a91a37 into micropython:master Jul 3, 2024
4 checks passed
@dpgeorge
Copy link
Member

dpgeorge commented Jul 3, 2024

Thanks!

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.

Serial connections dropping characters, not flushing buffers
2 participants