skip to Main Content

From inside of a development container for VSCode (Debian Linux) I’d like to use a COM port for communication via an USB device connnected to the Windows host machine (via WSL2). How can I make the COM port available insie of the container?

EDIT:

For WSL2 there is no official support yet.

As of right now WSL 2 does not include serial support, or USB device support.

A corresponding feature request is tracked on GitHub.

2

Answers


  1. July 2021: As of right now WSL 2 does not include serial support, or USB device support.

    Update November 2021: the same FAQ states:

    Skanda Hazarika reports:

    You can now connect USB devices in Windows Subsystem for Linux under Windows 11

    If you’re an active user of Windows Subsystem for Linux and want to access USB devices right from the Linux instance running under WSL, then you’ll be happy to know that there has been a significant progress in this front.

    Thanks to Microsoft’s contributions to the open-source dorssel/usbipd-win project, you can now enjoy USB passthrough access in WSL.
    It means end users can perform tasks like flashing Android devices under Windows Subsystem for Linux, which are otherwise not supported by the Linux subsystem.

    The usbipd-win project is all about creating a solution for sharing locally connected USB devices to other machines, including Hyper-V guests and WSL2. However, the official WSL2 Linux kernel used to lack support for the USB/IP protocol, requiring users to build the kernel themselves.

    Since WSL kernel version 5.10.60.1, the required parameters are configured out of the box, so no manual recompilation is needed.
    Microsoft has also contributed a command line interface to the project to both enable a USB device for sharing on Windows and seamlessly attach it from within WSL.

    So if you have:

    Then, your VSCode should be able to access mounted USB drives through WSL.

    Login or Signup to reply.
  2. April 2023:

    Now it is possible to setup the whole chain of access to USB in Windows 10 with docker assuming Ubuntu on WSL2.

    1. Make sure you WSL kernel is at least 5.10.60 (you can check with wsl --status in windows cmd line)
    2. Run the steps mentioned on the Microsoft page
    3. After you setup you should see your device with lsusb (apt install usbutils)
    lsusb
    Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
    Bus 001 Device 002: ID 0483:3748 STMicroelectronics ST-LINK/V2
    Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
    
    1. It is possible, that you still don’t see it in /dev. In this case you need to create a 99-platformio-udev.rules file in /etc/udev/rules.d and add the definition of your usb device. See the github page for the list which probably will contain your selected device as well.
    2. You may need to reload the udev config after this. Note: I found my device actually under /dev/bus/usb... rather then as /dev/ttyUSB
    sudo udevadm control --reload
    sudo service udev restart 
    
    1. Finally add "--device=/dev/..." to you .devcontainer file runArgs section or to your docker run ... command
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search