Developing C on the RP2040 on macOS

Where I install the tools and frameworks necessary to develop code in C on the RP2040 on a macOS platform.



Just as I did for the Linux platform, in this entry I’ll work through the steps required to be successful with developing code in C for the RP2040 on the Mac.

9.1 Building on Apple macOS

Like all good Mac users, I had already installed homebrew. I highly recommend homebrew if you do any development on your Mac. I followed the instructions on the toolchain:

brew install cmake
brew tap ArmMbed/homebrew-formulae
brew install arm-none-eabi-gcc

No issues as I had already installed from previous projects.

2.1 Get the SDK and examples

Let’s install the SDK and examples and test blink! Make sure you follow the structure laid out by the Guide. A base folder of pico with subfolders of pico-sdk and pico-examples.

cd Documents
mkdir pico
cd pico
git clone -b master
cd pico-sdk
git submodule update --init
cd ..
git clone -b master
  • For 2.2 Install the Toolchain, I wasn’t able to install “libnewlib-arm-none-eabi build-essential” using homebrew.

  • For the PICO_SDK_PATH: (copy the absolute path using pwd)

cd pico-sdk
export PICO_SDK_PATH=/Users/lkoepsel/Documents/pico/pico-sdk
# continuing on with building of blink
cd pico-examples
mkdir build
cd build
cmake ..
cd blink
make -j4
# plugin Pico with BOOTSEL plugged in
cp blink.uf2 /Volumes/RPI-RP2

Success! No surprise here.

Let’s follow a similar path for Hello_World.

  1. As before with Linux, use the UART version, not USB.
  2. I use the application Serial, its lovely. If you don’t want to pay for it, minicom is available for the Mac as well. Use “brew install minicom” to install and I used “minicom -b 115200 -D /dev/tty.usbserial-A10K59P8”. Your tty address will probably be different.

Success! Again, no surprise. So far, Linux and macOS are fairly similar.

Chapter 5. Flash Programming with SWD

Let’s move on to where it begins to get tricky. macOS has some issues with openOCD and openOCD is required for communication using the SWD port.

# install the tools
brew install libtool automake libusb wget pkg-config gcc texinfo
git clone --branch picoprobe --depth=1
cd openocd
export PATH="/usr/local/opt/texinfo/bin:$PATH"
./configure --enable-picoprobe --disable-werror
make -j4

Problems with Compiling OpenOCD on a M1 Mac

I had the same issue as this one, namely a missing capstone.h file prevented the openocd from compiling on an M1 Mac. Following the solution was:

brew install open-ocd --only-dependencies
brew install automake
brew install autoconf pkg-config libtool texinfo wget gcc

cd ~/projects/pico
git clone --branch picoprobe --depth=1 --no-single-branch
cd openocd

export PATH="$(brew --prefix)/opt/texinfo/bin:$PATH"
CAPSTONE_CFLAGS="-I$(brew --prefix)/include" \
  ./configure --prefix="$(brew --prefix)"  \
  --enable-picoprobe --disable-presto --disable-openjtag
make -j4

After that, openocd did compile. Many thanks to @idcrook.

Build and Flash PicoProbe

I went ahead and built PicoProbe on my Mac as well, once I realized I had over-written it with Blink. Duh, wrong Pico!

cd pico
git clone
cd picoprobe
mkdir build
cd build
cmake ..
make -j4

Getting OpenOCD to play nice

It took a little bit of work to get openocd to play nice on the Mac.

  1. I needed to use the -s flag to ensure it could find the interface and target files.
  2. It seemed best to remain in the openocd/src folder to run openocd, as it isn’t installed globally.
  3. Due to #2, I needed to specify the folder where the .elf file resided.

Net, net, this worked:

openocd -s ../tcl -f ./interface/picoprobe.cfg -f ./target/rp2040.cfg -c "program /Users/lkoepsel/Documents/pico/pico-examples/build/blink/blink.elf verify reset exit"

Going forward, I will be using a far more simple command (same as the one in Linux), to which I can make an alias:

alias ocd_pp="~/Documents/pico/openocd/src/openocd -s ../tcl -f ./interface/picoprobe.cfg -f ./target/rp2040.cfg"

Running gdb

You can’t install gdb-multiarch on macOS as there isn’t a cask/receipe on homebrew. Instead you use arm-none-eabi-gdb. I found this information here and they also have a nice tutorial on gdb as well. H/T to tinygo!

Make sure you have done the following so gdb can find the symbols:

cd Documents/pico/pico-examples
cd build
cmake -DCMAKE_BUILD_TYPE=Debug ..
cd hello_world
make -j4

Be sure to setup .gdbinit, go here for instructions.

Comments powered by Talkyard.