DEV Community

Cover image for BIOScope
Harish Kotra (he/him)
Harish Kotra (he/him)

Posted on AI-assisted

BIOScope

A BIO-powered 4-channel logic analyzer for the Dabao (Baochip-1x) with an EchoKit DIY (ESP32-S3) visual and audio front-end.

  Dabao / Baochip-1x                              EchoKit DIY
 ┌──────────────────────────────────┐            ┌──────────────────────────┐
 │  BIO Core0  stim (loopback)      │            │  ST7789 240×240          │
 │    x21 level writes, wins GPIO   │  USB CDC   │  4 live digital traces   │
 │  BIO Core1  4-ch sampler         │───────────►│  red TRIGGER banner      │
 │    quantum-timed, FIFO0 (8 deep) │  B1OS      │  MAX98357 1 kHz chirp    │
 │  VexRiscv + Xous  `scope` cmd    │            │  new firmware (not AI)   │
 └──────────────────────────────────┘            └──────────────────────────┘
                       │
                       ▼
              host/scope.py  (ASCII scope + USB-JTAG bridge)
Enter fullscreen mode Exit fullscreen mode

Two PicoRV32 BIO cores share the same pads through the I/O matrix. Core 0 generates the test signal (or you feed an external 3.3 V CMOS source). Core 1 samples four channels once per hardware quantum and pushes packed levels into FIFO0. The VexRiscv host under Xous drains the FIFO and emits framed bursts. EchoKit draws the traces and chirps on trigger.

The default demo needs no jumper wires: scope loopback 4000 drives and samples the same BIO bits on-chip.

Why BIO

A normal MCU GPIO ISR at 160–240 MHz cannot do this the same way.

  • Four PicoRV32 (RV32E) cores clocked with the SoC (~700 MHz aclk). The sample loop is a handful of instructions gated by a hardware quantum (mv x20, x0), not a timer IRQ.
  • GPIO writes from four cores collide by priority: lower core number wins. Stim lives on Core 0 so it owns the pads. The sampler on Core 1 never writes x24/x25.
  • The 8-deep FIFO halts the core when full. USB backpressure stretches the gap between bursts. Edges inside a burst stay cycle-accurate.
  • ClockMode::TargetFreqInt retimes both cores together when you run scope rate.
  • IoxFunction::AF1 muxes pads onto the BIO GPIO block. A GPIO AF would steal the pin back from BIO.

That is the silicon this project is meant to show.

Architecture

flowchart LR
  subgraph Dabao["Dabao / Baochip-1x"]
    Stim["BIO Core0<br/>stim kernel<br/>x26 mask, x24 OE, x21 levels"]
    Pads["PB1 PB2 PB3 PB11<br/>mask 0x80E"]
    Samp["BIO Core1<br/>sampler kernel<br/>snap_inputs"]
    FIFO["FIFO0 · 8 deep<br/>halt-on-full"]
    Xous["VexRiscv + Xous<br/>scope command"]
    Stim --> Pads
    Pads --> Samp
    Samp -->|"packed nibble + trig bit 16"| FIFO
    FIFO --> Xous
  end

  subgraph Host["Host"]
    Py["host/scope.py<br/>parse B1OS · ASCII traces<br/>non-blocking USB-JTAG writer"]
  end

  subgraph Kit["EchoKit DIY · ESP32-S3"]
    USB["USB serial-JTAG stdin"]
    UART["UART1 RX GPIO17"]
    LCD["ST7789 240×240"]
    Spk["I2S1 MAX98357A<br/>BCLK 15 · WS 16 · DIN 7"]
    USB --> LCD
    USB --> Spk
    UART --> LCD
  end

  Xous -->|"USB CDC ASCII<br/>B1OS + hex + LF"| Py
  Py -->|"B1OS-only bridge"| USB
  Xous -.->|"optional PB14 TX"| UART

Data path

  1. scope loopback 4000 (or scope capture 4000) claims BIO Core0+Core1 and FIFO0.
  2. Stim writes gpio_out = (x26 & x21) every quantum. Periods: CH0×2, CH1×4, CH2×8, CH3×16 quanta.
  3. Sampler waits one quantum, reads x21, packs CH0–CH3 into a nibble, ORs bit 16 on the first sample, pushes x16 (FIFO0).
  4. Xous drains FIFO0, emits TYPE_HEADER, one TYPE_TRIGGER, then TYPE_SAMPLES bursts of up to 32 bytes.
  5. USB CDC lines look like B1OS05B1... plus a newline.
  6. host/scope.py parses them, draws ASCII traces, and optionally forwards B1OS lines to EchoKit.
  7. EchoKit paints four rolling traces, a red banner for ~800 ms, and an 80 ms 1 kHz I2S chirp.

Technologies

Layer Stack
Capture SoC Baochip-1x, BIO (4× PicoRV32 RV32E @ ~700 MHz), VexRiscv
Capture OS Xous rev 4e9a9909, out-of-tree app forked from dabao-console
Capture language Rust (riscv32imac-unknown-xous-elf), BIO kernels via bio_code!
Front-end MCU ESP32-S3, ESP-IDF 5.x via esp-idf-svc 0.51
Front-end UI embedded-graphics + ST7789 (SPI mode 3, invert), MAX98357A I2S
Host Python 3, pyserial, termios non-blocking writes
Protocol Little-endian frames, magic 0xB105, ASCII B1OS hex on USB
Sim path C kernels in bio/ for bio-sim
Flash Serial UF2 into boot1 RRAM (scripts/flash_uf2_serial.py)

Repo layout

Path What
dabao/ Out-of-tree Xous app + BIO kernels (src/engine.rs, src/cmds/scope.rs)
echokit/ ESP32-S3 firmware: ST7789 traces + I2S trigger chirp
bio/ Same kernels in C for bio-sim
host/scope.py USB CDC viewer, ASCII traces, EchoKit bridge
host/test_protocol.py Frame encode/decode self-test (no hardware)
protocol.md B1OS wire format
docs/wiring.md Pins, UART option, EchoKit display / speaker
scripts/ Serial UF2 flasher, boot1/Xous console, demo cheat-sheet
firmware/ Matching loader.uf2, xous.uf2, apps.uf2
third_party/dabao-hw/ KiCad + pinout reference for header mapping

Hardware

Board USB role Example macOS port
Dabao in boot1 Baochip-1x, PID 0x6196 /dev/cu.usbmodemV6VJDB1 (CR line endings)
Dabao in Xous Dabao, PID 0x6197 /dev/cu.usbmodemV6VJDB3 (LF line endings)
EchoKit DIY Espressif USB serial-JTAG /dev/cu.usbmodem101

Re-check with python3 host/scope.py --list.

Capture pins (mask 0x80E):

Channel BIO bit Pad Header (dabao v3c) Loopback period
CH0 1 PB1 29 2 quanta
CH1 2 PB2 31 4 quanta
CH2 3 PB3 32 8 quanta
CH3 11 PB11 27 16 quanta

Full pin / speaker table: docs/wiring.md.

Quick demo

Both boards USB-plugged, Dabao already in Xous with this app, EchoKit running bioscope-echokit. Do not hold PROG.

python3 host/test_protocol.py
python3 host/scope.py --list
python3 host/scope.py --bridge --cmd "scope loopback 4000" --duration 8
Enter fullscreen mode Exit fullscreen mode

You should see:

  • Header: 4ch, mask 0x80E, rate ~10.7 kHz, bio_hz=700000000
  • A TRIGGER line, then ~25k packed samples
  • Unique sample bytes 0..15, ~50% duty on every channel
  • EchoKit: four rolling traces, red TRIGGER banner, one short beep

ASCII-only (no EchoKit):

python3 host/scope.py --cmd "scope loopback 4000"
Enter fullscreen mode Exit fullscreen mode

Cheat-sheet: ./scripts/demo.sh

External capture (3.3 V CMOS into those pads, shared GND):

scope capture 4000
Enter fullscreen mode Exit fullscreen mode

Packet format

USB CDC emits one ASCII line per frame: B1OS + hex(little-endian bytes) + \n.

magic 0xB105 | type | flags | seq u16 | n u16 | payload | xor
Enter fullscreen mode Exit fullscreen mode
type Meaning Payload
0x01 samples one byte per sample; bits 0–3 = CH0–CH3; flags bit 0 = first-burst trigger
0x02 header u8 channels, u32 pin_mask, u32 rate_hz, u32 bio_hz
0x03 trigger empty; one per capture

XOR checksum covers every byte except the last. Full spec: protocol.md.

// dabao/src/engine.rs
pub fn encode_frame(typ: u8, flags: u8, seq: u16, payload: &[u8]) -> Vec<u8> {
    let n = payload.len() as u16;
    let mut f = Vec::with_capacity(9 + payload.len());
    f.extend_from_slice(&MAGIC.to_le_bytes()); // 0xB105
    f.push(typ);
    f.push(flags);
    f.extend_from_slice(&seq.to_le_bytes());
    f.extend_from_slice(&n.to_le_bytes());
    f.extend_from_slice(payload);
    let mut xor = 0u8;
    for b in f.iter() {
        xor ^= *b;
    }
    f.push(xor);
    f
}
Enter fullscreen mode Exit fullscreen mode

On the wire that becomes:

B1OS05B10200....   # header
B1OS05B10301....   # trigger
B1OS05B10101....   # samples, flags=1 on the first burst
Enter fullscreen mode Exit fullscreen mode

BIO kernels

GPIO CSRs that matter (x21–x26), all masked by x26:

CSR Role
x21 level r/w: write applies (x26 & x21) → pads
x22 / x23 set-1 / clear-0
x24 output enable
x25 input enable
x26 action mask
x16 FIFO0 push (halts when full)
x20 quantum wait

Stim (Core 0) — start low, then level-write a walking square:

li   x1, 1
slli x1, x1, 11
ori  x1, x1, 0xE
mv   x26, x1
mv   x24, x1          # this core wins OE
mv   x21, x0          # start low
# loop: wait quantum, OR bits 1/2/3/11 from a counter, mv x21, x2
Enter fullscreen mode Exit fullscreen mode

Sampler (Core 1) — never touch x24/x25, pack a nibble, tag the first word:

mv   x26, x1          # same mask, for reads
# loop:
mv   x20, x0          # wait quantum
mv   x2, x21
# pack BIO1/2/3/11 into x6 bits 0..3
or   x6, x6, x5       # bit 16 set on first sample only
mv   x16, x6          # FIFO0
li   x5, 0
Enter fullscreen mode Exit fullscreen mode

Kernels avoid BIO instruction errata: no lui/auipc/jal with FIFO regs x16–x19, and immediates whose bits [24:20] equal 20. The mask 0x80E is built as li 1; slli 11; ori 0xE.

Build and flash — Dabao

Needs recent Rust (tested 1.100) and riscv32imac-unknown-none-elf. dabao/build.rs installs the Xous sysroot the first time.

The kernel + loader on the board must match xous-core rev 4e9a9909e6ba92b35d7f671074060f68d171cb69 (pinned in dabao/Cargo.toml). Prebuilt images live in firmware/.

rustup target add riscv32imac-unknown-none-elf
cargo install xous-tools          # xous-app-uf2

cd dabao
cargo build --release \
  --target riscv32imac-unknown-xous-elf \
  --features board-dabao --features bao1x --features utralib/bao1x

xous-app-uf2 --elf target/riscv32imac-unknown-xous-elf/release/bioscope
cp apps.uf2 ../firmware/apps.uf2
Enter fullscreen mode Exit fullscreen mode

Flash over the boot1 serial uf2 command. The BAOCHIP mass-storage volume is ~2 MiB of SRAM behind a fake 128 MiB FAT32. Dropping a full image there wedges the console.

Enter boot1: unplug USB, hold PROG (not RESET), plug USB back in, release PROG. boot1 product is Baochip-1x, PID 0x6196.

# from repo root, board in boot1
python3 scripts/flash_uf2_serial.py \
  --port /dev/cu.usbmodemV6VJDB1 \
  firmware/loader.uf2 firmware/xous.uf2 firmware/apps.uf2

python3 scripts/bao_console.py --port /dev/cu.usbmodemV6VJDB1 --cr boot
Enter fullscreen mode Exit fullscreen mode

After boot, the CDC port usually becomes ...V6VJDB3 (Xous, PID 0x6197, LF). Apps-only reflash is the same script with just firmware/apps.uf2.

On the Xous console:

scope pins
scope rate 10000
scope loopback 4000
Enter fullscreen mode Exit fullscreen mode

bao_console.py without --port can grab EchoKit's usbmodem101. Pass the Dabao device explicitly.

Do not type boot1 lockdown or self_destruct.

Build and flash — EchoKit

ESP-IDF via esp-idf-svc / the esp rustup toolchain. This firmware is a scope UI. It is not the EchoKit voice-AI image.

cd echokit
cargo build --release --target xtensa-esp32s3-espidf
espflash flash --port /dev/cu.usbmodem101 --baud=921600 --flash-size 16mb \
  target/xtensa-esp32s3-espidf/release/bioscope-echokit
Enter fullscreen mode Exit fullscreen mode

Speaker path (MAX98357A on I2S1):

let cfg = config::StdConfig::philips(16_000, config::DataBitWidth::Bits16);
let mut i2s = I2sDriver::<I2sTx>::new_std_tx(i2s, &cfg, bclk, dout, None, ws)?;
let _ = i2s.tx_disable(); // clocks off until a pulse
// pulse: tx_enable → 80 ms sine → 100 ms zeros → tx_disable
Enter fullscreen mode Exit fullscreen mode

Leaving TX enabled after the sine makes the DMA/circular buffer loop the last waveform forever. Silence + tx_disable is required.

Host writes to ESP32-S3 USB-JTAG are non-blocking; EAGAIN (errno 35) is normal. host/scope.py retries, keeps DTR/RTS off so the S3 does not reset, and forwards only B1OS lines on a background queue.

Fork and contribute

  1. Fork the repo. Clone. Keep dabao/ as source only (its nested .git is gitignored).
  2. Run python3 host/test_protocol.py — no hardware required.
  3. Change one side at a time: BIO kernels in dabao/src/engine.rs, Xous streaming in dabao/src/cmds/scope.rs, EchoKit UI in echokit/src/, host in host/scope.py.
  4. Keep the wire format in protocol.md in lockstep with all three parsers.
  5. Open a PR with: what you changed, how you flashed, and a loopback log (HEADER / unique sample bytes / duty).

Code map for a first patch:

dabao/src/engine.rs      BIO kernels, pin mux, frame encode
dabao/src/cmds/scope.rs  console: pins / rate / loopback / capture
echokit/src/main.rs      traces, trigger banner, I2S chirp
echokit/src/display.rs   ST7789 init (SPI3, mode 3, invert)
echokit/src/protocol.rs  B1OS + binary parser
host/scope.py            CDC, ASCII scope, USB-JTAG bridge
bio/sampler + bio/stim   C twins for bio-sim
Enter fullscreen mode Exit fullscreen mode

Ideas worth adding

Idea Why it fits BIO
UART / SPI / I2C decode Quantum-timed sampler already has cycle-accurate bits; decode on the host or a third BIO core
Edge + pulse-width trigger Core1 can wait on x21 with a width counter before tagging bit 16
RLE or delta frames USB-JTAG is ~4 KB/s; compressed TYPE_SAMPLES would drop fewer EchoKit frames
PulseView / Sigrok export Host already has packed nibbles + a known rate
Configurable pin mask scope pins 0x80E already has the mux path in setup_iox_pins
Direct UART Dabao → EchoKit PB14 → GPIO17 is wired in firmware; skip the host bridge on a bench
Wi-Fi / BLE stream from EchoKit ESP32-S3 is idle aside from SPI + I2S
Analog / mixed Pair BIO digital with Baochip ADC on a fifth channel
bio-sim CI bio/ kernels already build under ziglang; snapshot FIFO traces in GitHub Actions
More channels BIO bits map PB0–15 then PC0–15; mask and nibble packing extend cleanly

Match xous-core rev 4e9a9909 when you touch dabao/. Rebuild EchoKit with espflash only — leave Dabao in Xous unless you change the app.

Safety notes for flashing

  • Serial-flash UF2 into boot1. Skip the fake mass-storage disk.
  • boot1 REPL uses CR; Xous uses LF.
  • There is no Xous command back to boot1. Unplug, hold PROG, replug.
  • Pace UF2 one block at a time (16 KiB RX queue).

Official docs

Code & more: https://www.dailybuild.xyz/project/335-bioscope

Top comments (0)