stm32-usb: Use the susprdy bit to show disconnect#3944
stm32-usb: Use the susprdy bit to show disconnect#3944drbartling wants to merge 2 commits intoembassy-rs:mainfrom
Conversation
The USB peripheral does not require a VBUS connection. When USB is unplugged from a self-powered USB device, the existing drivers and hardware set the susprdy and the suspen bits. It's also notable that the frame number stops counting. I chose to use the susprdy bit as a way to identify when USB is unplugged to allow USB writes or reads to return an error. references: embassy-rs#3740 https://www.st.com/resource/en/reference_manual/rm0444-stm32g0x1-advanced-armbased-32bit-mcus-stmicroelectronics.pdf p. 1285
|
This is not correct, the SUSPRDY bit indicates suspend, not disconnect. in USB, "suspend" and "disconnect" are different things. It's only on actual disconnect that we should disable endpoints. On suspend, the host expects everything to stay as-is when it unsuspends. Here's how you tell which state you're in: VBUS present, activity on the bus -> USB is active the USB peripheral only looks at the DP/DM lines so it can only tell whether there's activity on the bus or not. To distinguish "suspended" and "disconnected" states you need to wire VBUS to a GPIO. Some boards don't wire it, in which case it's simply impossible to support the "disconnected" state, so it's simply impossible to implement a self-powered usb device in a compliant way. The correct fix would be to add "vbus detection" support to the driver via gpio. see previous discusison in #3629 (for rp, but the problem is exactly the same as here) |
The USB peripheral does not require a VBUS connection. When USB is unplugged from a self-powered USB device, the existing drivers and hardware set the susprdy and the suspen bits.
It's also notable that the frame number stops counting.
I chose to use the susprdy bit as a way to identify when USB is unplugged to allow USB writes or reads to return an error.
references:
#3740
https://www.st.com/resource/en/reference_manual/rm0444-stm32g0x1-advanced-armbased-32bit-mcus-stmicroelectronics.pdf p. 1285