MAVILERA Pico 2 Laboratory

The Pico 2 Laboratory

A Raspberry Pi Pico 2 in the browser: write a program in RISC-V assembly or in a subset of C, run it on a simulated RP2350 with its Hazard3 cores, and watch the instructions, the clock cycles and the pins.

About the laboratory

The Raspberry Pi Pico 2 is a small board built around the RP2350, a microcontroller from Raspberry Pi Ltd. The RP2350 has two processor cores, and each can run either as an Arm Cortex-M33 or as a Hazard3, an open-source RISC-V core; the choice is made at boot (RP2350 Datasheet §3.8, §3.9). The laboratory simulates the RISC-V side: two Hazard3 cores, the RP2350's address map (§2.2) and the devices listed under The chip's devices.

It is a teaching tool. A program runs one instruction at a time or at the speed of the real chip; every instruction takes the clock cycles the datasheet gives for Hazard3, and the Core view shows why. Programs are written in Hazard3 assembly language or in MAVILERA C, a teaching subset of C compiled in the page. What the model leaves out is listed under Limits of the model, and how it was checked under How the models were checked.

Getting started

  1. Open a sample project from Sample projects in the toolbar, for example Hello over UART. Its first lines say what it shows and what to try.
  2. Choose Assemble (Compile for C), or press Ctrl+Enter. Errors are underlined in the editor and listed in the console.
  3. Step (F10) runs one instruction; Step back (Shift+F10) undoes it. Run (F5) runs on and pauses.
  4. Open the Pins tab of the bottom pane to see GP25, the board's LED, and the other 29 GPIOs.

A path through the templates: A tour of Hazard3's extensions; Hello over UART and Blink GP25 with the SIO and TIMER0; Blink in C and Hello in C; A button on GP15 counts presses and Echo over UART in capitals; then the pipeline, sound, two cores, the buses and PIO. The practice exercises follow the same order.

The workspace

PartWhat it shows
EditorThe program, with a second tab for its .pio file when it has one.
ListingEach instruction with its address and encoding; the marked row runs next. Click the circle before an address to set a breakpoint.
Registersx0 to x31 and the machine CSRs; a register the last step changed is marked. Tick a register to stop when it is written. With two cores running, the Core 1 registers too.
Bottom paneTabs: Memory, Pins, and one per device (PWM, DMA, ADC, SPI, I2C, PIO).
ConsoleWhat the program sends on UART0, messages of the laboratory, and Send to UART0.
ToolbarSample projects, Assemble or Compile, Run, Step, Step back, Reset, the Speed menu, the Sound button and clk_sys.

Panes can be resized, folded and opened from their dividers; View in the header has Focus, Full screen, Zoom, Projector mode and the theme. Keys in the header lists the keyboard shortcuts.

Assembly language

The assembler takes Hazard3's instruction set: RV32IMAC with the bit-manipulation and code-size extensions, and Hazard3's own extensions, among them its interrupt controller (RP2350 Datasheet §3.8, §3.8.6). A program begins at its first instruction in .text; its data go in .data; it ends at ebreak when no trap handler is set. Without a bootrom (see Limits) the program itself starts the chip: it starts the 12 MHz crystal, chooses the clocks and takes the devices it uses out of reset, as the device templates do.

clk_sys in the toolbar chooses 1, 4 or 12 MHz. The assembler defines symbols for that choice, so that a program works at every clock:

SymbolMeaning
CLK_SYS_DIVThe value for CLK_SYS_DIV that divides the 12 MHz reference to clk_sys (§8.1).
CLK_SYS_HZclk_sys in hertz.
UART_IBRD, UART_FBRDThe UART's baud-rate divisors for this clock (§12.1).
TICK_CYCLESThe tick generator's count for a 1 µs timer tick (§8.5).

A .pio file in the second tab (File, then Add PIO file) is assembled with the program; a PIO program named blink gives the symbols blink_program (its words), blink_length, blink_wrap and blink_wrap_target.

MAVILERA C

MAVILERA C is the teaching subset of C of the MAVILERA laboratories, compiled in the page into Hazard3 assembly that you can read and step through. Its start-up starts the crystal, sets clk_sys to the chosen clock, starts UART0 for putchar and the timer, then calls main; main's return value is the program's exit code (in a0 at the end). Step line and Back line run one C line.

#include <rp2350.h> gives the registers by name and these helpers:

HelpersWhat they do
pin_output, pin_input, pin_write, pin_readA GPIO as a single-cycle IO output or input.
delay_us, delay_ms, sleep_ms, time_usWaiting and time from TIMER0 (sleep_ms waits asleep, for programs without interrupt handlers).
pwm_start(pin, top, div), pwm_level(pin, level)A pin's PWM slice: a period of top + 1 counts of clk_sys / div, high for level counts.
dma_copy(dst, src, words)A copy by DMA channel 0, waiting until it is done.
adc_read(input)A conversion of input 0 to 3 (GP26 to GP29) or 4 (the temperature sensor): 0 to 4095.
i2c_setup, i2c_write, i2c_readI2C0 on GP4 (SDA) and GP5 (SCL), the lab kit's bus.
spi_setup, spi_select, spi_transferSPI0 on GP16 to GP19, chip select on GP17.
core1_start, fifo_push, fifo_pop, core_idCore 1 runs the program's core1_main; words pass through the inter-core FIFOs.
pio_load(words, n)PIO0's instruction memory filled from address 0.
CLK_SYS_HZ, UART_BAUDThe chosen clock and UART0's baud rate.

MAVILERA C has no interrupt handlers; the interrupt templates are in assembly.

The chip's devices

Each device is modelled at the level of its registers, at the RP2350's addresses, and takes its time in clock cycles of its own clock. The tabs of the bottom pane show each one's state in words.

DeviceDatasheetIn the laboratory
Clocks, crystal, PLLs, resetschapter 8, §7.4The 12 MHz crystal, the clock generators and their dividers, the resets of each block; clk_sys from 1 to 150 MHz.
GPIO and padschapter 930 pins, each with its function, pad settings and level; the Pins panel drives a pin from outside.
Single-cycle IO (SIO)§3.1GPIO registers, the inter-core FIFOs, doorbells, each core's identity and timer compare.
Interrupts§3.8.6Hazard3's external interrupt controller (Xh3irq) and the devices' interrupt lines.
Timers§12.8, §8.5TIMER0 and TIMER1 with a 1 µs tick, their alarms and interrupts.
UART§12.1UART0 and UART1: FIFOs, baud rate, interrupts; UART0 is the console.
PWM§12.512 slices: divider, wrap, phase-correct mode, input modes, interrupts and DMA requests.
DMA§12.616 channels: chaining, address rings, pacing timers, the sniffer.
ADC§12.4One-shot and free-running conversion, round robin, the FIFO, the temperature sensor; ideal converter.
SPI§12.3SPI0 and SPI1 as masters, with loopback.
I2C§12.2I2C0 and I2C1 as masters: start, repeated start, aborts.
PIOchapter 11See PIO.

A program that uses a block or a feature that is not modelled gets a message in the console; the list is under Limits of the model.

The lab kit and analogue inputs

Parts, in the Pins panel, connects a kit of simulated parts to the Pico 2's default buses, as on a breadboard:

PartBus and addressGives
BMP280I2C0, 0x76temperature and pressure
MPU-6050I2C0, 0x68acceleration, rotation, temperature
MCP9808I2C0, 0x18temperature
16 x 2 character displayI2C0, 0x27two lines of text
24C02 EEPROMI2C0, 0x50256 bytes
BME280SPI0, chip select GP17temperature, pressure, humidity

The panel sets the environment the sensors read and the voltages on GP26 to GP29, the ADC's inputs (§12.4); the temperature is also the chip's own, read by its temperature sensor. Every change is an input of the run, given at the clock cycle you make it. The parts answer their buses byte by byte; their measuring times, filters, interrupt pins and the EEPROM's write time are not modelled.

The Core view

Hazard3 has three pipeline stages: F (fetch), X (execute) and M (memory). The view shows them cycle by cycle: which instruction is in each stage, the drawing of the stages, the cycles each instruction cost and the cause of every extra cycle (a load whose result is used at once, a taken branch, a divide, a multi-cycle push or pop), and the branch predictor's single entry. The counts are the datasheet's (RP2350 Datasheet §3.8.7). Where Hazard3's hardware design files take a different count (divide and remainder, mret, cm.popretz with one register), the laboratory keeps the datasheet's and says so in the view's help. The bus is perfect: every access completes without wait states.

PIO

The RP2350 has three PIO blocks of four state machines each (RP2350 Datasheet chapter 11). A state machine runs a program of up to 32 instructions that drives and reads pins with exact timing, with its own clock divider, FIFOs to and from the cores, and side-set. In the laboratory a PIO program is written in a .pio file in the Pico SDK's notation; programs that use the RP2350's additions start with .pio_version 1. The PIO tab shows each state machine's program counter, scratch registers, shift registers, FIFOs and divider.

All three blocks run exact to the clock cycle, with the RP2350's additions. Simulating a state machine that executes an instruction on every cycle of a fast clock is slow (at 150 MHz about 1 to 2 % of real time); one that waits on its divider, a FIFO or a pin runs close to real time.

Sound

Choose a pin as the Speaker in the Pins panel and turn Sound on (the speaker button in the toolbar): you hear that pin's level as a small loudspeaker on it would play it. The Converter is Pin-accurate by default (the pin's exact high and low times, filtered to 20 kHz); Ideal DAC plays a PWM output's duty cycle at each period, without its carrier. Sound plays in Real time; Render and play, in the Speed menu, runs up to 60 seconds of the chip's time as fast as it can and then plays them, for programs too fast for real time.

Two cores

After reset core 1 waits in the bootrom for core 0 to send it a short sequence of words through the inter-core FIFO (RP2350 Datasheet §5.3, §3.1). The laboratory models that wait without running the bootrom. In C, core1_start() sends the sequence and core 1 runs core1_main on a stack of its own. Both cores then run at once, interleaved by their clock cycles; Step steps core 0 while core 1 runs alongside, and the Core 1 registers show the other core.

Real time, speed and replay

SpeedWhat it does
Real time (the default)One second of the chip's time per second, so that blinks, tones and UART lines come as on the board. If this computer cannot keep up, the status says how much of real time it reaches.
Full speedAs fast as this computer can.
AnimatedOne step after another, slowly enough to follow.

A pin you drive, a line you send to UART0 and a change of the lab kit are the run's inputs, each given at a clock cycle. Replay in the Pins panel starts the program again and gives the same inputs at the same cycles: the run repeats exactly. A share link and a settings file carry the inputs with the program.

Circuits on the Board

The Board view draws the circuit around the board: at first the demo circuit (a push button on GP15, a knob on GP26 with its 3.3 V and ground), the board's own LED on GP25, and, when chosen in the Pins panel, the lab kit's modules and a speaker. All of them except the board's LED are parts you can move, re-wire, change or delete, and add to. The circuit is simulated with the program: each pin's voltage is solved from the parts on its net whenever something changes, at that clock cycle, and the chip reads its input from that voltage. Capacitors charge and discharge exactly to the cycle.

Editing. Turn on Edit circuit in the Board's heading (the program cannot run while it is on). Choose a part from the tray (its picture is its symbol; its name is in the tooltip) and click the sheet, or press A. Click a pin to start a wire and click again to bend it; end it on a pin, a pad, a junction or another wire. The tools above the tray select and move, draw wires, delete parts or wires, pan, turn, mirror, undo and redo. Everything can be done from the keyboard: arrow keys move a cursor on the grid, Enter selects, W starts a wire, F2 changes a value in Inspect, and ? lists every key. The Circuit tab lists the same circuit as a table with a menu for each pin's connection; there a part of your own can also be defined from the simple parts (Define a part).

Where the values come from. 5 mm LEDs: Kingbright WP7113 series (red ID, yellow YD, green GD, blue QBC/D, white QWC/D); diodes: Vishay 1N4148 and the 1N5819 Schottky diode; transistor: onsemi BC547B; light sensor: Advanced Photonix PDV-P8001; thermistor: Vishay NTCLE100E3103 (10 kΩ, B 3977 K); 7-segment display: Kingbright SC56-11SRWA and SA56-11SRWA; RGB LED: Kingbright WP154A4SUREQBFZGW. An LED's knee voltage and resistance are read from two points of its datasheet's curve (2 mA and 10 mA, the currents a pin gives). Chosen where no datasheet gives them: a switch's 0.05 Ω, the light sensor's resistance at 10 lux (5.74 kΩ, the middle of the datasheet's 3-11 kΩ) and its 1 MΩ in the dark, the resistances of the 7-segment and the RGB LED's red. The board's own LED keeps generic values, since the board's documentation does not name its part.

Light and temperature for the light sensor and the thermistor are the Pins panel's Environment values (Light in lux, Temperature in °C), inputs of the run that Replay repeats.

Sample projects

Sample projects, in the toolbar, are grouped by topic. Each begins with what it shows and what to try. Pico Lite lists the samples in assembly and MAVILERA C; Pico Full lists those in assembly and in Pico SDK C, which also run on a real Pico 2 (the Hardware tab). The laboratory's tests run every one of them and check what its comment says.

GroupSample projectLanguage
Getting startedHello in CMAVILERA C
Getting startedBlink in CMAVILERA C
Getting startedBlink GP25 with the SIO and TIMER0Assembly
Getting startedHello with printf (Pico SDK)Pico SDK C (Full)
Getting startedBlink the LED (Pico SDK)Pico SDK C (Full)
A complete projectSOS in Morse code, with meters on the LCD and a button (Pico SDK)Pico SDK C (Full)
Digital input and outputA button on GP15 counts pressesMAVILERA C
Digital input and outputAn LED and its resistorMAVILERA C + circuit
Digital input and outputA traffic lightMAVILERA C + circuit
Digital input and outputA transistor switches an LEDMAVILERA C + circuit
Digital input and outputA bouncing button and a capacitorMAVILERA C + circuit
Digital input and outputA button by interrupt (Pico SDK)Pico SDK C (Full)
Timers and interruptsMeasuring time with time_usMAVILERA C
Timers and interruptsA timer alarm interrupt (Xh3irq)Assembly
Timers and interruptsA repeating timer (Pico SDK)Pico SDK C (Full)
Serial: UARTHello over UARTAssembly
Serial: UARTEcho over UART in capitalsAssembly
Serial: UARTEcho in capitals (Pico SDK)Pico SDK C (Full)
Analogue input: ADCRead a knob with the ADCMAVILERA C
Analogue input: ADCThe chip's temperature sensorMAVILERA C
Analogue input: ADCA voltage divider into the ADCMAVILERA C + circuit
Analogue input: ADCA night light with a light sensorMAVILERA C + circuit
Analogue input: ADCA thermometer with a thermistorMAVILERA C + circuit
Analogue input: ADCRead a knob with the ADC (Pico SDK)Pico SDK C (Full)
Analogue input: ADCThe chip's temperature sensor (Pico SDK)Pico SDK C (Full)
PWM and soundFade the LED with PWMAssembly
PWM and soundA voltage from PWM and an RC filterMAVILERA C + circuit
PWM and soundA tone from PWMMAVILERA C
PWM and soundTwinkle, Twinkle, Little Star (in a loop)MAVILERA C
PWM and soundFade the LED with PWM (Pico SDK)Pico SDK C (Full)
PWM and soundA tone from PWM (Pico SDK)Pico SDK C (Full)
I2CAn I2C temperature sensor (MCP9808)MAVILERA C
I2CText on an I2C LCDMAVILERA C
I2CAn I2C temperature sensor (Pico SDK)Pico SDK C (Full)
I2CText on an I2C LCD (Pico SDK)Pico SDK C (Full)
SPISPI in loopbackAssembly
SPISPI in loopback (Pico SDK)Pico SDK C (Full)
DMACopy memory with DMAAssembly
DMAA sine from DMA and PWMMAVILERA C
DMACopy memory with DMA (Pico SDK)Pico SDK C (Full)
PIOPIO blinks the LEDAssembly + .pio
PIOA square wave from PIO with side-setAssembly + .pio
PIOPIO counts the 1 bits of a wordMAVILERA C + .pio
PIOPIO drives the LED (Pico SDK)Pico SDK C (Full) + .pio
Two coresTwo cores, two LEDsMAVILERA C
Two coresA message through the FIFOAssembly
Two coresTwo cores share the work (Pico SDK)Pico SDK C (Full)
Inside Hazard3A tour of Hazard3's extensionsAssembly
Inside Hazard3Sum of an arrayMAVILERA C
Inside Hazard3Load-use stalls and branch costsAssembly
Inside Hazard3A function with cm.push and cm.popretAssembly

Exercises

File, then Exercise…, lists the practice exercises. Each gives a task and a starter program; Run the tests runs your program once per test, from reset at full speed, with the test's inputs (a pin driven at a given time, text sent to UART0) given when the chip's clock reaches them, and shows expected against actual: memory, registers, the exit code, the console, pin levels, and the number, period and high time of a pin's changes within a stated tolerance. No solutions are included. An exercise file from a teacher (format risc-vista-exercise, with "arch": "pico2") opens the same way.

ExerciseLanguageTests
The sum of a table of wordsAssembly6
Count the 1 bits of a word, fastAssembly7
Print a number over UARTMAVILERA C7
Blink with a given rhythmMAVILERA C1
Count the presses of a buttonMAVILERA C5
A PWM wave with a given dutyMAVILERA C1
A sum on core 1MAVILERA C4
Pulses from PIOAssembly + .pio1

Files and sharing

Lite and Full

The stable laboratory holds one program in assembly language or in MAVILERA C (Pico Lite). A second edition, Pico Full, has projects of several files, C written for the Raspberry Pi Pico SDK and built in the browser by the SDK's own compiler (a download of about 25 MB, asked for at the first build and then kept), the import of SDK-built UF2 and ELF files, and loading onto a real Pico 2. Pico Full is offered in the beta release (MAVILERA 1.7.0-beta.2, at sajidlab.org/mavilera/beta/) and is not yet part of the stable release. Where it is offered, the switch beside the laboratory's name changes the edition; each edition keeps its own program.

A real Pico 2: the Hardware tab (beta)

Status, MAVILERA 1.7.0-beta.2: loading onto a board has been tested with simulated USB devices only, not yet with a real Pico 2. If a load fails, Download .uf2 and copying the file to the RP2350 drive always works. Please report what happened on GitHub.

In Pico Full the Hardware tab at the top holds everything about a real board, apart from the simulator (which keeps running). It needs Chrome or Edge on a computer (WebUSB); the UART monitor also works in Firefox 151 or later (Web Serial). Each card has a ? button with its explanation.

CardWhat it does
BoardProbe board reads what a Pico 2 in BOOTSEL mode reports: chip, ROM version, USB serial number, boot partition. The line under it says which build this browser last wrote to the board.
ProgramLoad to Pico (also in the toolbar) builds the project if it changed, asks you to confirm the board and the build, then erases, writes and reads back each sector and restarts the board. Steps and a progress bar show how far it is. Check reads the board back and compares; Download .uf2 and Copy to the Pico's drive give the file.
Debug (without a probe)Run restarts a board in BOOTSEL mode so that it runs its flash; Save flash reads the flash into a .bin file. Neither writes. Stepping and breakpoints on the board itself need a Raspberry Pi Debug Probe: planned.
UART monitorThe board's serial output over its USB cable (Pico 2 USB…) or a 3.3 V USB-UART adapter on GP0, GP1 and GND (Port…), 115200 bit/s by default; Send, Time, Hex, Read aloud; Compare checks the board's lines against the simulated console's.
  1. Hold BOOTSEL on the Pico 2 while you plug its USB cable in, then let go: a drive named RP2350 appears.
  2. Press Load to Pico and choose RP2350 Boot in the browser's list.
  3. Check the question (it names the board's serial number and the build) and press Enter.
  4. After the restart, connect the UART monitor to see the program's output.

A load that stops leaves the board in BOOTSEL mode: the part that marks the program as runnable is written last. The laboratory never changes the board's one-time-programmable memory or a partition table. On Linux the browser needs a udev rule for the USB IDs 2e8a:000f and 2e8a:0009.

Offline use and privacy

Every computation runs in your browser. MAVILERA has no account, sends no telemetry and uploads nothing. After a first visit the hosted version also opens without a network connection, and a single-file version can be downloaded for computers that have none.

How the models were checked

Against other simulators, test suites and Hazard3's hardware design files, not against a Pico 2 board:

WhatChecked againstResult
The core's instructionsriscv-arch-test, the RISC-V architecture tests, with the Sail reference model245 of 255 tests pass; the failures were examined: each is a point where Hazard3's own design differs from the reference model, except one that is not yet explained.
Instruction timing135 timing cases measured on Hazard3's hardware design (the RP2350 version), simulated with Verilator and with Icarus VerilogThe laboratory gives the hardware design's count in every case, except 18 where the design and the datasheet differ: there it gives the datasheet's (see The Core view).
The machine and its devicesThe Pico SDK's example programs built for RISC-V and run on rp2350js (an open-source RP2350 emulator, patched where it lacked features)Identical UART text and pin sequences, and pin timing within 1 % or 2 µs: 4 of 4 programs on the timers, UART and GPIO; 4 of 6 on PWM and DMA, 3 of 4 on two cores and 9 of 10 on ADC, SPI and I2C, each difference traced to a feature the emulator lacks; 13 of 13 PIO programs.
PIO, a second timerp2040-pio-emulator, an independent PIO emulator, on PIO-only tests21 of 22 tests identical cycle by cycle; the one difference is a feature that emulator lacks (refilling the output register between OUT instructions, RP2350 Datasheet §11.5.4.2).
The PIO assemblerpioasm, the Pico SDK's assembler, on 38 programsThe same words for every program.
Real timeA program at 1 MHz for 30 seconds in Chrome, Edge and Firefox on a 2021 laptop processor (AMD Ryzen 9 5900HS)Within 0.1 % of real time. At 12 MHz the same laptop reached 55 to 78 %. Slower computers were not measured.

The laboratory's own tests run every template and every exercise, and its browser tests run in Chrome, Edge and Firefox. Safari was not tested.

Limits of the model

Not modelled

Modelled with simplifications

The circuit outside the chip

Speed and browsers

What a simulation shows

The models were checked against emulators, test suites and the core's hardware design, not against a Pico 2 board. A simulation shows what the model does; it is not evidence of how a hardware build behaves.

Sources

Section numbers in this documentation and in the help are those of RP2350 Datasheet, Raspberry Pi Ltd, Release 8 (build 80d627281ed5), 1 October 2026, pip.raspberrypi.com/documents/RP-008373-DS, licensed CC BY-ND 4.0.

Licence and notices

© 2026 Sajid Muhaimin Choudhury. MAVILERA and its content (drawings, help texts, this documentation, templates and exercises) are licensed under the Apache License, Version 2.0. The names and the logo are not licensed as trademarks.

The table of the RP2350's register names, addresses and reset values is generated from the RP2350 description file of the Raspberry Pi Pico SDK (BSD-3-Clause licence; see THIRD_PARTY.md in the source repository). MAVILERA reproduces no text, figure or table of the RP2350 Datasheet; its simulator, drawings, help and programs are its own. rp2350js, rp2040-pio-emulator, riscv-arch-test, Verilator and Icarus Verilog were used for checking only; nothing of them is included. MAVILERA is not affiliated with or endorsed by Raspberry Pi Ltd. Raspberry Pi is a trademark of Raspberry Pi Ltd; Pico and RP2350 are names of its products.