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.
Chapter 1 Building the Toolset
Homebrew is a great way to have a Mac look like a Linux system. Brew uses similar commands and is able to install similar tools as a Linux system. To start, I recommend installing homebrew then using the following to install the tools you will need:
brew install cmake brew install git
The application make might already be installed, however if it isn’t, you may use brew install make to install it as well.
This is where is gets a bit tricky…as of April 7, 2022, I found an error. Two errors, really. The first error was I used to have homebrew install arm-none-eabi-gcc, however this has been deprecated by Arm. And second, the new version of the software gcc-arm-embedded has a bug which prevents if from working on an M1 Mac. The net of this is that you have the following options: (This installation will be the latest version 11.2-2022.02.)
# Intel Mac use this command brew install gcc-arm-embedded
For M1 Macs, follow these instructions (with additional information as well.)
UPDATED April 7, 2022
Required for M1 Macs, optional for Intel Macs
The complete instructions are:
- Removed the brew installed version of gcc-arm-embedded brew remove gcc-arm-embedded
- I downloaded the version above 10.2-2020.10
- It is a macOS package installer, so it installed it in the ARM directory of Applications
- My first attempt caused an error, where it was looking for the old version
- I used export PICO_TOOLCHAIN_PATH=/Applications/ARM/bin to show it where to find stuff.
Deprecated, left so people know what I used to say…
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:
# THIS HAS BEEN DEPRECATED brew install cmake brew tap ArmMbed/homebrew-formulae brew install arm-none-eabi-gcc
No issues as I had already installed from previous projects.
Chapter 2. Get the SDK and examples (Tested and works as of April 7, 2022)
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 https://github.com/raspberrypi/pico-sdk.git cd pico-sdk git submodule update --init cd .. git clone -b master https://github.com/raspberrypi/pico-examples.git
- For the PICO_SDK_PATH: (copy the absolute path using pwd)
cd pico-sdk pwd /Users/username/Documents/pico/pico-sdk export PICO_SDK_PATH=/Users/lkoepsel/Documents/pico/pico-sdk # If you get "Compiler 'arm-none-eabi-gcc' not found... export PICO_TOOLCHAIN_PATH=/Applications/ARM/bin # continuing on with building of blink cd pico-examples mkdir build cd build cmake .. cd blink make -j4 # plugin Pico with BOOTSEL pressed down to get RPI-RP2 cp blink.uf2 /Volumes/RPI-RP2
Success! No surprise here.
Let’s follow a similar path for Hello_World.
- As before with Linux, use the UART version, not USB.
- 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 https://github.com/raspberrypi/openocd.git --branch picoprobe --depth=1 cd openocd export PATH="/usr/local/opt/texinfo/bin:$PATH" ./bootstrap ./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 https://github.com/raspberrypi/openocd.git --branch picoprobe --depth=1 --no-single-branch cd openocd export PATH="$(brew --prefix)/opt/texinfo/bin:$PATH" ./bootstrap 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 https://github.com/raspberrypi/picoprobe.git 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.
- I needed to use the -s flag to ensure it could find the interface and target files.
- It seemed best to remain in the openocd/src folder to run openocd, as it isn’t installed globally.
- 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"
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.