2021-07-07 03:29 PM
I'm using a STM32L4A6 with OTG_FS peripheral. I use the USB driver from STM. I only get the suspend callback, but never resume, or connected, or disconnected callback. Suspend is not good indicator for plug in or out. Even USB cable plug in will also generate suspend event. I'd like to know when the device is plugged into or unplugged from a computer's USB port. How to do that? Thanks!
I'm using STM32 CubeL4 firmware package1.17.0 (and STM32L4xx HAL 1.13.0).
2021-07-07 04:19 PM
Detect VBUS presence. You can do it on any pin (after conditioning the VBUS voltage), not just the dedicated VBUS pin.
JW
2021-07-07 04:39 PM
Are you saying VBUS can be routed to a GPIO pin and then try to detect the pin to be 0 or 1? I checked out schematics it seems the VBUS pin (PA9 on the STM32L4A6) is not connected.
Also what are those call backs for - connected/disconnected callback?
2021-07-07 07:01 PM
You don't need to use the VBUS pin for this, you can use any GPIO pin, preferably with an inline resistor or other current limiting mechanism. You can set it up as EXTI and trigger on rising/falling edges to detect when the cable is connected/disconnected.
2021-07-07 09:39 PM
Ok, I see.
But if the VBUS from the cable actually is connected to the VBUS pin, then the USB driver library will automatically detect the presence and trigger those callbacks?
2021-07-07 10:05 PM
I don't think the ST USB peripheral drivers do anything with the VBUS signal. Could be wrong.
2021-07-08 12:43 AM
The VBUS detection behaviour is described in the OTG chapter of RM, for device, in Peripheral states/Powered state subchapter/section. If VBUS detection is enabled (by OTG_GCCFG.VBDEN), it will automatically attach/detach the DP pullup (provided it's not forced by OTG_GUSBCFG.FDMOD or not switched to host by either OTG_GUSBCFG.FHMOD or by the ID pin being pulled low) and throw OTG_GINTSTS.SRQINT interrupt.
As said above, you can use any pin to detect VBUS presence and handle the pullup and USB machine "manually".
I don't care what's in Cube, I don't use it (other than an auxiliary source of information to RM). It's open source, you can look it up yourself.
JW