
microPIO is a tiny programmable-I/O engine, in the spirit of the RP2040 PIO, for the Tiny Tapeout micro tile. You write a three-instruction program into the chip, and the chip then runs it one instruction per clock, bit-banging two output pins and watching two input pins with exact cycle timing. It can produce SPI, UART-like, PWM or any other simple serial waveform without a CPU.
An instruction is 6 bits: {opcode[2:0], operand[2:0]}. The three instructions live in a ring: after each
instruction the next slot becomes the current one, so a 3-slot program loops by itself.
| Op | Name | Operand [2:0] |
Effect |
|---|---|---|---|
| 0 | JMP |
op[2]=0 |
jump back one slot |
| 0 | JMP x-- |
op[2]=1 |
if X != 0: X = X - 1 and jump back one slot; if X = 0: go on to the next slot |
| 1 | WAIT |
op[1] = polarity, op[0] = pin |
stall (STALLED = 1) until PIO_IN[pin] == polarity |
| 2 | SHIFT |
op[2] = auto-pull, op[1] = side, op[0] = input pin |
PIO_OUT[1] = side; PIO_OUT[0] = SR[3]; SR = {SR[2:0], PIO_IN[pin]} (see below) |
| 3 | SET_PIN |
op[2]=0: op[1:0] |
PIO_OUT = op[1:0] |
| 3 | SET_PIN (side-set) |
op[2]=1: op[1] |
PIO_OUT[1] = op[1], PIO_OUT[0] unchanged |
| 4 | SET_X |
op[1:0] |
X = op[1:0] |
| 5 | PULL |
none | stall until STROBE rises, then SR = DATA_IN |
| 6 | DELAY |
op[1:0] |
while X != 0: hold this instruction and X = X - 1; when X = 0: X = op[1:0] and go on. With X = n the instruction takes n + 1 clocks |
| 7 | INV |
none | SR = ~SR |
SHIFT with auto-pull (op[2] = 1): when SR_DONE = 1 (four bits have been shifted, or after reset/PULL) the
instruction stalls until STROBE rises, then it loads SR = {DATA_IN[2:0], PIO_IN[pin]}, outputs DATA_IN[3]
on PIO_OUT[0] and restarts the 4-bit count. So four SHIFTs move one data nibble out (MSB first) while the
same four SHIFTs move one nibble in (the result is in SR).
SR_DONE is 1 when the 2-bit shift counter is 0: after reset, after PULL, and after four SHIFTs.
SR is the shared 4-bit shift register shown on uo[7:4].
A stalled instruction changes nothing (the engine simply waits). Only JMP, DELAY and the stall conditions
change the order of execution; every other instruction takes exactly one clock.
ui[0] PROG_MODE = 1. The program does not run while PROG_MODE is 1 (and the bit counter and X are cleared).ui[7:2] (INST[5:0], ui[2] is the least significant bit).ui[1]) high then low. The instruction is shifted into the ring on the rising edge.SET_X 0 = 0x20).The ring is only written in PROG_MODE; reset does not clear it.
| Slot | Instruction | Value on ui[7:2] |
What it does |
|---|---|---|---|
| 0 | SHIFT auto-pull, side 0, pin 0 |
0x14 |
SCK low, next MOSI bit out, MISO bit in; waits for STROBE between nibbles |
| 1 | SET_PIN side-set, SCK = 1 |
0x1E |
raise SCK, MOSI unchanged |
| 2 | SET_X 0 (filler) |
0x20 |
one clock of nothing |
Run it with ui[7:4] = the nibble to send and a rising edge on STROBE. The engine sends the bits on PIO_OUT[0]
(MOSI) with SCK on PIO_OUT[1] (three clocks per bit), reads MISO from PIO_IN[0], and after four bits shows
the received nibble on uo[7:4] with SR_DONE = 1 and STALLED = 1 (waiting for the next STROBE).
Each program is three instructions; load it as described under Programming. Full tables, waveforms and notes: docs/EXAMPLES.md in the repository.
| Example | Slot 0 | Slot 1 | Slot 2 | Behaviour |
|---|---|---|---|---|
| SPI master, slow clock | SHIFT auto-pull, side 0, pin 0 (0x14) |
DELAY n (0x30 + n) |
SET_PIN side-set 1 (0x1E) |
the SPI example with SCK = clk / (n + 3) |
| Nibble serializer | SET_X 3 (0x23) |
SHIFT auto-pull (0x14) |
JMP x-- (0x04) |
one STROBE sends one nibble, MSB first, 2 clocks per bit (strobe after clock 0) |
| PWM, mostly high | SET_PIN 1 (0x19) |
DELAY n (0x30 + n) |
SET_PIN 0 (0x18) |
high n + 2, low 1 clocks |
| PWM, mostly low | SET_PIN 1 (0x19) |
SET_PIN 0 (0x18) |
DELAY n (0x30 + n) |
high 1, low n + 2 clocks |
| Triggered pulses | WAIT PIN1 HIGH (0x0B) |
SET_PIN 1 (0x19) |
SET_PIN 0 (0x18) |
a pulse every 3 clocks while PIO_IN[1] is high |
| SPI slave / receiver | WAIT PIN1 HIGH (0x0B) |
SHIFT pin 0 (0x10) |
WAIT PIN1 LOW (0x09) |
SCK on PIO_IN[1], data on PIO_IN[0]; SR = the last four bits |
| Delay line | SHIFT (0x10) |
SHIFT (0x10) |
SHIFT (0x10) |
PIO_OUT[0] = PIO_IN[0] delayed by four clocks |
| Sequencer | SET_PIN 1 (0x19) |
SET_PIN 3 (0x1B) |
SET_PIN 2 (0x1A) |
PIO_OUT cycles 01, 11, 10 |
Two things to know: a STROBE edge is only seen by the instruction that is executing in that clock (so PULL / auto-pull SHIFT must already be waiting),
and the first DELAY after reset or programming takes one clock because X starts at 0.
| Pin | Function | Pin | Function |
|---|---|---|---|
ui[0] |
PROG_MODE | uo[0] |
PIO_OUT[0] (MOSI) |
ui[1] |
STROBE | uo[1] |
PIO_OUT[1] (SIDE / SCK) |
ui[2] |
PIO_IN[0] / INST[0] | uo[2] |
SR_DONE |
ui[3] |
PIO_IN[1] / INST[1] | uo[3] |
STALLED |
ui[4] |
DATA_IN[0] / INST[2] | uo[4] |
SR[0] |
ui[5] |
DATA_IN[1] / INST[3] | uo[5] |
SR[1] |
ui[6] |
DATA_IN[2] / INST[4] | uo[6] |
SR[2] |
ui[7] |
DATA_IN[3] / INST[5] | uo[7] |
SR[3] |
STALLED, SR_DONE and PIO_OUT react to ui_in combinationally (for example WAIT ends the moment the
pin changes), the instruction itself executes on the next rising clock edge. The inputs are not
synchronised: drive them from the same clock domain, or add a synchroniser outside the chip.
rst_n low for a few clocks with PROG_MODE = 1, then release it.0x14, 0x1E, 0x20: set ui[7:2] to the value and ui[0] = 1, raise ui[1], lower ui[1].ui[0] = 0, put 0xA on ui[7:4], raise STROBE for one clock. Watch uo[1:0]: SCK pulses four times
and MOSI shows 1 0 1 0 while SCK is high. Present MISO bits 1 1 0 0 on ui[2] just before each SHIFT
(clocks 0, 3, 6, 9 after the STROBE edge) and uo[7:4] ends as 0xC.SET_PIN 0b001, SET_PIN 0b110, SET_PIN 0b010 makes uo[1:0] cycle 01, 11, 10;
SET_X 2, SHIFT, JMP x-- runs the SHIFT three times per pass (SR fills 0001, 0011, 0111, 1111 with PIO_IN[0] = 1).The cocotb tests in test/ run all of these and compare a Python model of the chip with the RTL (and the
gate-level netlist) on every clock for random programs: cd test && make -B.
None needed to try it: switches or a microcontroller on the inputs, LEDs or a logic analyser on the outputs.
For SPI, connect PIO_OUT[0] = MOSI, PIO_OUT[1] = SCK and PIO_IN[0] = MISO to the target device (use
an external chip-select, for example a spare GPIO of the controlling microcontroller).
| # | Input | Output | Bidirectional |
|---|---|---|---|
| 0 | PROG_MODE | PIO_OUT[0] (MOSI) | |
| 1 | STROBE / TX_VALID | PIO_OUT[1] (SIDE / SCK) | |
| 2 | PIO_IN[0] / INST[0] | SR_DONE | |
| 3 | PIO_IN[1] / INST[1] | STALLED | |
| 4 | DATA_IN[0] / INST[2] | SR[0] | |
| 5 | DATA_IN[1] / INST[3] | SR[1] | |
| 6 | DATA_IN[2] / INST[4] | SR[2] | |
| 7 | DATA_IN[3] / INST[5] | SR[3] |