Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Investigate using usbdk on windows #22

Open
mattico opened this issue Aug 27, 2020 · 4 comments
Open

Investigate using usbdk on windows #22

mattico opened this issue Aug 27, 2020 · 4 comments

Comments

@mattico
Copy link
Contributor

mattico commented Aug 27, 2020

This was mentioned in #6 but not fixed by #21 so I wanted to open an issue to keep tracking the idea.

Using libusb on windows requires replacing a device's driver with a libusb one, e.g. using Zadig.

https://github.com/daynix/UsbDk could be used instead, which detaches the device from its drivers and Windows' PNP stack at runtime allowing the device to be controlled without needing to replace its driver.

@jonas-schievink
Copy link
Owner

I prototyped this on the context-usbdk branch a while back, and it seemed to work. I don't know if it'll still work with the WinUSB driver though.

@mattico
Copy link
Contributor Author

mattico commented Aug 27, 2020

I didn't know that libusb supported usbdk as a backend, I thought this was going to be a lot more work!

From my 10 minutes of research, usbdk should bypass whatever driver windows wants to use for the device but testing is required of course. Worst case we create 2 libusb contexts, set the option on one of them and enumerate both.

I should be able to work on this if I ever get probe-rs working with my micro.

@jonas-schievink
Copy link
Owner

Worst case we create 2 libusb contexts, set the option on one of them and enumerate both.

Yeah, that's a reasonable workaround I think.

@mattico
Copy link
Contributor Author

mattico commented Oct 1, 2020

I got this working: master...mattico:72d8ac9

Some notes to myself:

  1. probe_run enumerates the device, closes it, then immediately tries to enumerate it again to open the device. UsbDk doesn't release the device fast enough (?) so the device doesn't show up in the second enumeration. A sleep_ms(1000) in new_from_selector "fixes" this.
  2. When open_usb is called the second time handle.set_active_configuration doesn't actually work - active_configuration() keeps returning 0 so we get a "another application is accessing the device" error. If we ignore that error everything seems to work. We may be not de-initializing everything properly after the first open_usb, the libusb docs have many requirements, but rusb seems to be closing everything properly. Try to repro with libusb, might be a bug in that or usbdk.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants