RIOT develepment on Windows using WSL (Sorta)

Disclaimer: This is a quick guide that I wrote based on my own experience. It might not be the optimal solution, but it works for me. Improvements are welcome.

My main workstation is a Windows machine, but to work with riot I wanted to work in a Linux environment. Thus I use WSL2 to run a virtual Linux environment, combined with VScode as IDE with nice auto-completion and IntelliSense. Sadly you cannot access your USB peripherals from WSL2, so I also have a workaround for programming these devices.

Windows Subsystem for Linux (WSL)

WSL is a virtual Linux on your windows machine. To install it I used the instructions provided here: https://docs.microsoft.com/en-us/windows/wsl/install-win10

This amount to

  1. Enabling WSL using:
    dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart and
    dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart
  2. Setting you WSL to version 2 using: wsl --set-default-version 2
  3. Installing a Linux distribution of your choice (I used ubuntu 20.04LTS):

Do note that you might need to download the latest kernel package as specified in the Microsoft documentation, but I did not need it.

Building RIOT in WSL

As you now have effectively a blank ubuntu installation, you can install RIOT in the usual way.
Make sure that you run your git clone command in the Linux shell, not on windows, as it will use the wrong line endings
You will probably need to install the following packages as well:

  • Git
  • build-essentials
  • gcc-multilib
  • The toolchain for your specific board (In my case arm-none-eabi-gcc, according to the the RIOT documentation

You can verify your installed toolchains/compilers/software by running make print-versions to see if everything is recognized by make.

VScode in WSL.

A nice IDE on windows(or in general) is Visual Studio Code. vscode in windows has some integrations with WSL.
After installing VScode you can run code in your riot directory in WSL to open the folder VScode in windows.

To get a nice autocompletion you can use clangd and bear
You can install both of these using your package manager.

Visual Studio Code has an extension to interface with ClangD, called surprisingly clangd. Install this extension in VScode and make sure to disable the default C++ IntelliSense from Microsoft.

Not the only thing left is to use bear to generate a compile_commands.json. You can do this by running: bear make all ... with your standard arguments on a clean folder.
Make sure this is run on a clean folder use make clean, or else bear will not generate anything
You might need to move the generated compile_commands.json to the root folder of your VScode project.

You can validate if your Intellisense is working correctly for the correct board by autocompleting BOARD_ it should show the board you used in you make command (or Native).

Accesing the USB devices.

Sadly you cannot access your Windows USB devices in WSL. Currently, I am using a Pi3 which exposes it’s USB port using ser2net and I use socat to create a virtual com port in my WSL. There is probably a better way for this but I have not found it. I use these commands:
socat pty,link=~/dev/ttyv0 tcp:<HOSTIP>:5001
on WSL and as my ser2net config:
3333:raw:600:/dev/ttyACM0:1200 8DATABITS NONE 1STOPBIT
Suggestions for a better way are welcome.

TL;DR VScode works well with WSL, use it to dev riot on windows.

8 Likes

I also wrote some things down when I installed it within WSL. I think the troubleshooting parts might help some people. I don’t remember the exact tapsetup error though.

Troubleshooting

Error: WslRegisterDistribution failed with error 0x8007019e and 0x8000000d – WSL

Tapsetup fails

Try setting the following values in /etc/sysctl.conf in your linux system.

net.ipv6.conf.all.disable_ipv6 = 0
net.ipv6.conf.default.disable_ipv6 = 0
net.ipv6.conf.lo.disable_ipv6 = 0
1 Like

A small sidenote on the ser2net configuration. The baudrate of 1200 baud automatically forces the NRF52840 into bootloader mode. I increased the baudrate default to 115200, and added the option for the client to change the baud rate. The new ser2net config then becomes: 3333:raw:600:/dev/ttyACM0:115200 8DATABITS NONE 1STOPBIT,remctl

I cannot edit this in the original message, maybe someone with more permission can also change the command there.

The programming setup was a bit unstable, especially with the socat interface not always connecting. So I recently moved away from using WSL.
As I was using a Pi3 for the programming, I now use the remote ssh extension from visual code, and I now work directly on the pi. I used these instruction to configure it: