cancel
Showing results for 
Search instead for 
Did you mean: 

Virtual Com Port - Detect USB Disconnect

anbeyon2
Associate II
Posted on August 12, 2010 at 23:15

Virtual Com Port - Detect USB Disconnect

#stm32-usb

10 REPLIES 10
anbeyon2
Associate II
Posted on May 17, 2011 at 14:02

Hi Andrew,

Thanks for the reply - Unfortunately I can't do that. Hardware is fixed for the time being.

Any one have any other ideas ?

I have had a little success and enabled the USB Error interrupt and used this to determine that there is a problem but it is very hit and miss!

Thanks

Clive

Posted on May 17, 2011 at 14:02

''Does anyone have any idea how I might detect the unpluging of the USB ?''

 

When the USB power disappears?

John F.
Senior
Posted on May 17, 2011 at 14:02

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.

  • A high speed bus will have micro-frames sent every 125.0 µs ±62.5 ns.
  • A full speed bus will have a frame sent down each 1.000 ms ±500 ns.
  • A low speed bus will have a keep alive which is a EOP (End of Packet) every 1ms only in the absence of any low speed data.''
You should be able to see the interruption in keep alive packets. I'm sorry I don't have further technical details.
Nickname12657_O
Associate III
Posted on May 17, 2011 at 14:02

Hi John.F,

Good & clever point

0690X0000060MlHQAU.gif . 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

http://www.st.com/stonline/faq/faqview.php?ids=1230

)

Cheers,

STOne-

swhite2
Associate III
Posted on May 17, 2011 at 14:02

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!

anbeyon2
Associate II
Posted on May 17, 2011 at 14:02

Thanks STOne-32 & John F.

Your idea works really well !   Thanks

Clive

office2
Associate
Posted on December 12, 2011 at 10:54

Hi all,

what about detecting cable remove in mass storage option, where bIntPackSOF is not used?

Cheers,

Peter

office2
Associate
Posted on December 12, 2011 at 13:15

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?

daneichenwald
Associate
Posted on February 17, 2012 at 16:32

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!