On Sat, Nov 14, 2009 at 9:11 AM, Philip Pemberton w= rote: > =A0> One potential issue is wrong Data Toggle in the firmware. > > Surely the MCHP framework / SIE handles this? Probably. The 1.x stack is said to have data toggle and other problems. It caused great trouble for me under FreeBSD last time trying to get PICKit 2 work under FreeBSD (no longer running FreeBSD due to problems with my Acer PC). Reference: http://mcuee.blogspot.com/search/label/FreeBSD > >> usb_release_interface(devh, 0); >> usb_reset_device(devh); (adding this one often helps). >> usb_close(devh); >> usb_exit(); > > Now that's quite different to what I'm doing -- I wasn't aware that you > had to call all that before / after usb_close(). > > Also, doesn't the usb_reset_device() call cause the device to reset and > re-enumerate? Yes. That also reset the data toggle. Supposedly usb_set_configuration is kind of a less brutal force to reset the data toggle. But sometimes it does not work well. >> One example I tried before. >> http://www.microchip.com/forums/tm.aspx?m=3D340892 > > ... Which seems to be doing what I'm doing (calling usb_close() on its > own without releasing the interface). > And I had some problems on second try of the program, just as what happened to you. Adding usb_reset_device(devh) fixed the issue but it is a brutal force approach. It might be related to the firmware and the Linux USB stack implementation. Later it shows that usb_set_configuration was sufficient for me. > int suite_cleanup_usb(void) > { > =A0 =A0 =A0 =A0// Close the USB device > =A0 =A0 =A0 =A0if (usb_close(g_dev) < 0) { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return -1; // failure > =A0 =A0 =A0 =A0} else { > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0return 0; // success > =A0 =A0 =A0 =A0} > } > Try to add usb_reset_device(devh) before exiting. If it does not help, I am sure you will get better advice in the libusb mailing list. Often, they will ask you to use usbmon to see what really happens. Alan Stern is on the libusb mailing list and he is one of the main contributor to the Linux USB subsystem. If usb_reset_device(devh) helps, this may well point to a potential firmware bug. -- = Xiaofan http://mcuee.blogspot.com -- = http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist