Skip to content

usbhost: a flash drive in the GIGA's USB-A port is listed and mounts - #403

Merged
bdbarnett merged 2 commits into
mainfrom
giga-usbhost-enum-retry
Nov 10, 2026
Merged

bdbarnett merged 2 commits into
mainfrom
giga-usbhost-enum-retry

Conversation

@bdbarnett

@bdbarnett bdbarnett commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

A USB flash drive plugged straight into the Arduino GIGA R1's USB-A port is now listed and mounts. Before, usbhost_simpletest.py printed 0 USB device(s) found with the drive in the port, however long it waited.

The port's power and the host controller were fine: with the host started, the port showed a full-speed device connected and enabled, and the host sent its first SETUP. The drive didn't answer it. It is still starting up when TinyUSB resets it 150 ms after it appears: register-level tries on the board showed it ignoring the device descriptor request 10 ms after that reset and answering 20 ms after it, and answering at once from then on. TinyUSB's root port gets one enumeration, so after that failure it never tried again and the drive stayed connected and unlisted. A new patch, patches/lib-tinyusb/0002, posts the attach again after a failed enumeration on a root port that still has a device, up to three times, so the port is debounced, reset and enumerated anew; later TinyUSB releases have the same root-port retry. It also closes dev0's control endpoint after a failure before addressing, which every retry would otherwise leak. Devices behind a hub were never affected: the hub's next port status change already retries them.

On the GIGA with the Display Shield, this branch's firmware (built with displayif, lvgl, audiodsp, audioif, ulab and usbhost) with a PNY 8 GB FAT drive in the USB-A port: the drive attaches about 520 ms after usb.core.start() in three of three starts, the simpletest prints 1 USB device(s) found and 154b:009f, host_enum.py lists it with its strings, and usb_drive_mount.py mounts it read-only and lists its files. The new tests/test_tuh_enum_retry.c builds TinyUSB's host stack (at the commit the pinned MicroPython uses, with our patches) on a PC over a fake controller: a drive that ignores its first 300 ms has to mount, a dead device has to stop after its retries with no endpoint left open, and a ready device has to mount on the first reset. CI runs it, and runs it again without 0002 to check that it fails. With the host running, three power cycles of the port (_usbhost.host_port_cycle(), the nearest thing to a replug the board can do itself) each gave a detach and an attach 515 ms later. Not tried: a drive pulled out and plugged in by hand, and a drive behind a hub on this build.

A USB flash drive plugged straight into the Arduino GIGA R1's USB-A port
was never listed: usbhost_simpletest.py printed "0 USB device(s) found".
The drive is still starting up when TinyUSB resets it 150 ms after it
appears, so it doesn't answer the first device descriptor request, and
TinyUSB gave up on the port after that one attempt. A new patch,
patches/lib-tinyusb/0002, resets and enumerates a root port again after a
failed attach, up to three times, as later TinyUSB releases do.

On the GIGA with a PNY 8 GB drive in the port, the drive now attaches about
520 ms after usb.core.start(), the simpletest lists 154b:009f and
usb_drive_mount.py lists its files. test_tuh_enum_retry.c runs TinyUSB's
host stack on a PC over a fake controller and a drive that ignores its
first 300 ms; CI runs it with the patch, and checks that it fails without.
The usbhost workflow builds test_tuh_enum_retry.c against TinyUSB at the
commit the pinned MicroPython uses: with patches/lib-tinyusb/ applied it
has to pass, and with only 0001 it has to fail. The simpletest's and
usb_drive_mount.py's Tested on lines add the GIGA R1 run with a PNY drive
in its USB-A port.
@bdbarnett
bdbarnett merged commit 9a241aa into main Nov 10, 2026
14 checks passed
@bdbarnett
bdbarnett deleted the giga-usbhost-enum-retry branch November 10, 2026 23:27
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.

1 participant