Kaleidoscope icon indicating copy to clipboard operation
Kaleidoscope copied to clipboard

Model 01 doesn't always stay suspended

Open tlyu opened this issue 1 year ago • 2 comments

Describe the bug The Model 01 will turn off its LEDs for a normal USB suspend if it's still attached to a host. However, when connected to a powered USB hub, and the hub is then disconnected from a non-suspended host, the Model 01 will turn off its LEDs, and then turn them back on in less than a second. The Model 100 doesn't have this behavior.

To Reproduce Connect a Model 01 to a host through a powered hub. Disconnect the powered hub from the host.

Expected behavior The Model 01 should keep its LEDs off when a powered hub that it's connected to is disconnected from a host.

Environment (please complete the following information):

  • OS: macOS
  • Version 10.15.7 (19H2026)
  • Device Model 01

Additional context N/A

tlyu avatar Oct 02 '22 23:10 tlyu

Some close reading of the ATmega32U4 datasheet suggests that the Arduino AVR core might have a very old bug where it's using the wrong interrupt flag to detect a wakeup/resume condition. It might be using the wakeup interrupt flag (WAKEUPI), which detects any bus activity, possibly including a long-SE0 (reset) condition. There's a different interrupt flag (EORSMI) that detects an end-of-resume status.

I think (but haven't confirmed) that a self-powered hub sets its downstream ports to SE0 when disconnected from the host.

tlyu avatar Oct 03 '22 14:10 tlyu

Update: hub is a Belkin USB 3 hub with apparently some battery charging capability. When disconnected from a host, it sets D- to an intermediate value, and the AVR core sees it as a wakeup (because WAKEUPI triggers on any non-idle signal). A quick patch to use EORSMI seems to partially work, but doesn't always stay suspended when connected to hub when the hub is powered, but disconnected from the host. I'm guessing SUSPI won't reliably trigger unless it detects an electrical bus idle condition (D+ high, D- low), rather than a lack of SOF packets.

tlyu avatar Dec 21 '23 18:12 tlyu