>> Hi, my name is Ben McMorran.
I'm a software engineer here at Microsoft,
and I'm here today to talk to you
about how Microsoft contributed to
a third party open-source project that
allows you to connect USB devices to WSL.
[MUSIC]
Why would you want to use USB devices in WSL?
Well, it's been a really highly
requested feature for a long time,
and beginning with Windows 11,
you can attach USB devices.
This enables scenarios with embedded devices,
like an Arduino or the Azure IoT debit,
smart card readers, Bluetooth dongles,
or any of a variety of other scenarios where
you might want to interact with the physical device from WSL.
I'm going to show you how to try this on Windows 11
by using an Insider's build. Let's see it in action.
[MUSIC]
>> I'm using WSL2 on
the latest version of Windows 11 on the Insider's channel.
I'm also going to install the usbipd-win project.
This is the third party open-source project
that Microsoft has contributed to,
and I'm installing the version 1.0.0 of this project.
For the demo today I'm going to be using
the Azure IoT Getting Started guide,
specifically on the MXChip AZ3166,
which is the Azure IoT DevKit development board,
but many other USB scenarios should work.
This is just an easy scenario to demonstrate.
Right now, this embedded device is attached to my computer
and I can see it here in Device Manager as ST-Link Debug.
Also noticed that from within WSL,
if I run lsusb to list
the attached devices, it doesn't show up there.
We only see these root hubs.
In order to attach this device to WSL,
I start in an administrator command prompt
by running usbipd wsl list.
This shows me the set of USB devices that are
currently attached to my host computer on Windows.
A brief description of the device and whether or not
the device is attached to any WSL instances.
In this case, none of the devices are attached to WSL,
and so they all show is not attached.
I can see that this device 4-2,
the ST-Link Debug is the one that I'd like to attach to WSL.
In order to do that, I just run another command,
usbipd wsl, attach dash b to specify the bus ID, and then 4-2.
At this point, usbipd
is running a command in WSL and it needs to read access.
So it's asking you for pseudo permission.
I'll go ahead and enter my password
and now the device is attached.
We can see this by looking in the Device Manager and noticing
that there's no longer an ST-Link device here,
and if I run lsusb on WSL,
we can see that the device shows up in the Linux device tree.
That's cool. But what can I actually do with this device?
Well, I'll go ahead and start VS Code with
this Getting Started Guide project so that we can try
programming and debugging the device.
I'll note that this is using
the WSL remote support in VS Code so that from Windows,
VS Code can open a project that's hosted in
WSL and you can see that here with WSL Ubuntu.
I went ahead and set a break-point here for board
initialization so that I can
understand what this project does as it starts up.
In order to debug it,
I'll go over to the debug settings,
select the launch configuration that I
want and try to start debug.
Here we can see that it's starting to flash the device.
This might take a few seconds.
Now notice that we've hit a break-point here.
This has an implicit break-point at
the very first instruction that this embedded devices executing,
where it's setting up an interrupt table.
At this point, we can use VS Code just like normal to
debug this embedded device as if it was attached to Windows.
I can continue,
and I'll hit that break-point I said
earlier and I can continue and just let the program run.
If I break later,
I'll get some call stack that I met inside
the system application and the rest of
the VS Codes capabilities should work even though
we're running from within a WSL instance.
We'll go ahead and close Visual Studio Code
now and discuss how you would
take this device back if you want it on
the Windows side instead of on Linux.
One easy option is you could just physically
detach the device from your computer and reattach it.
When you reattach it, it'll always come back to Windows.
But if you don't want to do that,
there's a detach command as well.
Back in the administrator command prompt here,
I can run usbipd wsl detach.
Just like before I need to specify
which device I'd like to detach.
Here I'll do dash b 4-2,
just like before and the device is now detached.
We can see that by running lsusb
here and there just device no longer shows up in the list,
and if we look at the Device Manager,
the ST-Link debug device is back.
[MUSIC]
>> How does this all work?
In order to explain,
let me bring in Nelson,
software engineering intern who
worked on the contributions that made this possible.
I'm here with Nelson who worked with us this summer.
Nelson, could you tell us a little about yourself?
>> Sure thing. Hi,
I'm Nelson and I'm
a Software Engineer intern working on embedded tools.
This summer, I worked on enabling developers to
debug enters their USB devices with WSL.
Specifically, I work on improving our third-party tool that
allows users to share devices using the USB IP protocol.
>> Cool. How does that work?
>> You can start by running a Windows command line tool
where you specify USB device that you would like to share.
The tool takes care of routing USB information over
the network and attaching that device inside the WSL instance.
Once attached, you can use a standard Linux
commands as if it was physically attached to the machine.
When you are done using your device,
you can issue another command from Windows to
detach the device from the WSL or just unplug the device.
>> Wow, so I can use
normal Linux commands like ls usb to interact with the device.
What's the architecture to make that work?
>> Great. These tool takes advantage of
existing USB IP protocol support in the Linux kernel,
which in this case acts as USB IP client,
and it also adds USB IP server support on Windows.
The way that this works is that
USB IO messages are forwarded from the Windows server to
the Linux client, which using TCP/IP.
Recent changes in the official WSL Linux kernel configuration
enable these USB IP support.
>> Does this mean that WSL has full USB support now?
>> Not quite yet, but the WSL team is working on it.
For now, however,
we wanted to provide a still a way for users
to debug and test their devices using WSL.
>> What boards can I use this with?
>> We tested this feature with Azure IoT boards,
and ST-Link baseboards,
and it should be compatible with
any other device that utilizes bulk endpoints.
>> Okay. Is there
plan support coming for other boards and devices?
>> For now, the devices which are fully supported are
the so-called bulk endpoints devices,
which include that wire rate of development boards,
feature support for webcams,
joysticks, and other peripherals could be
added by enabling other USB transfer modes.
>> You mentioned earlier that this is third party,
who is the owner and did Microsoft contribute to this project?
>> That's right. This is
a third-party community supported project,
which I contributed features to.
The owner of this tool is Frans van Dorsselaer,
and I would like to give a huge shout out to
him for all the help that he gave us this summer.
>> Awesome. I'm excited to try it.
Where do I go to give feedback and contribute?
>> If you would like to give
feedback or contribute to this project,
you can go to the usbipd-win project and open an issue or PR.
We would love to see how you're
using this tool and if you have any issues with it.
[MUSIC]
>> If you'd like to get started,
check out aka.ms/wsl-usbip and
you can also file a feedback on that site.
We also have a whole bunch of great documentation on WSL and IoT
development on our docs websites
and on the command line blog. Thanks for tuning in.
[MUSIC]