By default, WSL does not have access to any USB devices. You will need to use the following workaround if you want to run the program through WSL.
Take a look at the following Microsoft Article if you need additional help: https://learn.microsoft.com/en-us/windows/wsl/connect-usb
The following instructions are for Ubuntu 20.04.
-
Install the latest version of usbidp: https://github.com/dorssel/usbipd-win/releases
-
In WSL:
sudo apt install linux-tools-virtual hwdata sudo update-alternatives --install /usr/local/bin/usbip usbip `ls /usr/lib/linux-tools/*/usbip | tail -n1` 20
-
Run:
usbipd.exe wsl list
. This will list all your USB devices. The STM32 will be labeled something with the word "ST-Link". Note itsBUSID
(something like2-2
). -
Replace
BUSID
with the value ofBUSID
found in the previous stepusbipd.exe wsl attach --busid=BUSID
-
Run
usbipd.exe wsl list
again and confirm that the STM state is now attached to Ubuntu. -
Run
lsusb | grep ST-LINK
to list the STM device. Confirm that the STM is showing up correctly. -
Run the following to enable permission for non-root user to access the STM:
sudo bash -c 'cat <<EOF > /etc/udev/rules.d/99-openocd.rules # STM32F3DISCOVERY - ST-LINK/V2.1 ATTRS{idVendor}=="0483", ATTRS{idProduct}=="374b", MODE:="0666" EOF'
-
Reload the new rules:
sudo udevadm control --reload-rules
. If you get an error that "Failed to send reload request: No such file or directory", runsudo service udev restart
then run it again. -
Run:
usbipd.exe wsl detach --busid=BUSID
thenusbipd.exe wsl attach --busid=BUSID
(effectively unplugging then plugging the USB back in). -
Done! You can now run the program from WSL.
If you ever unplug the STM from your computer, you will need to do a couple of commands before you can run the application.
-
Get the
BUSID
:usbipd.exe wsl list
-
Attach the usb to WSL:
usbipd.exe wsl attach --busid=BUSID