This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to detect if USB device is connected?

Does anyone know how I can detect if my USB device is connected to a Host or not?

Thx
Steven

Parents
  • Hi Steven,

    my suggestion for your case would be that you solder out USBLC6-4 ICs because they prevent VBUS going low when USB is disconnected.
    Also, you need to define USBD_VBUS_DETECT=1 for compilation of USBD_FS_STM32F2xx.c and USBD_HS_STM32F2xx.c which allows detection of VBUS changes.

    Now, if all previous is working as expected, from user API you would call USBD_Configured which would return "true" if device was connected and successfully enumerated otherwise it would return "false" (also in case you connect charger, your device would never get enumerated so this function will be retuning "false" all the time).

    For SOF variant, you would need to change USBD_FS_STM32F3xx.c and USBD_HS_STM32F3xx.c manually and add SOF interrupt handling in IRQ routine and provide information to your user application directly from IRQ routine.

Reply
  • Hi Steven,

    my suggestion for your case would be that you solder out USBLC6-4 ICs because they prevent VBUS going low when USB is disconnected.
    Also, you need to define USBD_VBUS_DETECT=1 for compilation of USBD_FS_STM32F2xx.c and USBD_HS_STM32F2xx.c which allows detection of VBUS changes.

    Now, if all previous is working as expected, from user API you would call USBD_Configured which would return "true" if device was connected and successfully enumerated otherwise it would return "false" (also in case you connect charger, your device would never get enumerated so this function will be retuning "false" all the time).

    For SOF variant, you would need to change USBD_FS_STM32F3xx.c and USBD_HS_STM32F3xx.c manually and add SOF interrupt handling in IRQ routine and provide information to your user application directly from IRQ routine.

Children