cancel
Showing results for 
Search instead for 
Did you mean: 

How to check if USB2.0 HS MSC is connected or not ?

taz1000
Associate III
Posted on October 17, 2016 at 15:50

Is there any method ( library function, variable, or other) to check 

if USB2.0 HS MSC connection is established or not ? 

I want to turn-on / off a LED on the board upon USB connection status. 

THANKS.... 
1 REPLY 1
Walid FTITI_O
Senior II
Posted on October 18, 2016 at 12:49

Hi chun.dan

,

If you want to know if you have a device is either connected or disconnected, use can a global variable inside both  HAL_PCD_ConnectCallback() and

HAL_PCD_DisconnectCallback()

.

If USBD_LL_DevConnected status is USBD_OK you should change the value of the global variable to 1 (or whatever you prefer). 

You should write the code to update this global variable into every related callbacks.

HAL_PCD_CconnectCallback() is called inside HAL_PCD_IRQHandler() (stm32f4xx_hal_pcd.c), by GOTGINT.SEDET (session end detected) interrupt

.

To ensure this interrupt is fired you need the following requirement:

  • VBUS (PA9) pin should be connected to VBUS (5V) pin of the USB connector (for OTG_HS on on-chip FS PHY, VBUS (PB13) pin)
  • Enable the Vbus sensing (vbus_sensing_enable is 'ENABLE'd in USBD_LL_Init() )

-Hannibal-