Setting up Qt Creator for Pi Pico RP2040 development

Qt Creator is tricky to set up for RP2040/Pi Pico development, but fairly quick once you know the steps. I was unable to make Pico projects run correctly under VS Code using Raspberry's suggested editor extension.

Note: These are personal notes from setting up Qt Creator for Raspberry Pi Pico 1 development on a new machine, organized into an article after the fact. They are specific to my machine (Arch Linux, fish shell) and may have missing or outdated steps, which may not fully succeed on a new machine or user account.

IDE setup

If you're using Arch Linux, you can install dependencies as follows:

# paru -S pico-sdk  # github raspberrypi/pico-setup only works on apt-based systems
cd (path to pico-sdk (either ~, a code folder, or a files folder))
git clone https://github.com/raspberrypi/pico-sdk.git
set -Ux PICO_SDK_PATH $PWD/pico-sdk

sudo pacman -S --needed arm-none-eabi-gcc arm-none-eabi-newlib arm-none-eabi-gdb

I cloned https://github.com/raspberrypi/pico-sdk, but you could alternatively paru -S pico-sdk. The official PDFs suggest raspberrypi/pico-setup, but I found the script only works on apt-based systems.

While attempting to attach Qt Creator's gdb backend to the Pico, I ran into repeated debugger lockups. It turns out the latest release of OpenOCD is too old to work properly with multicore Pi Pico programs, and switching to paru -S openocd-raspberrypi-git magically fixed all debugging issues. I later tried installing openocd-git which worked fine as well.

Once you've installed dependencies, it's time to set up Qt Creator.

Sidenote: Why does Qt Creator configure the Desktop device in the Devices tab, while Bare Metal devices have no options besides picking a named bare metal configuration, which gets created in the Bare Metal tab? The two tabs are needlessly different too; the Devices tab has a device dropdown, Add button at the right, and a full-screen configuration, while the Bare Metal tab has a left-side visible list of configurations, Add and Clone button at the bottom, and configuration at the right. I wonder if this is due to bare metal support living in a plugin rather than core, which can't add new configuration screens to the Devices tab.

Project setup

At this point, you can build .uf2 files in Qt Creator and drag them to your Pi Pico in BOOTSEL mode as usual.

If you want to attach a debugger, you'll need a second Pi Pico flashed with the Raspberry debugprobe (formerly picoprobe) firmware. Attach the debugprobe's GPIO pins to the first Pico's SWD pads, and plug the debugprobe to your PC over a USB cable. Now Qt Creator's Run and Debug buttons will flash and debug your first Pico over SWD, as if you were launching programs on your PC.

Tip: Every time you open a new Pico CMake project, you'll end up with two run configurations. There's no point in running bs2_default (a boot stage rather than the complete project), so in the sidebar click Projects, open the "Run Settings" tab, and remove bs2_default. You'll have to repeat this for each project you open.

Fixing broken projects

A Pico project needs a pico_sdk_import.cmake file copied from <PICO_SDK_PATH>/external/pico_sdk_import.cmake. If the file is missing, CMake configuration may find the compiler but not the RP2040 toolchain config, use the wrong compile/link flags, and throw an error undefined reference to `_exit'.

To resolve this error, first copy pico_sdk_import.cmake into your project root, then delete your CMake folder and reconfigure from scratch to fix compilation flags. (CMake is infamous for having a non-memoryless configuration system, which fails to invalidate cache and update configuration when you change build parameters or update your toolchain.)