🛠 Exploiter les 3 blocs PIO et 12 machines d'état du RP2350 (avec IRQ dédiées)

RP2350 (generic / RP2350-based boards) · intermediaire · Schéma : IMG-rp2350-generic-intermediaire-1-rp2350-pio-3-blocs-irq.svg — puce RP2350 avec les 3 blocs PIO (PIO0/1/2) et leurs 4 machines d'état chacun, signal WS2812 sur PIO0 et compteur sur PIO1, IRQ par bloc reliant PIO et cœurs, LED GP25 animée par la PIO

Objectives

The DNA of RP2 chips: PIO (Programmable I/O). The RP2350 doubles down compared to the RP2040: 3 PIO blocks instead of 2, 12 state machines (4 per block) instead of 8, and above all 2 dedicated IRQs per block (PIO0/1/2_IRQ_0/1) whereas the RP2040 shared a single pair (RP2350 datasheet, §3.2 interrupt table). You will run an autonomous PIO while the CPU does something else, then understand why 12 SMs open up architectures that the RP2040 did not allow.

Hardware

Complete code

# pio_double.py — une PIO autonome + PWM matériel en parallèle
import rp2, time
from machine import Pin, PWM

# --- PIO0/SM0 : clignotement ~1 Hz, 100 % autonome (CPU libre) ---
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def blink_1hz:
    set(pins, 1)
    set(x, 31) [6]
    label('high')
    nop [29]
    jmp(x_dec, 'high')
    set(pins, 0)
    set(x, 31) [6]
    label('low')
    nop [29]
    jmp(x_dec, 'low')

sm = rp2.StateMachine(0, blink_1hz, freq=2000, set_base=Pin(25))
sm.active(1)

# Plan des 12 SM sur RP2350 : indices 0..3 -> PIO0,
# 4..7 -> PIO1, 8..11 -> PIO2. Sur RP2040, l'indice 8 lève une erreur ;
# ici sm2 = rp2.StateMachine(9, ...) est légal.

# --- PWM matériel en parallèle : 50 Hz « servo » sur GP2 ---
# (PWM du RP2350 : 8 tranches/16 canaux sur RP2350A,
#  12 tranches/24 canaux sur RP2350B — une tranche par fréquence servo)
servo = PWM(Pin(2), freq=50, duty_u16=int(65535 * 1.5 / 20))

n = 0
while True:
    n += 1            # le CPU ne fait QUE tourner ici : la PIO pilote la LED
    time.sleep_ms(500)

Expected verification

The GP25 LED blinks at ~1 Hz while the Python loop runs at 500 ms: the PIO executes its own program, without any CPU instruction. The machine's freq=2000, divided by the ~2 × 32 × 30 cycles of the double counter, yields approximately 1 Hz. Then push the counter further: reuse indices 4..11 with different programs — all 12 slots must activate, proving the existence of the 3 blocks.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials