finite-state machine (State Machine): Each PIO contains 4 independent finite-state machines, which are the core execution hardware of the PIO and can be regarded as a lightweight dedicated processor, with the following internal components:
PC (Program Counter): Records the address of the instruction to be executed currently in the instruction memory, and controls the sequential execution of instructions;
Clock Div (Clock Divider): Independently adjusts the operating clock frequency of the finite-state machine to adapt to external I/O protocols of different rates;
X/Y Erasable Data Register: Temporarily stores operation data and intermediate results;
Out Shift (Output Shift Register): Shifts data according to the specified bit width and sequence, then outputs it to GPIO;
In Shift (Input Shift Register): Reads data from GPIO and performs shift buffering according to specified rules;
The finite-state machine reads assembly instructions in the instruction memory via internal registers, and autonomously completes operations such as data read/write and GPIO control; meanwhile, it can access modules including FIFO, DMA and GPIO, and generate interrupt signals for synchronization between finite-state machines as well as between PIO and the main CPU.
Instruction Memory: it is a read-only memory unit with a capacity of 32 instructions, shared by 4 finite-state machines within the same PIO. The PIO-specific assembly instructions written by users will be loaded into this memory for each finite-state machine to read and execute independently.
GPIO Mapping:
The input/output signals of the finite-state machine can be mapped to the GPIO pins of the RP2040 (the hardware supports up to 32 GPIOs, while the RP2040 actually leads out 30 available GPIOs);
All finite-state machines within the same PIO can independently and simultaneously access any GPIO pin, featuring flexible pin allocation capabilities.
FIFO Memory: The Out Shift and In Shift shift registers of each finite-state machine are respectively connected to a set of "Transmit FIFO (Tx FIFO)" and "Receive FIFO (Rx FIFO)", whose core function is to realize the asynchronous decoupling between "data transmission and reception requests" and "actual execution operations":
Transmission Scenario: The main CPU first writes the data to be output to the Tx FIFO; when the finite-state machine is ready, it fetches data from the Tx FIFO and outputs it to the GPIO via the Out Shift register.
Reception Scenario: The finite-state machine temporarily stores the data read from the GPIO into the In Shift register, then writes it to the Rx FIFO; the main CPU can fetch the data from the Rx FIFO at an appropriate time.
Interrupt and Interrupt Mask Registers: Used to manage the interrupt signals of PIO:
Interrupt sources: including raw interrupt signals from FIFOs (e. g., FIFO full/empty) and finite-state machines (e. g., instruction execution completion, specific operation trigger);
Interrupt Mask Register: It configures the original interrupt signals to be either "enabled or masked", and only unmasked interrupts are sent to the RP2040 interrupt controller to trigger the response of the main CPU.