2020-11-04 05:48 AM
i am using stm32l072XX
I am using USB msc mode
found below functions to detect connection and disconnection of usb in file usbd_core.c
usbd_LL_suspend(***)
usbd_LL_resume(***)
they work properly when i insert or remove usb cable(i have added print statement in both functions)(connected one end to microcontroller and other to pc)
but when i keep usb cable connected and then power on the microcontroller, these functions are not called and my code doesn't knows that usb is connected.
usb is still working as i can see in my computer(get a mass storage device), but the code in microcontroller doesn't knows it as i am watching above two functions only to detect.
How to find at startup itself that USB is connected ?
2020-11-04 06:16 PM
For USB devices, one would typically monitor the VBUS pin and, if high, the cable is there and you should initialize USB. You should also deinitialize it when VBUS drops.
You can of course blindly try to initialize USB on startup without checking for VBUS, which is technically not allowed for dual powered devices but probably won't hurt anything. The state of the USB should be reflected in one of its structures (USBD_HandleTypeDef).
2020-11-04 07:51 PM
how to detect VBUS status using software ?
cannot find VBUS in datasheet or reference manual ,but some functions are available with the name vbus in the code generated by cubemx