Episode 03 put CVE2 in charge of board control. Episode 04 folds those scattered accesses into one memory-mapped peripheral bus: GPIO, SPI (QSPI Flash + TF card), I²C EEPROM, four PWM channels, bus-error reporting and a five-source interrupt aggregator. With no scope and no signal generator, PWM is checked by its own on-chip capture counter, while SPI and I²C are accepted by device responses.
No waveform-level evidence in this episode. There is no oscilloscope, logic analyzer or signal generator on site, so acceptance relies on device responses plus on-chip counting: PWM CH0 captures its own period and high time, SPI reads the Flash JEDEC ID and the TF card R1, I²C reads the EEPROM ACK. This proves the transactions complete; it does not prove eye height, rise time or clock-domain jitter.
Complete boot log after JTAG programming. Every self-test finishes before READY, with no host command required:
ALINX AR035 CVE2 Peripheral Bus EP04
BOOT CAUSE=POR/EXT
GPIO TEST=PASS
FLASH ID=00c84018 OK
EEPROM DATA=00000074 ACK
SD R1=00000001 OK
PWM PERIOD=0000c350 HIGH=000061a9 FREQ=1000 DUTY=500/1000
PWM TEST=PASS
BUSERR TEST=PASS
IRQ TEST START
IRQ COUNT=00000001
IRQ TEST=PASS
KEY1=0 KEY2=0
BUS TXN=00434418 RD=002e2c51 WR=001539d2 WAIT=00000000 ERR=00000002 LAST=00003044
IRQ STATUS=00000000 ENABLE=00000000 COUNT=1
READY
PWM PERIOD=50000 / HIGH=25000 comes from CH0 capturing its own output with a 50 MHz free-running counter: 1.000 kHz and 500‰ duty, exactly the programmed 50,000 / 25,000. That is the core substitute for a scope in this episode.
| Block | Test | Expected | Observed | Result |
|---|---|---|---|---|
| GPIO | OUT/SET/CLR/TOGGLE readback | bit-exact | GPIO TEST=PASS | pass |
| SPI Flash | QSPI JEDEC ID 9F | C8 40 18 | 00c84018 | ok |
| SPI TF card | CMD0, R1 response | 0x01 | 0x01 | ok |
| I²C EEPROM | 7-bit 0x50, word address 0, read 1 byte | ACK on address and data | DATA=0x74 ACK | ACK pass |
| PWM | CH0 50,000/25,000, on-chip capture | period 49k–51k, high 24.5k–25.5k | 50,000 / 25,000 | pass |
| Bus error | read/write unmapped 0x5000_0000 | load/store access fault | trap count=1, cause 5/7 | pass |
| Interrupt | PWM period → irq_external | trap entered, count increases | IRQ COUNT=1 | pass |
| KEY | read KEY1/KEY2 | 0 when released | KEY1=0 KEY2=0 | readable |
I²C stops at ACK level: address byte, word address, repeated start and data read all receive ACK, so the bus timing and slave addressing work. The returned byte is whatever the board EEPROM contains; firmware does not compare it against a fixed value and does not claim data integrity. KEY still has no pressed/debounce count.
CVE2 instruction and data requests share one decoder. Data requests always grant with gnt=1; an unmapped address returns rvalid+err, which the core turns into a load/store access fault.
| Base | Block | Registers |
|---|---|---|
0x0000_0000 | Instruction / data RAM | 16 KiB + 16 KiB |
0x1000_0000 | UART | +0 TX, +4 status, +8 RX |
0x3000_0000 | WDT | +0 arm, +4 kick, +8 cause, +C status |
0x4000_0000 | GPIO | +0 OUT, +4 IN, +8 DIR, +C SET, +10 CLR, +14 TOGGLE |
0x4001_0000 | SPI | +0 CTRL, +4 TX, +8 RX, +C STATUS; CTRL[1] flash_cs_n, [2] sd_ncs, [15:8] divider |
0x4002_0000 | I²C | +0 CTRL, +4 TX, +8 RX, +C STATUS; start/read/stop/write byte |
0x4003_0000 | PWM | CH0 +00/+04/+08, CH1 +10, CH2 +20, CH3 +30; +40/+44 captured period/high |
0x4004_0000 | BUS | +0 TXN, +4 RD, +8 WR, +C WAIT, +10 ERR, +14 IRQ status, +18 enable, +1C clear |
0x4005_0000 | DBG | +0 cfg/clock, +4 version 0x45503034 |
STARTUPE2.USRCCLKO; the TF card uses a normal pin. MOSI is shared and MISO is selected by CS. Mode 0, 8-bit, reset divider 124 (~200 kHz), Flash probe temporarily switches to 4 (~6.25 MHz).IDLE/START/TXBIT/ACK/RXBIT/NACK/STOP/DONE, each phase counted by div. Writes sample ACK, reads send NACK; ack=0 means the slave responded.cap_period/cap_high/cap_valid, so it can measure itself without a probe.BUS block; irq_ext drives CVE2 irq_external_i.case(data_addr[7:4]) did not qualify the low four bits, so writes to +4 (duty) and +8 (CTRL=1) also landed on pwm_period[0], collapsing the period to 1. Besides failing the PWM test, it raised one interrupt per cycle and turned into an interrupt storm once enabled. Fix: qualify period writes with data_addr[3:0]==0.irq_handler, so t0–t3 were not spilled and the return restored from the wrong stack. Changed to j trap_handler so the common prologue runs.busy immediately, when busy had not asserted and done was still 1 from the previous transfer, so it returned and read a stale ACK. Fixed by waiting for busy to assert first, then for busy to clear and done to set.| Item | Value | Utilization |
|---|---|---|
| Slice LUTs | 4,103 | 19.73% |
| Slice Registers | 3,559 | 8.56% |
| Block RAM Tile | 8 | 16.00% |
| DSPs | 11 | 12.22% |
| Bonded IOB | 25 | 10.00% |
| WNS / WHS | 1.285 ns / 0.052 ns | 0 failing endpoints |
Versus Episode 03 this adds 690 LUTs and 882 FFs, mostly from the SPI/I²C byte FSMs, four PWM channels plus capture counters, the five-source interrupt aggregator and the bus-error path; BRAM, DSP and IOB are unchanged. Bitstream top_cve2_ep04.bit, 2,192,137 bytes, SHA-256 5940ddfc502c5ecb29e09493dc0d5fae0d3de177c3b194c57c56549ced681145.
riscv-nuclei-elf-gcc (GCC 10.2), JTAG and USB-UART cables; keep a TF card in the socket.cd sw && make clean && make.vivado -mode batch -source build_ep04.tcl.vivado -mode batch -source program_ep04.tcl.cd sw && make clean && make
cd ..
/media/alinx/nvme4t/Xilinx/2025.2/Vivado/bin/vivado -mode batch -source build_ep04.tcl
/media/alinx/nvme4t/Xilinx/2025.2/Vivado/bin/vivado -mode batch -source program_ep04.tcl
python3 cap_serial.py 10 /tmp/ep04.bin # start before programming
These files come directly from the verified project. Use the OpenHW repository as the source of truth for upstream CVE2 code.
Daily Briefing · Weekly Digest · Monthly Deep Dive