Skip to content

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

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 1 commit into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion micropython/usb/usb-device-cdc/manifest.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
metadata(version="0.1.0")
metadata(version="0.1.1")
require("usb-device")
package("usb")
10 changes: 7 additions & 3 deletions micropython/usb/usb-device-cdc/usb/device/cdc.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def init(
if flow != 0:
raise NotImplementedError # UART flow control currently not supported

if not (txbuf and rxbuf):
raise ValueError # Buffer sizes are required
if not (txbuf and rxbuf >= _BULK_EP_LEN):
raise ValueError # Buffer sizes are required, rxbuf must be at least one EP

self._timeout = timeout
self._wb = Buffer(txbuf)
Expand Down Expand Up @@ -330,7 +330,11 @@ def _wr_cb(self, ep, res, num_bytes):
def _rd_xfer(self):
# Keep an active data OUT transfer to read data from the host,
# whenever the receive buffer has room for new data
if self.is_open() and not self.xfer_pending(self.ep_d_out) and self._rb.writable():
if (
self.is_open()
and not self.xfer_pending(self.ep_d_out)
and self._rb.writable() >= _BULK_EP_LEN
):
# Can only submit up to the endpoint length per transaction, otherwise we won't
# get any transfer callback until the full transaction completes.
self.submit_xfer(self.ep_d_out, self._rb.pend_write(_BULK_EP_LEN), self._rd_cb)
Expand Down
Loading