adafruit / Adafruit_Windows_Drivers

All in one Windows driver installer for Adafruit's boards.
MIT License
88 stars 28 forks source link

USBtinyISP Libusb Incompatibility #22

Closed Amavect closed 4 years ago

Amavect commented 4 years ago

The USBtinyISP driver is based on Libusb-win32 project's libusb0.dll and libusb0.sys. Libusb-win32 is obsoleted by Libusb (which is a separate project). Libusb's device enumeration (calls to SetupDiGetClassDevsA() ) depends on the Device Interface GUID to be registered by the driver, and on the Windows registry containing an entry named DeviceInterfaceGUIDs to be set to the libusb0.sys device interface GUID. Libusb-win32 enumerates the bus differently, which I haven't looked much into besides glancing at the function calls.

Luckily, WinAVR hasn't been updated, so their build of Avrdude still works because it's likely still linked to Libusb-win32. Fresh builds of Avrdude do not work because they are linked to Libusb.

Adding the libusb0 GUID, {F9F3FF14-AE21-48A0-8A25-8011A7A931D9}, to the .inf file has not helped. I assume that the libusb0.sys driver is not registering its device interface GUID. (Or maybe I didn't reboot my computer? That shouldn't matter.)

Alternative kernel drivers can be retrieved from the LibusbK project or the (proprietary) WinUSB project. Perhaps it would be worth linking against one of those?

Thanks, Amavect

ladyada commented 4 years ago

hi...this code is quite old and dependable - we'd rather document any incompatibilities than try relinking. what dox should we update?

Amavect commented 4 years ago

Here's a few docs that can be changed:

https://learn.adafruit.com/usbtinyisp/download The "Windows Drivers" section should be removed and point to https://learn.adafruit.com/usbtinyisp/drivers The "AVRDUDE" section should be removed and point to https://learn.adafruit.com/usbtinyisp/avrdude

https://learn.adafruit.com/usbtinyisp/drivers The download link should point to https://github.com/adafruit/Adafruit_Windows_Drivers/releases/latest so any new releases don't need a hyperlink update.

I don't think any incompatibilities with new avrdude builds needs to be documented quite yet. I've actually been successful in replacing the current .inf with one that uses winusb.sys instead of libusb0.sys. However, this breaks compatibility with the old WinAVR avrdude. I'll see if I can make it work with both...

Amavect commented 4 years ago

I got so close to making them both work, but it just doesn't work. If I comment out either of the AddService lines, I get one avrdude version to work, but not the other. If neither are commented out, it picks the second AddService line in the list.

https://docs.microsoft.com/en-us/windows-hardware/drivers/install/inf-addservice-directive

Every device driver INF should have exactly one associated service.

So, it can't work. Here's another thing to document:

https://learn.adafruit.com/usbtinyisp/help section title: I'm running avrdude and I get "error: usbtiny_transmit: initialization failed, rc=-1" section body: insert image avrdude_usbtiny_transmit_error.png This response means that it found the USBtiny, but could not communicate with it. The likely reason is that you found a version of avrdude that was not from WinAVR. Differences in new versions of avrdude mean that it doesn't work with the libusb-win32 USBtinyISP driver. For more information, see https://github.com/adafruit/Adafruit_Windows_Drivers/issues/22

Lastly, would you guys be willing to have a pull request for WinUSB usbtinyisp driver? Or would that be a little confusing to have both a WinAVR driver and a non-WinAVR driver?

almost.inf.txt USBtiny_WinUSB.inf.txt

ladyada commented 4 years ago

ok added those changes. PR is ok but please maybe put in a unique folder so its separate and doesnt confuse existing users :) many folks are using the usbtiny with arduino's distribution which is winavr-compat