Skip to content

Instantly share code, notes, and snippets.

@zulonas
Last active February 5, 2024 19:33
Show Gist options
  • Save zulonas/4f72938611ef99ff2dc2097b0bb91579 to your computer and use it in GitHub Desktop.
Save zulonas/4f72938611ef99ff2dc2097b0bb91579 to your computer and use it in GitHub Desktop.
ACTIVATING USB FORWARDING TO WSL2

author: https://github.com/BerndNW18 source: MicrosoftDocs/WSL#1868 (comment)

Hi, here is my complete solution on how to forward a USB port to WSL2, using the latest usbipd-win. Note that my use-case is connecting to an rplidar fromSlamtec, which uses a Silicon Labs CP210x USB-to-serial Interface board to connect to the actual Lidar device. ACTIVATING USB FORWARDING TO WSL2 Purpose: make USB to Serial Bridge accessible in WSL2 to test the RPLidar SDK build on WSL Linux (Ubuntu)

  1. Install usbipd-win on the Windows-host: https://github.com/dorssel/usbipd-win/releases
  2. Install USBIP tools and hardware-database in Linux (WSL) bernd@myOmen:~$ sudo apt install linux-tools-generic hwdata bernd@myOmen:~$ sudo update-alternatives --install /usr/local/bin/usbip usbip /usr/lib/linux-tools/*-generic/usbip 20
  3. Open Powershell (Administrator)
  4. PS C:\WINDOWS\system32> usbipd list Output: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Not shared 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared 2-8 0461:4f03 USB Input Device Not shared 2-10 8087:0033 Intel(R) Wireless Bluetooth(R) Not shared 3-2 046d:081b Logi C310 HD WebCam Not shared 4-1 05a7:1020 Bose USB Audio, USB Input Device Not shared 4-2 046d:c52b Logitech USB Input Device, USB Input Device Not shared 4-3 04e8:329f Samsung CLP-320 Series Not shared
  5. We're interested in sharing the CP210x, so run PS C:\WINDOWS\system32> usbipd bind -b 2-2 where "2-2" is the value in BUSID column from usbipd list
  6. PS C:\WINDOWS\system32> usbipd list Output: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Shared 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared "Shared" means ready to be forwarded, but still parked
  7. PS C:\WINDOWS\system32> usbipd attach --wsl --busid 2-2 #this will now forward the USB-device. You will hear the "unplug" chime in Windows. Output: usbipd: info: Using WSL distribution 'Ubuntu' to attach; the device will be available in all WSL 2 distributions. usbipd: info: Using IP address 172.26.144.1 to reach the host.
  8. PS C:\WINDOWS\system32> usbipd list #check if it worked Output: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Attached 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared
  9. Open WSL
  10. bernd@myOmen:~$ lsusb Output: Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 003: ID 10c4:ea60 Silicon Labs CP210x UART Bridge Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bingo!
  11. bernd@myOmen:~$ ls -l /dev/ttyUSB* #check permissions crw-rw---- 1 root dialout 188, 0 Dec 8 11:30 /dev/ttyUSB0
  12. check if you're in the group (dialout): bernd@myOmen:~$ groups bernd adm dialout cdrom floppy sudo audio dip video plugdev netdev docker
  13. change to RPLidar SDK folder where the built demos are
  14. run one of the sdk-demos to check if the connection works: bernd@myOmen:~/rplidar/rplidar_sdk/output/Linux/Release$ ./simple_grabber --channel --serial /dev/ttyUSB0 256000 Output: SLAMTEC LIDAR S/N: E6BAED95C4E493CDA5E69EF0776A4B69 Version: SL_LIDAR_SDK_VERSION Firmware Ver: 1.32 Hardware Rev: 6 Lidar health status : OK. (errorcode: 0) waiting for data...
  15. [histogram data is shown] Do you want to see all the data? (y/n) n -> works. Yay! CLEANUP (un-forward USB)
  16. PS C:\WINDOWS\system32> usbipd detach --busid 2-2
  17. PS C:\WINDOWS\system32> usbipd list Connected: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Shared 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared
  18. PS C:\WINDOWS\system32> usbipd unbind --busid 2-2
  19. PS C:\WINDOWS\system32> usbipd list Connected: BUSID VID:PID DEVICE STATE 2-2 10c4:ea60 Silicon Labs CP210x USB to UART Bridge (COM3) Not shared 2-6 30c9:0069 HP Wide Vision HD Camera, Camera DFU Device Not shared
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment