Read this First Before Developing C on the RP2040

Where I explain the issues which impact developing C/C++ code on the RP2040.

Sources

Introduction

There are three fundamental steps one must take to fully develop C/C++ code on the RP2040. Both the Raspberry Pi “Getting Started with Pico” known as the Guide from here on and this blog utilize this approach:

  1. Install the tool chain necessary to cross-compile C/C++ and link code for the RP2040 on the platform of choice.
  2. Test #1 using the Raspberry Pi Pico Github code using the pico-sdk and pico-examples.
  3. Advance the ability to debug by adding a hardware debugger in the form of the Picoprobe and gdb.

For each of the platforms, there is a level of complexity to accomplish each step. Its important to understand that the tools that exist to accomplish cross-compiling and linking C/C++ for an embedded microcontroller are designed for Linux. Therefore, the closer a system “looks like Linux”, the easier it is to follow the three steps. This isn’t a problem. It is simply something to understand and account for. Specifically, the level of difficulty of the three steps in each operating system is:

Linux

  1. Toolchain Easy.
  2. Pico code Easy
  3. Debug Easy

macOS

  1. Toolchain Easy.
  2. Pico code Easy
  3. Debug Intermediate, might require more work to implement.

Windows

  1. Toolchain Intermediate, requires a different approach than usual in Windows.
  2. Pico code Easy, however there can be bugs.
  3. Debug Complex

Why It Is Worth It

If you don’t have a Linux computer or you have a Windows computer, you might ask yourself, why would I pursue this? Because you can have a well-documented, fully supported, high quality hardware debugger and embedded 32-bit ARM Cortex-M0+ microcontroller system for only $15. I emphasize the system aspect, as this isn’t simply one board, this is two boards with one acting as a hardware debugger, while the other is the target.

This is an incredible feat and for which, I don’t believe the Raspberry Pi Foundation has been given sufficient credit. The vision and execution is outstanding! Thank you, Eben Upton, James Adams, et al.

BTW, here are the parts that comprise the “$15 debugger/target system”:

  • First Pico to serve as a target board, $4
  • Second Pico to use as a PicoProbe for debugging, $4
  • FTDI breakout board and cable for console I/O from target system i,e; Adafruit, Sparkfun or Olinuxino Serial Console Cable $7
  • A breadboard which can contain both Pico’s (optional, however a pain without it)

OK, now what?

Get started!

Be aware that there might be some difficulty in the initial steps of installing and confirming the operation of the tool chain required. Understand that you might need to download and install a fair number of software applications. And that some of those applications might use commands and a language that is difficult to understand.

That said, if developing code on an embedded microcontroller is important to you, the steps you take to accomplish these tasks are very important. And learning what it takes to implement and use the tool chain will be very useful.

One Last Thing

Don’t follow many, if not all of the examples and start using Visual Studio Code. If you are presently using it and like it, fine, continue. If you haven’t began to use it and are not well accomplished in the use of a Integrated Development Environment (IDE), don’t start…yet.

IDE’s can be great in that they automate a lot of the development experience. This is paramount if you are an engineer developing code for a living. An IDE will raise their productivity. The engineer using the IDE has already spent a tremendous amount of time, understanding the intricacies of compiling, linking, loading and debugging code, more than likely via the command line.

If this content how to develop C/C++ on an RP2040 is new, particularly using gcc, CMake, make, openocd and gdb, then embrace using those tools by themselves. This will help you understand them much better. And understanding them now will make you much more proficient later when you are sufficiently knowledgeable to use an IDE.

Good luck and have fun!

Comments powered by Talkyard.