Cross-compiler Raspberry Pi Pico

Microcontrollers generally use a different CPU architecture than the developer’s laptop. This implies a cross compiler is needed to build code for the microcontroller on the laptop. It’s straightforward to install the Raspberry Pi Pico ARM C / C++ cross-compiler on macOS, Windows, and Linux.

Please follow the section relevant to the laptop operating system. About 2..5 gigabytes of hard drive space is required by the Raspberry Pi Pico SDK and associated tools.

Git, CMake and a cross compiler are used by almost all full projects as well. This script will install the cross-compiler and other tools needed for the Raspberry Pi Pico SDK, or follow the manual process below.

#!/usr/bin/env bash

set -e

# determine OS and arch
case "$OSTYPE" in
linux*)
sudo apt update
sudo apt install git cmake g++ gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib;;
darwin*)
brew install git cmake
brew install --cask gcc-arm-embedded;;
*)
echo "$OSTYPE not supported"
exit 1
esac

macOS

Homebrew install Git, CMake build system, and ARM cross-compiler by:

brew install cmake git

brew install --cask gcc-arm-embedded

The cross-compiler executables have a prefix “arm-none-eabi-” that are linked into $(brew --prefix)/bin for easy use from the command line.

It’s likely the macOS laptop has an Apple Silicon CPU. If so, it’s necessary to enable Rosetta. Rosetta enables most x86 apps on Apple Silicon at nearly full performance.

Note: if on macOS you get a build error like:

arm-none-eabi-gcc: fatal error: cannot read spec file ’nosys.specs’: No such file or directory

and you’ve installed the GCC cross-compiler via:

brew install --cask gcc-arm-embedded

Then something is wrong with the cross-compiler setup.

Linux

Install Git, CMake build system, and ARM cross-compiler on:

  • laptop/desktop with Ubuntu / Debian-like distros
  • full Raspberry Pi (e.g. Raspberry Pi 4)
apt update

apt install git make cmake g++ gcc-arm-none-eabi libnewlib-arm-none-eabi libstdc++-arm-none-eabi-newlib

Windows MSYS2

pacman -S mingw-w64-x86_64-arm-none-eabi-gcc

This takes about 2GB of storage.

Windows WSL

Windows Subsystem for Linux (WSL) is useful for many projects including the Raspberry Pi Pico SDK. WSL can be the easiest way to work with non-Windows projects on Windows.

The Ubuntu WSL process takes about 10 minutes depending on download speed. WSL can be installed via the Microsoft Store Ubuntu app. If the Microsoft Store isn’t available on the computer, it is also possible to install Ubuntu WSL manually.

WSL can access the native Windows filesystem. WSL sees the native Windows filesystem “C:” in WSL via “/mnt/c”. Use the native Windows drive under “/mnt/c/pico” from WSL. Then use Windows File Explorer in path “C:/pico” to drag and drop .uf2 file to Pico.

The cross-compiler install on WSL Ubuntu is just like plain Linux in the section above.

To make switching between Windows and WSL easier, optionally use Windows Terminal.

Alternative: Visual Studio

The Visual Studio cross-compiler setup is described in Section 9.2 of the Pico install guide.