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
- 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
- Setting you WSL to version 2 using:
wsl --set-default-version 2
- 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.