Goal: Extend SPI verification to UVM+SV — SPI agent (transaction, sequence, driver, monitor, scoreboard); run on Verilator.
← Previous: Module 5: SPI → | Next: Module 7: I²C →
This module applies UVM to the SPI DUT. Before running commands:
- Read the detailed SPI learning guide: SPI_LEARNING_GUIDE.md — what SPI is, how it works (signals, Mode 0, timing), and how it maps to our RTL.
- Read the protocols + UVM overview: LEARNING_GUIDE_PROTOCOLS_AND_UVM.md — Part B § 5. How UVM Maps to a Protocol and § 7. SPI UVM Mapping (where UVM sits, how transaction/driver/monitor/scoreboard map to SPI).
Then follow Overview → Topics Covered → Example → Exercises.
- Module doc: module6/README.md
- Example: module6/examples/spi_uvm/ — SPI RTL + full UVM agent (same DUT as Module 5)
Quick run (from repo root):
cd module6/examples/spi_uvm
make SIM=verilator TEST=test_spi_uvmOr: ./scripts/module6.sh --run
Module 6 builds on Module 5 (SPI protocol + RTL + basic testbench):
- Same DUT: spi_master, clk_div (reused from module5/examples/spi_baseline).
- UVM testbench: SPI agent — transaction (byte to send), sequence (directed bytes: 0x00, 0x01, 0x55, 0xAA, 0xFF), driver (start/data_in, wait for done), monitor (observe sclk/mosi/cs_n, sample MOSI on rising SCLK, MSB first), scoreboard (expected vs observed).
- Toolchain: Verilator + UVM_HOME + Make (same as Module 2).
- SPI UVM agent: Transaction (SpiTransaction), sequence (SpiSequence), driver (SpiDriver), monitor (SpiMonitor), scoreboard (SpiScoreboard).
- Interface: spi_master_if (clk, rst_n, clk_div_tick, start, data_in, sclk, mosi, cs_n, busy, done) connects UVM to DUT.
- Mode 0 monitoring: SCLK idle low; capture on rising edge; monitor samples MOSI on each rising SCLK, MSB first, to reconstruct the byte.
- Module 1 (spec → RTL), Module 2 (UVM+SV, uvm_smoke), Module 5 (SPI protocol + RTL + basic TB).
- Verilator, Make, C++ compiler, UVM (UVM_HOME or vendored UVM).
- Transaction (SpiTransaction): byte to send (data); monitor fills observed_mosi (reconstructed from MOSI on SCLK).
- Sequence (SpiSequence): produces directed transactions (0x00, 0x01, 0x55, 0xAA, 0xFF).
- Driver (SpiDriver): gets transaction, drives start and data_in for one cycle, waits for done.
- Monitor (SpiMonitor): watches cs_n; when cs_n goes low, samples MOSI on each rising edge of SCLK (mode 0, MSB first), writes transaction to scoreboard.
- Scoreboard (SpiScoreboard): compares expected (from test) vs observed_mosi (from monitor).
- SPI mode 0: SCLK idles low; data captured on rising edge; data changed on falling edge.
- Monitor: Waits for cs_n low, then on 8 rising edges of SCLK captures MOSI into bits [7:0] (MSB first).
- Same as Module 2: Verilator with -sv, --timing, --trace, UVM include paths, make SIM=verilator TEST=test_spi_uvm. Run with +UVM_TESTNAME=SpiTest.
| Component | Role |
|---|---|
| dut/ | spi_master.v, clk_div.v (same as Module 5) |
| test_spi_uvm.sv | Interface, SpiTransaction, SpiSequence, SpiDriver, SpiMonitor, SpiScoreboard, SpiAgent, SpiEnv, SpiTest; top with clk_div, spi_master, clock/reset |
Run: cd module6/examples/spi_uvm && make SIM=verilator TEST=test_spi_uvm
cd module6/examples/spi_uvm
make SIM=verilator TEST=test_spi_uvmOr from repo root: ./scripts/module6.sh --check then ./scripts/module6.sh --run.
UVM is used only in the testbench around the SPI DUT. The transaction is one byte; the driver drives start/data_in and waits for done; the monitor samples MOSI on rising SCLK (mode 0, MSB first) and sends the reconstructed byte to the scoreboard. See LEARNING_GUIDE_PROTOCOLS_AND_UVM.md § 7 for the full mapping.
- Describe the SPI UVM agent (transaction, sequence, driver, monitor, scoreboard) and mode 0 monitoring.
- Run spi_uvm and interpret UVM output.
- Ready for Module 7: I²C protocol + RTL + basic testbench.
-
Run spi_uvm
- Run
make SIM=verilator TEST=test_spi_uvminmodule6/examples/spi_uvm. Confirm UVM phases, DRIVER/MONITOR/SCOREBOARD messages, and scoreboard pass.
- Run
-
Trace one transaction
- For one transaction (e.g. 0x55), trace: sequence → driver (start, data_in, wait for done) → DUT drives SCLK/MOSI/CS_N → monitor samples MOSI on rising SCLK → scoreboard compares. Map to the corresponding UVM classes.
-
Change the sequence
- Add or change a value in the SPI sequence and update the test/scoreboard expected values. Re-run and confirm pass.
-
Optional: Compare to UART UVM
- Compare the structure of the SPI agent to the UART agent (Module 4): same pattern (transaction, sequence, driver, monitor, scoreboard), different protocol timing.
- Can describe the SPI UVM agent and how it maps to SPI (one byte, mode 0 monitoring).
- Can run spi_uvm and interpret UVM output.
- Ready for Module 7: I²C protocol + RTL + basic testbench.
After Module 6, proceed to Module 7: I²C — protocol + RTL + basic testbench.