I really like the RP2040

Date: unknown

Location: dgroshev.com

The RP2040 is a microcontroller made by Raspberry Pi. Unlike their more widely known products, the RP2040 is meant to be embedded in consumer electronics. It's cheap and available in tens of thousands for immediate dispatch from your local Mouser.

I really like the RP2040 and I want you to know why.

Just the right size

Here is the Mouser stock for a microcontroller manufacturer Espressif:

Dozens of slightly different controllers. Why?

Unlike software, physical products cost money to manufacture. Every cent saved on a gizmo's components is a cent in earnings, which adds up when the gizmos are manufactured by the million. This creates an incentive to pick a microcontroller that is only just powerful enough (to "right size" it), and usually microcontroller manufacturers are happy to help, offering dozens of variations of the same microcontroller.

Here is the Mouser stock for Raspberry Pi:

(This is the same microcontroller, just two different packaging options1.)


…as long as it's black

Raspberry Pi pulled a Henry Ford and boldly went with just one microcontroller.

There is no choice, no right sizing, but that might be OK! An RP2040 costs ~70 cents, and not all gizmos are produced by the million.

In return, Raspberry Pi ensured that everyone on the planet works with the same part. Compared to more traditional wide lineups, there is a disproportionate number of StackExchange questions, blog posts (including this one), experience, Github issues, libraries, and tools for the RP20402.

This is a good tradeoff for projects like Late Mate, which are likely to save more on development costs than on parts3.

Down the stack

This single model pragmatism is evident in the choices Raspberry Pi made for the microcontroller itself. It is designed to be a jack-of-all-trades, trading "excellent" for "sufficient and flexible":

  • Two decent cores. The second core is there if you need it.
  • 30 GPIO pins, a very average number.
  • No on-board flash, spending the budget on more internal RAM that is much harder to wire externally.
  • An OK ADC, good USB support, and the usual peripherals (UART/SPI/I2C/PWM).

Less conventionally, the RP2040 comes with a peripheral called "PIO" for Programmable Input/Output. It's like two tiny coprocessors that can execute your IO fast, with precise timing, and without spending CPU time. Some cool things people do with PIO:

The RP2040 is impossible to brick. It comes with a read-only bootloader that can either mount as a USB mass storage device (firmware updates can just be copypasted to the "storage device"), or use its own simple USB protocol.

In the same pragmatic vein, the RP2040 doesn't engage in security theatre. Protecting the firmware from a dedicated attacker is nearly impossible, but there are complexity and DX costs to trying, so I'm glad Raspberry Pi made the call.

I just love the deliberate design of this little square of silicon. When I work with it, I can see how smart people thought hard about the niche the RP2040 is in and drove the tradeoffs accordingly. As an engineer aspiring to be good someday, I appreciate it.

Discuss on Hackernews

More of ^this^ on Mastodon, Twitter, RSS, or a very occasional newsletter.

Or just let me know what you think at dan@dgroshev.com!