Setting USB Passthrough In DevContainer.

Part 1: Configuring Windows and WSL

Setting up Windows and WSL

Run PowerShell as administrator and run the bellow command.

winget install usbipd

List all the attached devices.

usbipd list 

Pasted image 20251022151241.png
I'm going to enable passthrough for a USB serial device on COM27 with BUSID 1-1, as you can see in the screenshot above the status is not shared.

Use the below command to bind the BUSID of the device. Once it is success full status changes to shared as shown in the screen shot below.

usbipd bind --busid <BusID>

Pasted image 20251022151357.png

Attach to WSL:

Run this command to attach the device to WSL.

usbipd attach --wsl --busid <BusID>

Pasted image 20251022152033.pngThe USB device will disconnect from the host and connect to WSL, you can very this by running the usbipd list and the status of the USB device changes to attached as shown in the screenshot below.

Pasted image 20251022152313.png

Part 2: Configuring the Dev Container

Access WSL cli and, Open PowerShell and type WSL it should launch you in to WSL terminal.

Look for the USB device that we've attached to WSL in step one.

ls /dev/tty* 

It should typically look some thing like ttyUSB0 or ttyACM0.

Pasted image 20251023111657.png

Now add below line in the devcontainer.json file and rebuild the container.

"runArgs": ["--privileged","--device=/dev/ttyACM0:/dev/ttyACM0"]

You can verify the USB passthrough using the same ls /dev/tty* command on the devcontainer's terminal.