Lost connection with PC: any way to restore?

General discussions about V-USB, our firmware-only implementation of a low speed USB device on Atmel's AVR microcontrollers
Post Reply
AntonG
Posts: 4
Joined: Thu Aug 13, 2009 2:59 pm

Lost connection with PC: any way to restore?

Post by AntonG » Thu Aug 13, 2009 5:02 pm

Hello!

If after some event PC loses USB-connection with device (with v-usb driver, of course) while physically it is still there, the connection can only be restored by either resetting the device or by unplugging it and then connecting to PC again. Somewhat similar problem is described in this thread, and an "event" was Windows sleep mode.

I'm building a PC-controlled power source, and the interface board is actually PowerSwitch with some extra functions. For me an "event" is manual switching power (220V AC) on or off. Board continues to function as intended except USB connection. Since connection loss happens even when there is _no_ galvanic coupling between interface board and _anything_ else except PC, I suppose it's because of EM interference from transformers.

test case:
220V AC <=> on/off switch <=> transformer
No other connections.
Tested hardware: my interface board, UsbAsp (both with Atmega8)
Firmware: PowerSwitch (both my modification and plain), UsbAsp, bootloadHID.
The difference from original is that I'm using Int1 instead of Int0 on both boards (was better for routing).
OS: windows XP with libusb-win32-0.1.12.1.
If I change switch state (in any direction), board in near loses connection to pc, but works fine otherwise.

Is there any way to fix it in firmware?
I would very much appreciate any help.

maxi
Rank 3
Rank 3
Posts: 122
Joined: Fri Jul 24, 2009 6:13 pm

Re: Lost connection with PC: any way to restore?

Post by maxi » Thu Aug 13, 2009 5:28 pm

Sorry I cannot answer your question but I can confirm that this problem exists. My project is currently still on proto-board, one half of the board has my avr powered by usb, on the other side I have a simple oscillator powered by a stabalised 5v supply pulled from an old printer. Even when there is no physical connection between the circuits (not even ground), a simple matter of connecting the 5v supply occaisionally stalls the usb driver forcing me to reset. However since I decoupled my ADC pin with a small cap the problem occurs much less frequently, I was rather hoping it might just go away once I got everything soldered up on to a pcb.

I would also be very interested to know if there is a way to re-connect automatically through the firmware.

ulao
Rank 4
Rank 4
Posts: 481
Joined: Mon Aug 25, 2008 8:45 pm

Re: Lost connection with PC: any way to restore?

Post by ulao » Thu Aug 13, 2009 5:40 pm

One possible thing to look at is the time during usb write to device read. If the avr takes too long to work with the device the usb may fall behind. Not sure about the details here but I have made this mistake before and the result as you described.

Grendel
Rank 4
Rank 4
Posts: 167
Joined: Sat Dec 16, 2006 9:53 pm
Location: Oregon, USA
Contact:

Re: Lost connection with PC: any way to restore?

Post by Grendel » Thu Aug 13, 2009 10:01 pm

You can reconnect automatically if you connect the D- pull up resistor to an I/O pin instead of Vcc. See the USB_CFG_PULLUP_* macros in usbconfig.h . To reconnect, issue usbDeviceDisconnect(), wait 1-2s, then issue a usbDeviceConnect().

AntonG
Posts: 4
Joined: Thu Aug 13, 2009 2:59 pm

Re: Lost connection with PC: any way to restore?

Post by AntonG » Thu Aug 13, 2009 11:55 pm

Grendel wrote:You can reconnect automatically if you connect the D- pull up resistor to an I/O pin instead of Vcc.

Do we really need extra IO pin to enforce re-enumeration like we do it just after usb initialization? Like this:

Code: Select all

    usbDeviceDisconnect();
   _delay_ms(500);
    usbDeviceConnect();
Unfortunately I have no spare IO pins this time.

And we should know first whether the connection is lost or not, shouldn't we? I don't think it is a good idea to reset usb every N cycles. But it's just a feeling, I don't know for sure. Maybe somebody here knows better?

Anyway I will try in the morning just to see if it works.

Edit:
Sorry, had no chance to try and will not have in the next two weeks :(

AntonG
Posts: 4
Joined: Thu Aug 13, 2009 2:59 pm

Re: Lost connection with PC: any way to restore?

Post by AntonG » Thu Sep 03, 2009 11:47 am

I don't know how clean is this workaround, but at least it works for me.
I just run this every 10s:

Code: Select all

USB_INTR_ENABLE &= ~(1 << USB_INTR_ENABLE_BIT);
usbDeviceDisconnect();
_delay_ms(500);      // or some other sort of delay
usbDeviceConnect();
USB_INTR_ENABLE |= (1 << USB_INTR_ENABLE_BIT);

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Lost connection with PC: any way to restore?

Post by christian » Tue Sep 22, 2009 10:30 am

I can confirm that EMI (Electro Magnetic Interference) is a problem with AVRs. Switching an inductive load can cause the PC disconnect. Analysis has shown that the AVR itself performs kind of half of a reset. Some parts of the chip go into reset status, others don't. I have seen this even on projects without USB connectivity.

You can brute-force work around the problem by performing the USB disconnect when you suspect a problem.

Other than that, all measures which reduce EMI help. But this is a very complex topic.

saltuka

Re: Lost connection with PC: any way to restore?

Post by saltuka » Wed Sep 23, 2009 4:18 am

Just an idea,

Periodically read a specific message from AVR-USB device. In switch : case of this message refresh a timer. If timer overflows reset the chip.If USB device
always works fine the timer should not have chance to overflow hence no reset occurs.

saltuka

Re: Lost connection with PC: any way to restore?

Post by saltuka » Sun Sep 27, 2009 5:33 pm

Reseting USB fixes connection problems but connect- disconnect sound in windows is an isue. My quesiton is: Is there a way to
disable this sound only for a given VID/PID USB device in Windows.

I am using win - usblib as USB driver. May be there is a way to fix this isue from driver.


Best regards
saltukasaltuka

saltuka

Re: Lost connection with PC: any way to restore?

Post by saltuka » Sun Sep 27, 2009 10:38 pm

I tried to use watchdog reset to init firmware when usb connection is broken. I will check the connection periodically from host software and clear a flag. If flag is not cleared IC will get into watchdog reset. This does not cause re-connect with usb hence no sound for disconnect - connect of usb device. Any idea about this solution is very appreciated.
Saltuka

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Lost connection with PC: any way to restore?

Post by christian » Mon Sep 28, 2009 12:00 pm

Why should this prevent the disconnect/connect sound? A watchdog reset also triggers a disconnect. If it does not, there's a discrepancy in the host's notion of the USB ID and the device's notion.

You should be able to prevent EMI problems with a (very) good board layout.

saltuka

Re: Lost connection with PC: any way to restore?

Post by saltuka » Sat Oct 03, 2009 7:42 pm

christian wrote:Why should this prevent the disconnect/connect sound? A watchdog reset also triggers a disconnect. If it does not, there's a discrepancy in the host's notion of the USB ID and the device's notion.

You should be able to prevent EMI problems with a (very) good board layout.



Dear Christian, I am not expert on USB however the solution I adviced somehow worked for me. Could you explain little more what may cause "discrepancy in the host's notion of the USB ID and the device's notion." Actually after reset of device I can still read my usb parameters corretly and windows does not give plug - unplug sound.

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Lost connection with PC: any way to restore?

Post by christian » Sun Oct 04, 2009 11:39 am

If your main() routine begins with a usbDisconnect() which lasts for some time (all our examples do that), then I don't see a difference to initiating the disconnect somewhere during runtime.

If your main() does not do that, the host won't know that you had a reset. The USB driver's usbDeviceAddr variable is reset to 0, but the host tries to reach it under the address which was negotiated before the reset.

Alan Chatham
Rank 1
Rank 1
Posts: 28
Joined: Wed Sep 30, 2009 3:36 am
Location: Osaka, Japan
Contact:

Re: Lost connection with PC: any way to restore?

Post by Alan Chatham » Wed Oct 07, 2009 2:25 am

christian wrote:... Analysis has shown that the AVR itself performs kind of half of a reset. Some parts of the chip go into reset status, others don't. I have seen this even on projects without USB connectivity.


Sorry this is drifting slightly off-topic, but I was wondering if there were any resources to look into about this sort of "half-reset" problem? Thanks so much!

christian
Objective Development
Objective Development
Posts: 1443
Joined: Thu Nov 09, 2006 11:46 am

Re: Lost connection with PC: any way to restore?

Post by christian » Wed Oct 07, 2009 10:43 am

I have read about this when doing support. Somebody found out that the program was executing normally, but the I/O registers were reset to their RESET state. I have not verified this myself, so it may have been some other unexpected behavior.

On the other hand, I have seen lots of EMI problems with the AVR myself, especially with V-USB. Probably because a long cable is directly connected to I/O pins.

Post Reply