2010-08-12 02:15 PM
Virtual Com Port - Detect USB Disconnect
#stm32-usb2011-05-17 05:02 AM
2011-05-17 05:02 AM
''Does anyone have any idea how I might detect the unpluging of the USB ?''
When the USB power disappears?
2011-05-17 05:02 AM
I read in ''http://www.beyondlogic.org/usbnutshell/usb2.htm'' that,
''A USB device will enter suspend when there is no activity on the bus for greater than 3.0ms. It then has a further 7ms to shutdown the device and draw no more than the designated suspend current and thus must be only drawing the rated suspend current from the bus 10mS after bus activity stopped. In order to maintain connected to a suspended hub or host, the device must still provide power to its pull up speed selection resistors during suspend.USB has a start of frame packet or keep alive sent periodically on the bus. This prevents an idle bus from entering suspend mode in the absence of data.
2011-05-17 05:02 AM
Hi John.F,
Good & clever point . It should work : Enable ''SOF'' interrupts in the application, and monitor ''bDeviceState & bIntPackSOF'' variables. If (bDeviceState == CONFIGURED) & bIntPackSOF is not updating / incrementing Then the USB Cable is disconnected. The only drawback of the solution is some software overhead in SOF IRQ each 1ms and in main program loop routine above versus the hardware solution where its consists to monitor VBus presence by an external Interrupt/ GPIO. We have an FAQ on the subject ) Cheers, STOne-2011-05-17 05:02 AM
Thanks to all for this info. I'm working on a project that uses USB and the rev A hardware didn't monitor USB power. Rev B does :)
(Debug output) 08/16/2010 15:20:59.435 USB cable inserted/power added! 08/16/2010 15:20:59.602 USB cable/power removed!2011-05-17 05:02 AM
Thanks STOne-32 & John F.
Your idea works really well ! Thanks Clive2011-12-12 01:54 AM
Hi all,
what about detecting cable remove in mass storage option, where bIntPackSOF is not used? Cheers, Peter2011-12-12 04:15 AM
Hi,
I found that Mass_Storage_In and Mass_Storage_Out functions sends some data in time interval to the host . I think to set variable in MassStorage In and Out function and reset them in timer. Maybe someone have better idea to detect cable unplug?2012-02-17 07:32 AM
I have a similar issue and came across this post, but the ''We have an FAQ on the subject'' is a dead link. Any idea where that has been moved to? Thanks!