Score:2

CH340 Serial device doesn't appear in /dev/ (WSL)

cn flag

I have an arduino nano clone with a CH340 serial chip. It appears in lsusb as QinHeng Electronics HL-340 USB-Serial adapter and when it connects I can see it in dmesg with the following logging:

[   31.251098] vhci_hcd vhci_hcd.0: pdev(0) rhport(0) sockfd(3)
[   31.251544] vhci_hcd vhci_hcd.0: devid(65541) speed(2) speed_str(full-speed)
[   31.252004] vhci_hcd vhci_hcd.0: Device attached
[   31.538489] vhci_hcd: vhci_device speed not set
[   31.608492] usb 1-1: new full-speed USB device number 2 using vhci_hcd
[   31.698522] vhci_hcd: vhci_device speed not set
[   31.768510] usb 1-1: SetAddress Request (2) to port 0
[   31.812328] usb 1-1: New USB device found, idVendor=1a86, idProduct=7523, bcdDevice= 2.63
[   31.812734] usb 1-1: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[   31.813059] usb 1-1: Product: USB2.0-Serial

But there is no /dev/ttyUSB*.

Thanks.

NotTheDr01ds avatar
vn flag
Are you using USB/IP or trying to access it directly from WSL? AFAIK, only USB/IP will work (and only in the latest kernel, which you apparently have).
Leo Bound avatar
cn flag
USB/IP (with usbipd) in WSL2 on Win11. Appears with lsusb as "Bus 001 Device 002: ID 1a86:7523 QinHeng Electronics HL-340 USB-Serial adapter" and uname -r is "5.10.60.1-microsoft-standard-WSL2"
Score:5
cn flag

So as of writing this, the reason for the lack of support for USB serial devices is due to their modules not being included in the WSL kernel.

You can compile your own WSL kernel with the modules by doing the following:

  1. You may need these dependencies: sudo apt install build-essential flex bison libssl-dev libelf-dev dwarves libncurses-dev

  2. Clone the WSL2 repo with: git clone https://github.com/microsoft/WSL2-Linux-Kernel.git

  3. Change directory into the WSL2-Linux-Kernel folder: cd WSL2-Linux-Kernel

  4. Modify the kernel config by running make menuconfig KCONFIG_CONFIG=Microsoft/config-wsl.

  5. Go to Device Drivers -> USB Support -> USB Serial Converter support then enable your drivers in here.

    • The CP210x family are also common on microcontroller dev boards.
    • You probably want these baked into the kernel so press y or space twice to make sure they are enabled with <*> rather than <M>.

    Then save and exit menuconfig and overwrite config-wsl.

- You probably shouldn't use the following struck through points but they are an alternative to the previous two -

3. Modify the config-wsl file: nano Microsoft/config-wsl (Or use your editor of choice).

​Go to line 2409 (shift+_ then 2409 in nano) and replace # CONFIG_USB_SERIAL_CH341 is not set with CONFIG_USB_SERIAL_CH341=y ​- You may want to do the same for CONFIG_USB_SERIAL_CP210X - another common serial-usb adapter.

  1. Close your text editor and save (ctrl + x then y then enter with nano).

  2. Build the kernel using the WSL2 kernel configuration: make KCONFIG_CONFIG=Microsoft/config-wsl ​- This can take a while ​- You can speed this up with the -j argument but make sure to specify a value e.g. -j4

  3. Copy the compiled kernel to your Windows user directory: cp arch/x86/boot/bzImage /mnt/c/Users/<your-user-name-here>/wsl_kernel

  4. Create a file in your Windows user directory called .wslconfig and paste this into it:

[wsl2]
kernel = C:\\Users\\<your-user-name-here>\\wsl_kernel
  1. Shut down WSL with wsl --shutdown in a Windows command prompt.

  2. Open your WSL terminal and now you should be able to connect USB serial devices as outlined here.

And hopefully everything should work! (Tested on Win10 and Win11 with Ubuntu WSL2 distro)

Biswapriyo avatar
ng flag
Use menuconfig instead of manually editing config file.
Leo Bound avatar
cn flag
@Biswapriyo Thanks, I've never actually had to mess with the kernel config before so wasn't aware of the best way to do it. I've updated the above accordingly and appreciate any other comments anyone has.
ro flag
I was able to confirm that both the manual and menuconfig flow works! I had to install libncurses but otherwise worked perfectly.
BlinkyBill avatar
ua flag
Using the menu I was only able to add the drivers as modules. Editing the config file however worked successfully.
Börge avatar
cn flag
Great step-by-step instructions. BTW: The same steps can be performed in order to add support for USB Drives. Only difference: Instead of the USB Serial Converter Support, Tick the USB Mass Storage Support, with any needed drivers.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.