A feature that sets the Raspberry Pi Foundation RP2040 microcontroller apart from other microcontrollers is "PIO". The RP2040 datasheet says that the "programmable input/output block (PIO) is a versatile hardware interface. It can support a variety of IO standards… PIO is programmable in the same sense as a processor."
In this guide, you'll learn how to write and use PIO programs from CircuitPython. The official datasheet (chapter 3), the book "Get Started with MicroPython on Raspberry Pi Pico" and pico-examples (pio folder) are helpful resources too, but CircuitPython sometimes deviates from the way that PIO is used in other environments like C or MicroPython.
Instead, an implicit
.wrap is at the bottom of every program, and an implicit
.wrap_target is at the top of every program. You can add a
jmp instruction instead of using
.wrap but remember that this slightly changes the instruction length and the timing of your pio program.
mov instruction can accept an optional argument, called an operator, to reverse (
::) or invert (
~) its argument. In adafruit_pioasm, one or more spaces must come between the
~ and the operand. These spaces are not required by the official dialect.
The official dialect allows "!" to mean the same as "~". This is not accepted by adafruit_pioasm.
Standard pioasm supports expressions like
[T1 + 1]. In pioasm, calculations are not supported. Instead, use string formatting operations to insert the computed value where necessary, e.g.,
These examples were designed for the Raspberry Pi Pico but can be adapted to the range of boards with the RP2040 microcontroller. The QT Py RP2040 requires the addition of an external LED and current-limiting resistor for the standard LED examples.