cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_PCD_ConnectCallback() is not called on USB connection

AlaaM
Associate III

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!

1 ACCEPTED SOLUTION

Accepted Solutions
AlaaM
Associate III

Thanks. Eventually I followed the solution here:

https://community.st.com/s/question/0D50X00009XkXEESA3/which-function-can-detect-stm32f413-usbcdc-connected-or-disconnected

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).

View solution in original post

4 REPLIES 4

Do you have VBUS pin connected and VBUS detection (or HNP/SRP) enabled?

JW

AlaaM
Associate III

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

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

AlaaM
Associate III

Thanks. Eventually I followed the solution here:

https://community.st.com/s/question/0D50X00009XkXEESA3/which-function-can-detect-stm32f413-usbcdc-connected-or-disconnected

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).