Skip to main content
AlaaM
Associate III
November 21, 2018
Solved

HAL_PCD_ConnectCallback() is not called on USB connection

  • November 21, 2018
  • 4 replies
  • 2700 views

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!

    This topic has been closed for replies.
    Best answer by AlaaM

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

    4 replies

    waclawek.jan
    Super User
    November 21, 2018

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

    JW

    AlaaM
    AlaaMAuthor
    Associate III
    November 21, 2018

    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

    waclawek.jan
    Super User
    November 21, 2018

    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
    AlaaMAuthorBest answer
    Associate III
    November 22, 2018

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