Page 1 of 1
What is needed for usb stability.
Posted: Sat Jun 28, 2014 8:58 pm
by ulao
Ok I have been using v-usb for 7 years and all I do is this...
//init
Code: Select all
static void usbReset(void)
{
usbDeviceDisconnect(); /* enforce re-enumeration, do this while interrupts are disabled! */
uchar i = 0;
while(--i)
{ // USB disconnect for >250ms
_delay_ms(1);
};
usbDeviceConnect();
}
cli();
sreg = SREG;
usbInit();
usbReset();
SREG = sreg;
sei();
//main loop
makeReport();
while (!usbInterruptIsReady()){usbPoll(); } usbSetInterrupt( reportBuffer, 8);
Now I have noticed there is a bit of a rocky start, usb reset kinda bumpy, and even ( very seldom ) the usb drops out during use. It has not been a big deal but I'd like to clean it up. I have seen people use the timers and the watch dog but what is really needed here. Can anyone give me a very minimal basic usb init and loop? I'm not using the mega8 but instead the 328 so the timers are not the same.
Re: What is needed for usb stability.
Posted: Tue Jul 01, 2014 8:23 am
by blargg
This is about the most minimal I come up with for an USBasp board (atmega8).
Code: Select all
#include <avr/interrupt.h>
#include "usbdrv/usbdrv.h"
int main( void )
{
usbInit();
sei();
for ( ;; )
{
usbPoll();
}
}
uchar usbFunctionSetup( uchar data [] )
{
(void) data;
return 0;
}
Re: What is needed for usb stability.
Posted: Tue Jul 01, 2014 2:10 pm
by ulao
So why do so many people full with timers, watch dogs, status registers, and resets?
Re: What is needed for usb stability.
Posted: Tue Jul 01, 2014 9:48 pm
by blargg
Those provide additional features. Watchdog can reset device if it hangs (though I think these are a bad idea during development as they can hide bugs if you don't notice the reset). Timers provide a timebase for other things you're doing. Sometimes people put a USB reset on the bus in the beginning so when developing and the device has just been reflashed, the host will re-enumerate and see the new device. Also
copypasta explains unnecessary things. And of course I may be incorrect in some way.
Re: What is needed for usb stability.
Posted: Wed Jul 02, 2014 1:36 pm
by ulao
blargg, that was helpful thx. I finally got the init down to the point I'm happy with it but in my poll loop the usb is constantly drops out. AS you suggested I dont want to watch dog it. I'd rather find the error. My build report is well under 8 ms, and my polls occurs every 8 ms on time, each time. Aside from time, what else would make the usb drop out? By that I mean the usb device stop reporting data (seen from my analyzer) than comes back.
If the usb gave up wouldn't it need to re-enumerate? If so that is not my problem. Though for some reason the usb does not communicate with the host at some length of time and then starts to talk again.
Re: What is needed for usb stability.
Posted: Wed Jul 02, 2014 10:03 pm
by ulao
ok found my issue, too long of a wait in-between polls. What it the max with the current v-usb version?
Re: What is needed for usb stability.
Posted: Thu Jul 03, 2014 12:10 am
by blargg
In a thread a while back someone replied to you that it was
50ms. What's your code doing for 8ms between calls? usbPoll() is generally quick as it has nothing to do.
Re: What is needed for usb stability.
Posted: Thu Jul 03, 2014 1:29 pm
by ulao
They didn't reply to me, they replied to the above user, I dont retain every post I comment in.
Anyways I think I jumped the gun on that one .The longest wait I have seen is 4 ms in testing. So I take that back, its not a time out issue.
What's your code doing for 8ms between calls?
I just meant that the usb interrupt is every 8 ms like it should be and my code is well under 8ms.
Did some testing tonight and it turns out the usb device works on all my 7 systems but the two that have the avr isp usb burner and avr studio installed. To make it see my symptoms.
avr studio open
1) if I unplug the avr burn my usb device drops out. Same if I plug it in
2) the usb device works when the avr burner is plugged in but as described above.
3) the usb device will not enumerate if the usb burner in unplugged.
4) unplugging or plugging in the avr causes the device to reset.
avr studio closed
1) if I unplug the avr burn my usb device drops out.Same if I plug it in
2) the usb device works when the avr burner is plugged correctly
3) the usb device works when the avr burner is not plugged correctly
If avr stuio is not running and the device is working well I can run avr studio and use the isp. Until I burn to the chip and my device is back to crap again.
This is the same on my two system both win7 64 but. Both have the latest 6.2 avr studio.