Skip to content

usb.core: a read that times out keeps its transfer, so no packet is lost - #745

Merged
bdbarnett merged 1 commit into
mainfrom
usb-core-reads-keep-transfer
Nov 21, 2026
Merged

bdbarnett merged 1 commit into
mainfrom
usb-core-reads-keep-transfer

Conversation

@bdbarnett

Copy link
Copy Markdown
Contributor

Device.read() now says what happens to a read that times out on usbhost firmware that keeps the transfer armed (PyDevices/omnipython-builds#625). The transfer stays armed, the next read collects whatever the device sends, and a zero-length packet ends a read without a timeout and gives 0. On older firmware, a read that raises USBTimeoutError still cancels its transfer, and the docstring says so. The read code itself is unchanged: its 250 ms steps already raise and retry, and on the new firmware those steps no longer cancel anything.

The fake _usbhost in tests/test_usb_host_streams.py can now script reads. Two new tests check that a read with no timeout rides through timeouts in 250 ms steps and returns the packet, and that a zero-length packet ends it with 0 rather than another wait. python3 -m unittest tests.test_usb_host_streams passes: 45 tests.

On hardware, with omnipython-builds#625 on an ESP32-P4: before it, 32 KB flash drive reads with 1 ms raising timeouts lost 4.58 MB in 200 commands. With it, 1200 commands were byte-exact.

Fixes #742 together with PyDevices/omnipython-builds#625.

With usbhost firmware that leaves a timed-out IN transfer armed, the
default read's quarter-second steps and a raising timeout no longer cancel
a transfer the device is filling. The docstring says so, and the tests pin
that the default read rides through timeouts and returns a zero-length
packet as 0.
@bdbarnett
bdbarnett merged commit 199cd4b into main Nov 21, 2026
6 checks passed
@bdbarnett
bdbarnett deleted the usb-core-reads-keep-transfer branch November 21, 2026 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

usb.core: a read that times out can drop a packet the device already sent

1 participant