FreeRTOS on a Pico – Part 0

I recently picked up a couple of the relatively new Raspberry Pi Pico controllers, and yesterday I began what I hoped would be a fairly painless process of compiling the open-source real-time operating system FreeRTOS onto a Pico.

I’m still working on it. I’m going to start taking notes here, so I can keep track of what does and doesn’t work. (I expect to be doing this again.)

There are a lot of nicely produced YouTube videos that would seem to make the process straightforward, but I haven’t yet been successful with any of them.

The first one I tried was How to Use FreeRTOS on the Raspberry Pi Pico (RP2040) Part 1: VSCode Setup and Blinky Test! by Learn Embedded Systems. It’s a nicely done video, but it begins after the necessary toolchain and CMake setup has been completed. My problems start before this gentleman’s narration begins, and I’m still working on that.

Bit of Context

I’m traveling this week, so I’m doing my development on a Windows 11 laptop. Ideally I’d end up with a cross-compilation environment running on Windows. I plan to do quite a lot of development for the RTOS, so I want something substantially richer than my standard embedded Linux tools (vi, g++, make). I expect to end up with VSCode, which I really haven’t used yet but suspect I’ll be using more in the future.

Speaking of unfamiliar, I’ve also never used CMake, at least not in any very deliberate way. (It’s used behind the scenes in my Qt development environment, but my interaction with it has been little more extensive than adding dependencies to a CMakeLists.txt file.) CMake is impressive, and I’m going to have to learn it.

Unfortunately, it’s also been a sticking point, though I think I’ve finally resolved that.

Toolchain

I haven’t set up many cross-compile toolchains, and it’s been years since I last did. Setting up for the Pico on Windows wasn’t bad. I went to the Arm Developer site, Arm Holdings being the company behind the ARM Cortex processor on the Pico (and a host of other small computer/controller products).

As of this writing the latest release version is 11.3.Rel1. It can be found here. The toolchain installation went smoothly, and VSCode (which is trivially easy to install) found it without a problem.

CMake

As I said, I’m really not familiar with CMake. Installation was easy: I went to the CMake.org download site, here, and downloaded the latest Windows installer.

VSCode, Python, Pico_SDK, Ninja, etc.

Nothing special here.

First Problem: CMake on Windows

I got VSCode configured to the point where CMake appeared to run correctly and create the build scripts. That took a few hours, mostly because I had to keep going back and resolving dependencies (CMake, Ninja, Python) as I discovered them. Also, it took awhile to get comfortable with the VSCode configuration files and extensions. When I reached the point where CMake appeared to be happy and it created the build scripts without reporting errors, I clicked the Build button for my sample application (the LED-blinking demo described in the video linked earlier) and held my breath.

The build process failed. The specific problem was that the linker was being passed unrecognized flags, flags appropriate to Windows builds but not for a bare-metal build on the Pico.

The offending flags were: –major-image-version and –minor-image-version.

Nothing I tried prevented CMake from generating Ninja build instructions that contained link flags (and, occasionally, library references) appropriate for Windows but not for my Pico target system.

I don’t doubt that the error is mine. It might even be easy to fix. But I’ve given up on that route for now.

Some hours later…

What I’m trying now is to trying to follow the instructions at the Raspberry Pi Pico site. Those instructions are for a Linux host running on a Raspberry Pi. I installed Debian under WSL on my Windows 11 laptop, and am trying to run the pico_setup.sh script described in the Getting Started document.

Progress? Mixed. The latest CMake package for this Debian release is too old, so I had to download source and rebuild CMake. That’s done. Similarly, the latest Python package is too old. I’m in the process of rebuilding that in my Debian environment as well. [Update: I think I could have apt-get’d python3 and received the release I needed.]

Once that’s done I’ll try again to run the pico_setup script.

Some more hours later…

The pico_setup.sh script didn’t work in my WSL Debian setup. I ran into build problems in the Pico SDK having to do with the noexcept C++ keyword. I fixed those, but then encountered further problems having to do with missing USB components while building picoprobe and picotool.

I could have gone back and re-run the entire script after deleting work already done: somewhere along the way it gave me suggestions about how to fix the USB problem.

But the script is really aimed at Linux running on a Raspberry Pi, not in a Win11 WSL session. It crashed again when it tried to git the vscode repository. I didn’t like having to patch things just to get the script to run all the way through, so I went back to the drawing board.

I found this. I’m half way through it now, and liking what I see so far. More soon….

Hiccough 1: As with the pico_setup.sh attempt, the CMake installed in Debian is too old for the Pico builds. The latest apt-get retrieves is 3.7.2. I need 3.12 or later. So I’ll do what I did last time: download and build CMake 3.25.1 (current latest). Back soon….

And… success! I now have a working build environment and can compile and run the pico-example programs.

Next step is to get VSCode running. This same fellow includes instructions for that, so let’s try it. Back soon….

Finally, success.

Everything now works — except the debugger. I’ll get that sorted out soon.

But as things now stand I’m able to run VSCode in a Debian WSL session and edit and compile code which I can then download to the Pico and watch it run.

I’m building a full FreeRTOS runtime: the Pico is hosting a small real-time operating system and running my code inside it.

To get here I had to make one edit to the pico-sdk files. In pico-sdk/src/rp2_common/pico_standard_link/new_delete.cpp, add the following to the top of the file to correct a compile error on line 22:

#define noexcept

That will remove the noexcept term, which appears to be used only in this file.

(Note to self: Make sure that this doesn’t negatively impact memory management by making the no-longer-flagged function uncallable. I’m not really clear on the nuances of the new noexcept keyword.)

Other than that modification, all I did to get basic Pico support working was build the latest CMake and install Ninja (ninja-build), and follow the excellent instructions mentioned above (here, again) for setting up WSL appropriately and linking VSCode to it. (I think VSCode is going to grow on me for all embedded work.)

To configure VSCode within the WSL I went back to the video and website mentioned earlier here. The instructions on that site didn’t include toolchain, etc., setup, but the two sites together covered all the bases.

I am content.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>