Development on Windows using WSL

The CPSC359 VM is an option for most Windows devices, but modern Windows includes an awesome tool (that you should get familiar with anyway!) called Windows Subsystem for Linux - WSL.

WSL is a slim virtual machine that runs Linux and tightly integrates it with Windows. It is essential for any modern developer as it lets you have a neat combination of Windows and Linux development environments.

I won’t go into how to install and set up WSL here as this is covered quite nicely elsewhere, but I will provide the specific steps for hooking up your Pi and using WSL to do everything you need it to.

This guide is here as a reference to get you started if you are feeling adventurous enough to try this out. Support for development and compiling on WSL cannot be provided; you’re on your own if you go this route!

Requirements

Software setup

You only need a few packages to get going, install them with the following command:

sudo apt install openocd screen build-essential gdb-multiarch

To build software you will also need the aarch64-elf toolchain. The easiest way to install this in WSL is to use Homebrew. Run the Homebrew installation command given on the Homebrew website, and then follow the steps in the Homebrew-on-Linux documentation to add it to your $PATH.

With Homebrew installed, simply run brew install aarch64-elf-gcc. This will install the correct compiler toolchain for you to build baremetal code inside of WSL!

Now looking outside of the VM, you need to install a driver called usbipd to attach USB devices to the WSL VM. Some more information on this is given on the Microsoft documentation site, but the gist is to just do the following:

In Windows Terminal, run: winget.exe install --interactive --exact dorssel.usbipd-win (you can run Windows executables from inside of WSL!). If you don’t have winget (it should be included in all installations of Windows 11 now), go to the Github page for usbipd and download the installer.

Once you have installed usbipd, restart your computer.

Hardware setup

With WSL and the usbipd driver set up, hook up your Pi to your computer via USB-B and turn it on. In an elevated Powershell window (right click Powershell and select “Run as Administrator”), do the following:

That’s it! The Pi is hooked up to WSL and you can use all the tools as you’d expect EXCEPT in the case that gdb must be invoked as gdb-multiarch so;

openocd -f /path/to/rpi4.cfg
-- new terminal --
gdb-multiarch
set architecture aarch64
target extended-remote :3333
-- new terminal --
screen /dev/ttyUSB1 115200

Support

Please note that I cannot provide support for a WSL development environment. This is simply because I don’t have access to one readily available.

The official means that you have at your disposal to develop for CPSC359 is to use the CPSC359 VM or any of the computer science lab spaces.

If you are having a hard time finding a space to work on campus, please contact cpsc.uls@ucalgary.ca and we can help.

Thanks to Ivan Agalakov for the tip on using WSL for development!