Skip to content

Repeated hub connect events can leak devices #3073

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

Open
1 task done
tannewt opened this issue Apr 10, 2025 · 3 comments · Fixed by #3104
Open
1 task done

Repeated hub connect events can leak devices #3073

tannewt opened this issue Apr 10, 2025 · 3 comments · Fixed by #3104

Comments

@tannewt
Copy link
Collaborator

tannewt commented Apr 10, 2025

Operating System

Linux

Board

Fruit Jam

Firmware

CircuitPython using TinyUSB commit: 60e6d53

What happened ?

An assertion occurred when TinyUSB ran out of device numbers.

How to reproduce ?

Plug in the LS mouse from the Adafruit shop: https://www.adafruit.com/product/2025 into the Fruit Jam.

For some reason, the onboard hub detects brief USB device disconnects. It emits the port connection change each time it does. By the time the status is read the connection state is 1 again. This triggers TinyUSB to reset the port and start enumeration:

tinyusb/src/host/hub.c

Lines 432 to 446 in 865e348

if (p_hub->port_status.status.connection) {
// Reset port if attach event
hub_port_reset(daddr, port_num, connection_port_reset_complete, 0);
} else {
// submit detach event
const hcd_event_t event = {
.rhport = usbh_get_rhport(daddr),
.event_id = HCD_EVENT_DEVICE_REMOVE,
.connection = {
.hub_addr = daddr,
.hub_port = port_num
}
};
hcd_event_handler(&event, false);
}

However, because connection is 1 again, it never detaches the old device on the port. This leaks device numbers and generally device state. The device itself won't respond because it's been reset and given a new, different device number.

Debug Log as txt file (LOG/CFG_TUSB_DEBUG=2)

This is just selective logging of the status change bits and status report for the port.

Serial console setup
[1:] USBH Device Attach
  Hub Status Change = 0x08
  HUB connection change addr = 5 port = 3
  BITS change 0001 status 0301
  HUB ccccc addr = 5 port = 3
[1:] USBH Device Attach
lun 1 is not writable
lun 1 is not writable
lun 1 is not writable
lun 1 is not writable
  Hub Status Change = 0x08
  HUB connection change addr = 5 port = 3
  BITS change 0001 status 0301
  HUB ccccc addr = 5 port = 3
[1:] USBH Device Attach
  Hub Status Change = 0x08
  HUB connection change addr = 5 port = 3
  BITS change 0001 status 0301
  HUB ccccc addr = 5 port = 3
[1:] USBH Device Attach
XR_*=1
  Hub Status Change = 0x08
  HUB connection change addr = 5 port = 3
  BITS change 0001 status 0301
  HUB ccccc addr = 5 port = 3
[1:] USBH Device Attach
XR_*=1

Screenshots

No response

I have checked existing issues, dicussion and documentation

  • I confirm I have checked existing issues, dicussion and documentation.
@hathach
Copy link
Owner

hathach commented Apr 11, 2025

seems like an deboucing issue, I will look at this, and order the mouse for testing if needed

@HiFiPhile
Copy link
Collaborator

Me too I was looking at enumerate handling without hub. Currently there are 2 issues related to blocked debouncing wait:

  • _usbh_q filled up
  • xfer complete event of previous enumeration attempt arrive at next enumeration

I'm testing by break down the delay into smaller chunk, so far it's more reliable:
HiFiPhile@22ea6ee

@hathach
Copy link
Owner

hathach commented May 5, 2025

still happend with sigma mouse + fruit jam, doing more tests to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants