Raspberry Pi Pico and Mecrisp Forth

Raspberry Pi Pico

By stalking some IRC channels, I found out about the Rasberry Pi Pico RP2040 board:

My Raspberry Pi Pico board

It is a microcontroller board with a Dual ARM Cortex-M0+ running at 133MHz. I wanted to experiment with assembly programming on a microcontroller, but there were are a few things about the AVR- and ESP-based systems that don't appeal to me. Since this RP2040 only costs $8, it seemed worth at least buying one unit to study.

I haven't been much interested in the larger Raspberry Pi computer boards, partially because they are not microcontrollers, and partially because of some things I had read about non-free code required for part of the boot process. I do not think the Pico has problems with that — my understanding is that the bootloader is all free software, though I haven't been able to look into that in detail yet.

This system implements the ARMv6-M architecture, which has a simpler programming model than the ARMv7, and simpler is good for my present purposes. I'm hoping to learn how to use the DEBUG line, with the idea of running ARM assembly code with a debugger.

The Pico has a nifty BOOTSEL button which causes your Pico to boot up as a USB mass storage device, allowing you to drag and drop in your firmware binary as a u2f file. That is the easiest and most portable firmware loading approach I've worked with so far.

Mecrisp Stellaris Forth

It turns out that there is an interesting Forth called Mecrisp Stellaris which supports this MCU (and 62 others).

Mecrisp Stellaris Unofficial UserDoc

I had become a little jaded about Forth on microcontrollers, since discovering that the last two Forths I experimented with, flashforth and punyforth, both have non-free dependencies.[1] But Mecrisp Stellaris does not seem to have this problem — the author assures me that "nothing proprietary is necessary for building from scratch", and it depends on GNU Binutils for ARM. I'll have to try building it myself later, but that was encouraging.

I've only been able to spend a few minutes experimenting with Mecrisp, but so far it seems like a nice Forth. Here are a few things I like:

- A `see' word is included for disassembling any word's code field.

- It has mode-switching words to switch between compiling definitions to flash or to ram.

- When doing a `words' listing, not only the names are outputted, but the memory addresses of the various fields (ADDRESS, LINK, FLAGS, and CODE).

- The Mecrisp source code package includes a loadable assembler in case you want to intersperse some assembly in your Forth definitions without using an external assembler.

- Friendly support is available at the #mecrisp IRC channel on Libera.

End Notes

[1] FlashForth is itself all free software, but is built on Microchip's proprietary suite for assembling and linking. I was able to get it to build with avr-gcc, but for some as-of-yet unascertained reason, the binary did not run correctly when loaded onto my AVR board. Punyforth uses the Espressif SDK, with some core components of that being non-free blobs.

Proxied content from gemini://gem.librehacker.com/gemlog/tech/20220305-0.gmi

Gemini request details:

Original URL
gemini://gem.librehacker.com/gemlog/tech/20220305-0.gmi
Status code
Success
Meta
text/gemini
Proxied by
kineto

Be advised that no attempt was made to verify the remote SSL certificate.