This repository contains a sample project for programming the Raspberry Pi Pico (and all RP2040-based boards) using the following tool stack:
As is, this template project is Mac-specific. However, little would need to change for use on other operating systems. Specifically just the paths contained in .envrc
. I provide the Mac-specific instructions for installing dependencies below.
If not already installed, install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Use the following commands to install CMake, direnv, the Arm GNU Toolchain, VSCode, and the required VSCode extensions:
brew install cmake direnv
brew tap ArmMbed/homebrew-formulae
brew install arm-none-eabi-gcc
brew install --cask visual-studio-code
code --install-extension marus25.cortex-debug
code --install-extension ms-vscode.cmake-tools
code --install-extension ms-vscode.cpptools
In order to install J-Link tools, download and install the appropriate package of J-Link Software and Documentation Pack.
You will need to allow the .envrc
file to be run using:
direnv allow
The .envrc file defines the PICO_SDK_PATH
, the GNU_ARM_PATH
, as well as some variables used when interacting with J-Link.
Open the project folder using:
code .
If you have not used CMake Tools in VSCode before, you will be prompted to select the correct Kit. In our case, this is arm-none-eabi-gcc
located in /opt/homebrew/bin
. For more information, see the relevant documentation about CMake Tools Kits.
You should now be able to build the project in VSCode using the relevant CMake commands.
The project template includes four Debug launch configurations in .vscode/launch.json:
- JLink GDB - Starts and connects to a JLinkGDBServer.
- JLink GDB (RTT) - Starts and connects to a JLinkGDBServer with RTT enabled (output in the VSCode Terminal/RTT pane)
- JLink GDB (Semihosting) - Starts and connects to a JLinkGDBServer with semihosting enabled (output on telnet port 3334)
- JLink Flash - Flashes the code using the script
tools/jlink-flash
To generate makefiles:
cmake -B build -S .
Build:
make -C build -j8
Flash:
./tools/jlink-flash build/hello.hex
For convenience, a Makefile is provided at the root folder to simplify the above commands to:
make flash
- The script at
tools/jlink-debug
starts a JLinkGDBServer and connects using the GDB command-line interface. - The script at
tools/jlink-rtt
starts a JLink session and connects a JLinkRTTClient for viewing.