Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
9
rated 0 times [  9] [ 0]  / answers: 1 / hits: 4954  / 3 Years ago, fri, october 29, 2021, 4:13:26

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.


More From » drivers

 Answers
1

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)


[#1026] Saturday, October 30, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
weamp

Total Points: 197
Total Questions: 115
Total Answers: 92

Location: Mauritania
Member since Sun, May 7, 2023
1 Year ago
;