Every block of cvsoc now exists and has passed its own tests: the CPU subsystem, the interconnect, the SRAM, the bridge, GPIO, the UART and the timer. This article puts them together in the top-level module, cvsoc_top, and runs the programs from Running Programs on an SoC on your own SoC, with your UART printing their output. Writing a top level is mostly wiring, but wiring is where integration bugs live: a slot number swapped, two windows given in the wrong order, an output left unconnected. Exercise S16 is the second system exercise of the section.

7 min read | Intermediate

What You'll Learn

  • Write a top level that connects a CPU subsystem, an interconnect, memories and peripherals
  • Set the parameters that turn reusable blocks into one specific memory map
  • Run compiled C programs on your complete SoC and read its system report
  • Recognize the integration bugs that block tests cannot find

Before You Start

This section needs Verilog: see the Verilog Tutorial. Pass these first: S08 (Your First System), S10 (The AXI4-Lite to APB Bridge), S11 (GPIO), S14 (The UART) and S15 (The Timer). Top-Level Integration and Connectivity Checks explains how teams build and check top levels.

The Top Level

The top level of an SoC is where its memory map stops being a table and becomes hardware. It instantiates every block and sets the parameters that place them in the map. These are its ports, the outside of the chip as the testbench sees it:

module cvsoc_top (
    input  logic        clk,
    input  logic        rst_n,
    output logic        uart_tx,
    output logic [31:0] gpio_out,
    input  logic [31:0] gpio_in,
    output logic        timer_irq,
    output logic        sim_done,
    output logic [31:0] sim_code
);

Inside, it connects these blocks:

cvsoc_top: u_cpu connects to the interconnect with N = 2 and the two windows; the SRAM is subordinate 0 and the APB bridge subordinate 1 with four peripherals: UART at index 0 in slot 0, timer at index 1 in slot 1, GPIO at index 2 in slot 2, and simulation control at index 3 in slot F.
  • u_cpu, your cvsoc_cpu_subsys from S08. Keep the instance name: the tests load programs through u_cpu.u_tcm.mem and watch u_cpu.u_core.
  • Your cvsoc_axil_xbar with N = 2, its manager side connected to u_cpu's manager port.
  • Subordinate 0: your cvsoc_axil_sram, window BASE 0x2000_0000, SIZE 0x4000.
  • Subordinate 1: your cvsoc_axil2apb, window BASE 0x4000_0000, SIZE 0x1_0000, with NP = 4.
  • Behind the bridge, peripheral 0: your cvsoc_uart in slot 0, tx to uart_tx; peripheral 1: your cvsoc_timer in slot 1, irq to timer_irq; peripheral 2: your cvsoc_gpio in slot 2, its pins to gpio_out and gpio_in; peripheral 3: cvsoc_simctrl in slot F, its done and code to sim_done and sim_code.
  • Every block gets clk and rst_n.

cvsoc_simctrl is the one block you do not write: the tests provide it. It has the same APB ports as your peripherals plus its two outputs; a write to its offset 0x000 sets done and keeps the written value on code.

Parameters Make the Map

None of your blocks contains a cvsoc address. The interconnect knows windows only through BASE and SIZE, the bridge knows slots only through slot, the SRAM knows its size only through WORDS. The top level is the single place where the memory map is written down, and it is written as parameter values. The packing follows the rule from the blocks: entry i sits at bits [32*i +: 32] or [4*i +: 4], so in a concatenation the highest index comes first:

BASE = {32'h4000_0000, 32'h2000_0000}    // subordinate 1, subordinate 0
SIZE = {32'h0001_0000, 32'h0000_4000}
slot = {4'hF, 4'h2, 4'h1, 4'h0}          // peripheral 3 ... peripheral 0

Writing them the other way round is the most common mistake in this exercise, and no block test can catch it, because every block is right. Only a system test that reaches the SRAM and every peripheral finds it.

Quick Check

Q: The slot parameter is written as {4'hF, 4'h1, 4'h2, 4'h0} by mistake. What does hello's line GPIO_OUT = 0xA5; do now?

Show Answer

Peripheral 1, the timer, now sits in slot 2, and peripheral 2, the GPIO, in slot 1. The store to 0x4000_2000 goes to the timer's offset 0x000, MTIME_LO, which ignores writes; the pins never change, and the program's two reads of the "timer" at 0x4000_1000 read the GPIO instead. The program still ends, but gpio_out stays 0 and its printed cycle count is wrong.

How It Is Tested

For S16 you submit one file with all your modules: the TCM, the manager port, the CPU subsystem, the interconnect, the SRAM, the bridge, the FIFO, the transmitter, the UART, the timer, the GPIO, and your new cvsoc_top. The tests load four programs into the TCM and run them, with a terminal model on uart_tx:

  • hello: must print a text that begins with "Hello from cvsoc!", end with the expected checksum, and leave gpio_out at 0xA5;
  • copy_sram: 1,024 words copied into the SRAM and read back;
  • stream_div4: 256 bytes through the UART at DIV = 4;
  • badaddr: three reads that no block can answer, each returning 0.

The visible test runs hello on the behavioral stand-in core, as in S08; the hidden tests use the 3-stage core. As before, `define CVSOC_OWN_CORE on the first line runs your own core instead.

Your SoC at Work

On the reference design, the four programs give these system reports, the same numbers quoted throughout this section:

ProgramInstructionsCyclesCore waiting on the bus
hello7,66616,26543.3%
copy_sram21,52230,74420.0%
stream_div45,66010,55840.7%
badaddr163542.9%

Your SoC should match them exactly if every block takes the cycles its specification gives. The tests do not require that: they check results, not cycle counts, so a block that takes a cycle longer still passes. The cycle count each test prints is a little higher than the report's, because the test keeps running for a few cycles after the program ends to let the last UART character leave the line. Measuring Your SoC uses these reports to account for every cycle.

Where Does This Matter?

On real projects the top level is rarely written by hand any more: tools generate it from a description of the blocks, their parameters and their connections, often in IP-XACT, precisely because hand-written wiring of hundreds of blocks goes wrong in the ways shown here. The checks stay the same: a connectivity test that reaches every block from every manager, and the first software that runs on the whole chip, which is what hello is for cvsoc.

Common Mistakes

Mistake #1: Parameters in the wrong order

BASE, SIZE and slot are packed with the highest index first. Swapping two entries moves blocks to each other's addresses; every block test still passes, and the first program that uses the moved blocks fails.

Mistake #2: An output left unconnected

Leaving .tx() open, or forgetting to connect the simulation control's done, compiles without an error. The program then runs, but nothing reaches the terminal, or the test never sees the end. Check every port of every instance; Top-Level Integration and Connectivity Checks describes the lint rules that flag them.

Mistake #3: Writing your own cvsoc_simctrl

The tests provide cvsoc_simctrl. A second module with the same name in your file is a compile error. Instantiate it; do not define it.

Your Turn in the Lab

Exercise S16: paste all your modules into one file and write cvsoc_top. Run the visible test and watch "Hello from cvsoc!" appear in the log, printed by your own UART; then submit.

Open exercise S16 in ChipVerify Lab

Summary

  • cvsoc_top instantiates the CPU subsystem u_cpu, the interconnect with the SRAM and the bridge, and the UART, timer, GPIO and provided simulation control behind the bridge.
  • The memory map lives only in the top level's parameters: BASE, SIZE, WORDS and slot, packed with the highest index first.
  • The tests run hello, copy_sram, stream_div4 and badaddr on your SoC and check results, the UART text and the GPIO pins.
  • Integration bugs (swapped parameters, open outputs) pass every block test and fail the first program that needs the misplaced block.
Did you find what you were looking for?

Quiz

No quiz questions available for this article.