[SOLVED] using cflib in WSL2

Firmware/software/electronics
Post Reply
Kaiser1401
Beginner
Posts: 11
Joined: Tue Apr 21, 2020 11:36 am

[SOLVED] using cflib in WSL2

Post by Kaiser1401 »

[Not completely sure if this is the right Sub-Forum]

I am trying to setup a development environment using WSL2 under windows 10.

Building and flashing works with the current make files using windows' python.

As I have to use linux dependent things to connect to my swarm (a.o. ROS) it would be nice to connect through the linux's python installation.

I managed to get general USB passthrough to WSL using usbipd (see https://devblogs.microsoft.com/commandl ... es-to-wsl/). the Radio is listed with lsusb and i have the access rights. Somewhere on the way creating a connection I get

Code: Select all

usb.core.USBError: [Errno 2] Entity not found
(more detailed below)

It's the same for trying with radio and direct usb connection to the drone.

After that the device is not listed in lsusb anymore.
From the code I guess it is somehow reset. Would it report itself as a different device (vendor id, etc) then?
I guess this is a WSL / usbip specific thing but maybe someone has some insight or ideas

Thanks
-Klaus

Code: Select all

  File "/home/klaus/.local/lib/python3.8/site-packages/cflib/crazyflie/__init__.py", line 223, in open_link
    self.link = cflib.crtp.get_link_driver(
  File "/home/klaus/.local/lib/python3.8/site-packages/cflib/crtp/__init__.py", line 98, in get_link_driver
    instance.connect(uri, link_quality_callback, link_error_callback)
  File "/home/klaus/.local/lib/python3.8/site-packages/cflib/crtp/radiodriver.py", line 267, in connect
    self._radio = RadioManager.open(devid)
  File "/home/klaus/.local/lib/python3.8/site-packages/cflib/crtp/radiodriver.py", line 226, in open
    shared_radio = _SharedRadio(devid)
  File "/home/klaus/.local/lib/python3.8/site-packages/cflib/crtp/radiodriver.py", line 149, in __init__
    self._radio = Crazyradio(devid=devid)
  File "/home/klaus/.local/lib/python3.8/site-packages/cflib/drivers/crazyradio.py", line 147, in __init__    self.handle.reset()
  File "/home/klaus/.local/lib/python3.8/site-packages/usb/core.py", line 961, in reset
    self._ctx.backend.reset_device(self._ctx.handle)
  File "/home/klaus/.local/lib/python3.8/site-packages/usb/backend/libusb1.py", line 911, in reset_device
    _check(self.lib.libusb_reset_device(dev_handle.handle))
  File "/home/klaus/.local/lib/python3.8/site-packages/usb/backend/libusb1.py", line 604, in _check
    raise USBError(_strerror(ret), ret, _libusb_errno[ret])
usb.core.USBError: [Errno 2] Entity not found
Last edited by Kaiser1401 on Tue Mar 22, 2022 12:08 pm, edited 1 time in total.
Kaiser1401
Beginner
Posts: 11
Joined: Tue Apr 21, 2020 11:36 am

Re: using cflib in WSL2

Post by Kaiser1401 »

Turns out it is a usbip problem indeed.

The virtual driver acts up when usb devices get send a reset.

Details and initial discussion:
https://www.virtualhere.com/comment/9432

LinuxKernelMailingList:
https://lkml.org/lkml/2021/7/21/1117

It has been fixed but not in the current default WSL2 kernel (5.10.60) yet.

Solution to make it work under WSL2:
Checkout newest (for me 5.10.102.1 worked) Kernel from microsofts WSL repo https://github.com/microsoft/WSL2-Linux-Kernel and compile and config according to https://blog.dan.drown.org/replacing-the-wsl-kernel/ (i.e. copy compiled kernel to windows host and have .wslconfig pointing to it)

It also looks like WSL does not run the udev rules when usb devices are bound. Will look into that later but giving access to the usb device under /dev/bus/usb/... with chmod works so far.
Use lsusb to figure out which port the device is on after binding it with usbipd wsl .... under windows
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: [SOLVED] using cflib in WSL2

Post by kristoffer »

Great that it worked out and thanks for sharing!
Post Reply