Compiling Arduino Mbed OS Core for the Raspberry Pi Pico in Debug Mode

A project log for Raspberry Pi Pico Emulator

Live-coding an Open-Source Pico Emulator from Scratch

Uri ShakedUri Shaked 05/09/2021 at 17:390 Comments

In one of the recent live streams, we tried to debug a program compiled with the official Arduino Core for the Pi Pico. 

However, debugging it proved difficult: the Arduino Core produces programs without debugging info. In addition, it's based on Mbed OS, an embedded operating system for ARM Cortex-M processors. Mbed OS adds another layer of complexity: it manages tasks and threads, and does a lot of work behind the scenes even for a simple Blink program.

Therefore, I decided to compile the Arduino Core for Pi Pico from scratch, and this this with debugging symbols. This log explains how I did it. If you want to follow it, you need an Ubuntu or Debian-based Linux system (for Windows users, WSL is also fine).

1. Installing Dependencies

Install the Mbed OS CLI. For Linux:

sudo apt install python3 python3-pip git mercurial
python3 -m pip install mbed-cli

For other environments, check out the Mbed OS CLI documentation

In addition, the Arduino Mbed OS core requires jq. Install it too:

sudo apt install jq

2. Get the source code

git clone arduino-mbed-os
git clone

Note how we clone mbed-os from Arduino's GitHub. They have their own fork with patches specific for the Pi Pico. At the time of writing, they still haven't merged these patches upstream.

3. Patch it

Apply the following patch to the ArduinoCore-mbed. The patch enables debug build:

diff --git a/mbed-os-to-arduino b/mbed-os-to-arduino
index 902b0c5d..921c39a8 100755
--- a/mbed-os-to-arduino
+++ b/mbed-os-to-arduino
@@ -130,6 +130,9 @@ mbed_compile () {
export PROFILE=-${PROFILE^^}
+ else
+ export PROFILE="-DEBUG"
+ PROFILE_FLAG="--profile=debug"

4. Build it!

cd arduino-mbed-os
git checkout rp2040
mbed deploy

cd ../ArduinoCore-mbed
./mbed-os-to-arduino -r "`pwd`/../arduino-mbed-os" RASPBERRY_PI_PICO:RASPBERRY_PI_PICO

You may be able to skip mbed deploy - I not sure if it's actually needed.

If everything went well, you'll find the compiled library under ArduinoCore-mbed/variants/RASPBERRY_PI_PICO/libs/libmbed.a. The debug symbols make it pretty heavy - expect a 135MB file.

You can copy this file over your existing libmbed.a in the Arduino directory, e.g.:

cp  ArduinoCore-mbed/variants/RASPBERRY_PI_PICO/libs/libmbed.a ~/.arduino15/packages/arduino/hardware/mbed_rp2040/2.0.0/variants/RASPBERRY_PI_PICO/libs/libmbed.a

The target path may vary depending on your system configuration and the version of the mbed_rp2040 core you have installed. 

Happy debugging! ;-)