fpga.love
中文 App
Home / Projects / CVE2 EP02 case
Reproduction · OpenHW on ALINX · Episode 04

Peripheral bus matrix: GPIO / SPI / I²C / PWM in one address map

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.

Verified on board · 2026-11-20 CVE2 / RV32IM 50 MHz Vivado 2025.2 Episode 04 / 12

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.

BoardALINX PI-AR035-F1-1Engineering board, not yet in the board selector
SiliconAMD Artix-7 · XC7A35TDevice data and sister boards → ProjectOpenHW CVE2 / CV32E20Upstream repo and commit →
Board
ALINX PI-AR035-F1-1
Peripherals
GPIO / SPI / I²C / PWM
Interrupts
5 sources · irq_external
PWM
4 channels · 32-bit period/duty
Flash
GD25Q128E · C8 40 18
I²C
7-bit 0x50 · ACK
Bitstream
2,192,137 B

1. Board result

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.

2. Test matrix

BlockTestExpectedObservedResult
GPIOOUT/SET/CLR/TOGGLE readbackbit-exactGPIO TEST=PASSpass
SPI FlashQSPI JEDEC ID 9FC8 40 1800c84018ok
SPI TF cardCMD0, R1 response0x010x01ok
I²C EEPROM7-bit 0x50, word address 0, read 1 byteACK on address and dataDATA=0x74 ACKACK pass
PWMCH0 50,000/25,000, on-chip captureperiod 49k–51k, high 24.5k–25.5k50,000 / 25,000pass
Bus errorread/write unmapped 0x5000_0000load/store access faulttrap count=1, cause 5/7pass
InterruptPWM period → irq_externaltrap entered, count increasesIRQ COUNT=1pass
KEYread KEY1/KEY20 when releasedKEY1=0 KEY2=0readable

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.

3. Address map

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.

BaseBlockRegisters
0x0000_0000Instruction / data RAM16 KiB + 16 KiB
0x1000_0000UART+0 TX, +4 status, +8 RX
0x3000_0000WDT+0 arm, +4 kick, +8 cause, +C status
0x4000_0000GPIO+0 OUT, +4 IN, +8 DIR, +C SET, +10 CLR, +14 TOGGLE
0x4001_0000SPI+0 CTRL, +4 TX, +8 RX, +C STATUS; CTRL[1] flash_cs_n, [2] sd_ncs, [15:8] divider
0x4002_0000I²C+0 CTRL, +4 TX, +8 RX, +C STATUS; start/read/stop/write byte
0x4003_0000PWMCH0 +00/+04/+08, CH1 +10, CH2 +20, CH3 +30; +40/+44 captured period/high
0x4004_0000BUS+0 TXN, +4 RD, +8 WR, +C WAIT, +10 ERR, +14 IRQ status, +18 enable, +1C clear
0x4005_0000DBG+0 cfg/clock, +4 version 0x45503034

4. Bus and interrupt design

5. Pitfalls

6. Resources and timing

ItemValueUtilization
Slice LUTs4,10319.73%
Slice Registers3,5598.56%
Block RAM Tile816.00%
DSPs1112.22%
Bonded IOB2510.00%
WNS / WHS1.285 ns / 0.052 ns0 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.

7. Reproduction

  1. Prepare Vivado 2025.2, riscv-nuclei-elf-gcc (GCC 10.2), JTAG and USB-UART cables; keep a TF card in the socket.
  2. Build firmware: cd sw && make clean && make.
  3. Synthesize and implement: vivado -mode batch -source build_ep04.tcl.
  4. Start hw_server on 3122 and program: vivado -mode batch -source program_ep04.tcl.
  5. Drain the UART for 0.8–1 s and start capture before programming, so bytes left over from the previous bitstream are not mistaken for the new log.
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

8. Project files

These files come directly from the verified project. Use the OpenHW repository as the source of truth for upstream CVE2 code.

Verified here: GPIO bit ops, Flash JEDEC, TF CMD0, EEPROM ACK, PWM on-chip capture, unmapped-access exception and PWM interrupt. Not verified: I²C read-byte content, EEPROM write/erase, Flash erase/write, SD block I/O, KEY press debounce, bus peak bandwidth, waveform quality.

9. Related

Subscribe to fpga.love

Daily Briefing · Weekly Digest · Monthly Deep Dive