← index #993PR #1080
Likely Duplicate · high · value 4.251
QUERY · ISSUE

usb-device-cdc raises TypeError when using default timeout of None and going to block

openby aylen384opened 2025-03-30updated 2025-03-30

https://github.com/micropython/micropython-lib/blob/master/micropython/usb/usb-device-cdc/usb/device/cdc.py#L368
and same for read function.

            # check for timeout
            if time.ticks_diff(time.ticks_ms(), start) >= self._timeout:
                return len(buf) - len(mv)

            machine.idle()

should be something like this:

            if isinstance(self._timeout, int) and time.ticks_diff(time.ticks_ms(), start) >= self._timeout:
CANDIDATE · PULL REQUEST

usb-device-cdc: Fix default timeout in CDCInterface.init().

openby andrewleechopened 2026-02-15updated 2026-02-15

Summary

CDCInterface is broken when constructed with default arguments — calling read(), write(), readinto(), or flush() raises TypeError: unsupported types for __ge__: 'int', 'NoneType' because self._timeout ends up as None.

__init__ sets self._timeout = 1000 then immediately calls self.init(**kwargs). The init() method has timeout=None as default and unconditionally assigns self._timeout = timeout, overwriting the 1000 with None. All the stream methods then fail on time.ticks_diff(...) >= self._timeout.

Fix is changing the default parameter from timeout=None to timeout=1000, consistent with how the other init parameters (baudrate, bits, parity, stop) all carry their real defaults in the signature.

Testing

Tested on ESP32-S3 as USB CDC device with an MIMXRT1170-EVK as USB host. Confirmed cdc._timeout is now 1000 after default construction and read(), write(), readinto() all work without error. Also verified explicit timeout= parameter still takes effect.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied