2018-11-21 12:30 AM
Hi,
I'm trying to capture a USB connection / disconnection event in STM32F722RE. The interrupt HAL_PCD_IRQHandler() is called when I connect / disconnect the device to the PC, but the flags USB_OTG_GINTSTS_SRQINT and USB_OTG_GINTSTS_OTGINT are never set, so the callbacks HAL_PCD_ConnectCallback() and HAL_PCD_DisconnectCallback() are never called.
What should be done in order to set the appropriate flags?
Thanks!
Solved! Go to Solution.
2018-11-21 11:38 PM
Thanks. Eventually I followed the solution here:
and it worked.
In summary: CDC_Init_FS() (in usbd_cdc_if.c) is called when the usb is plugged, and hUsbDeviceFS.dev_state becomes USBD_STATE_CONFIGURED. This is our connection indication.
For disconnection, HAL_PCD_SuspendCallback() is called (in usbd_conf.c).
2018-11-21 12:40 AM
Do you have VBUS pin connected and VBUS detection (or HNP/SRP) enabled?
JW
2018-11-21 12:56 AM
VBUS pin is not connected, and VBUS detection is disabled. When I enable VBUS detection by cubemx (Activate_VBUS: Enable sensing), the global interrupt HAL_PCD_IRQHandler() is not called anymore. Why is that?
Note: I need the USB only as device, not host.
Thanks
2018-11-21 03:33 AM
GINTSTS.SRQINT indicates VBUS activity, so if you don't use VBUS detection you won't see that being set.
Withough VBUS, the USB stack relies upon the host resetting the device when attached, i.e. the stack is reset/started upon GINTSTS.USBRST. There is no direct method for detecting detach, but it could be indirectly detected by missing regular SOFs.
> When I enable VBUS detection by cubemx (Activate_VBUS: Enable sensing), the global interrupt
> HAL_PCD_IRQHandler() is not called anymore. Why is that?
I don't know, I don't use Cube/CubeMX.
JW
2018-11-21 11:38 PM
Thanks. Eventually I followed the solution here:
and it worked.
In summary: CDC_Init_FS() (in usbd_cdc_if.c) is called when the usb is plugged, and hUsbDeviceFS.dev_state becomes USBD_STATE_CONFIGURED. This is our connection indication.
For disconnection, HAL_PCD_SuspendCallback() is called (in usbd_conf.c).