Using STM32F4 USB Mass Storage Controller example in Device Mode, how do you detect connections and disconnections with a host controller?
I tried polling the VBUS pin state yet it could be high from a wall adapter or high without any communication with the host.
Is there a register to check? I noticed DSTS (status I guess?) in the USB library structs but couldn't find its documentation nor any useful comments in the code.
Best Answer
You could detect the connection and disconnection from this file:
usbd_core.c
and the API for it is this
I am not sure about USB Mass Storage Class but in the CDC class, the 2 APIs above detect the USB connection and disconnection, maybe this helps
Things to note:
I used STMCubeMX to generate the USB CDC class.