This section of the SoC Design tutorial is hands-on: you build a small system-on-chip yourself, block by block, around a RISC-V processor core, and run compiled C programs on it that print on a serial line. The first half of the tutorial explained how the parts of an SoC work and how they talk to each other; here you write them. Each block starts as an empty module, a hidden set of tests in ChipVerify Lab grades what you write, and your blocks come together into one SoC named cvsoc. This article explains what you will build, how the exercises work, and what you need before you start.

15 min read | Beginner to Intermediate

Prerequisite: Verilog. You write every block of the SoC yourself, so you need to know Verilog first: modules with ports and parameters, always blocks with blocking and nonblocking assignments, case statements, vectors and bit selects, state machines, and how to read a simulation log and a waveform. If any of that is new, work through the Verilog Tutorial first and come back.

What You'll Learn

  • Describe the SoC you will build, its memory map and the role of each block
  • Explain how the exercises work: an empty module, a specification, a visible test and hidden tests
  • Explain how your blocks become a running system in the two integration exercises
  • Choose between the provided core and your own core from the Computer Architecture tutorial

Before You Start

You need Verilog for this section; it is a firm prerequisite, because no exercise gives you the code. The Verilog Tutorial covers everything used here. The blocks are written in the small part of SystemVerilog that every simulator understands (logic, always_ff, always_comb), the same style as the Computer Architecture tutorial.

Four articles from the first half of this tutorial describe exactly what you are about to build, and the exercises assume them: What Is in an SoC, Buses and Transactions (AXI4-Lite and APB), Memory-Mapped I/O and Registers and Memory Maps and Address Decoding. Each article in this section names the ones it relies on.

The processor core comes from the hands-on section of the Computer Architecture tutorial, Build a RISC-V Core: Section Overview. You do not have to have built it: the tests provide a finished core. If you did build it, you can use your own core in its place, as explained below.

What You Will Build

A system-on-chip (SoC) is a processor together with the memories and devices it works with, on one chip. The one you build, cvsoc, is small enough to finish and complete enough to run real programs. It has the same structure as the reference SoC described in What Is in an SoC:

Block diagram of cvsoc: a CPU subsystem with the cvr32 core, a 64 KB TCM and an AXI4-Lite manager port, connected through an interconnect to a 16 KB SRAM and an APB bridge, with UART, timer, GPIO and simulation control behind the bridge.
  • The CPU subsystem: the processor core cvr32, a 64 KB tightly coupled memory (TCM) that holds the program, its data and its stack and answers in one cycle, and an AXI4-Lite manager port through which the core reaches everything else.
  • The interconnect: it looks at each address and routes the access to the block that owns it, or answers with an error when no block does.
  • The system SRAM: 16 KB more memory, behind an AXI4-Lite port.
  • The APB bridge and the peripherals: APB is a simpler, slower bus for registers. Behind the bridge sit a UART transmitter (a serial line that prints text), a timer, 32 GPIO pins and a small simulation control block that ends a test.

Every block is reached by an address. This is the memory map of cvsoc, the same one the C programs are compiled for:

AddressBlockSize
0x0000_0000TCM, inside the CPU subsystem64 KB
0x2000_0000system SRAM16 KB
0x4000_0000UART4 KB slot
0x4000_1000timer4 KB slot
0x4000_2000GPIO4 KB slot
0x4000_F000simulation control (the EXIT register)4 KB slot
anything elseno block: the interconnect answers with an error

The design is deliberately basic. There is one manager on the bus (the core), one transaction at a time, one clock, no caches, no DMA and no interrupt handling. Those are the subjects of the first half of the tutorial, and the last article of this section shows where each would fit. What you get instead is a system in which every cycle can be explained, which is exactly what you need to understand how the parts of an SoC fit together.

Why Build an SoC Yourself

An SoC is mostly about the connections between blocks: who may talk to whom, how a request travels, what happens when the other side is slow, and what happens when nobody answers. On a block diagram those questions look small. When you build the blocks, each one becomes a concrete decision. Does the manager port keep its address valid until the interconnect accepts it? What does the interconnect send back for an address no block owns, and when? What does the core do in the cycles while a store to the UART is still in flight? The exercises are arranged so that you meet those decisions one at a time.

Integration is also where much of the real work on an SoC goes. A block that passes its own tests can still break the system because it disagrees with its neighbour about one rule. Top-Level Integration and Connectivity Checks describes how teams catch that. In this section you will meet it first-hand, twice: once when your core, memory and bus first run a program together, and once when the whole SoC does.

How the Articles and Exercises Work

Each article in this section is a design brief. It explains what one block does and why, gives its port list, describes its behavior with tables and timing diagrams, says how it is tested, and lists the mistakes people usually make. It does not show the answer.

Each article then sends you to an exercise in ChipVerify Lab. An exercise opens with an empty module: the name, the parameters and the ports are given, the body is empty. The exercise statement next to the editor repeats the specification. You write the logic and press Submit Solution; the lab compiles your code with a hidden testbench and runs it. A testbench is a piece of Verilog that drives a design's inputs and checks its outputs; "hidden" means you see its verdict, not its code.

Next to your design you also get one visible test, testbench.v. For a block it is the directed checks of the hidden test, printing ok or FAIL for each; for a system it is one of the test programs. You can simulate it as often as you like, look at the waveform and add your own checks. When you submit, it runs together with the hidden tests, and nothing you change in it affects the grading.

Many of the tests check a bus protocol, so their messages name the rule that was broken and the cycle it happened in, for example:

Output
FAIL: AWVALID must stay 1 with the same AWADDR until AWREADY is 1

For each exercise, the tests were run against a correct reference design and against a set of typical wrong solutions, on two simulators; they had to pass the first and catch every one of the others.

Quick Check

Q: A program stores a byte to address 0x4000_2000. Which block receives it, and through which buses does the store travel?

Show Answer

GPIO, in slot 2 of the peripheral window. The address is not in the TCM, so the CPU subsystem sends it out through its AXI4-Lite manager port. The interconnect sees that 0x4000_2000 is in the 64 KB window at 0x4000_0000 and routes it to the APB bridge, which turns it into an APB transfer to the peripheral whose slot is 2.

The Exercise Ladder

The section has seventeen graded exercises in four chapters. Each builds on the ones before it:

The seventeen exercises in four columns: Getting Started S01, Memory and the Bus S02 to S08, Peripherals on APB S09 to S16, and Sign-off S17, with the core and system exercises highlighted.
ChapterExercisesWhat you build
Getting StartedS01your core learns to wait for a memory that is not ready yet
Memory and the BusS02 to S08the TCM and its address decode, the AXI4-Lite manager port (reads, then writes), the AXI4-Lite SRAM, the interconnect (reads, then writes), and your first system running C programs
Peripherals on APBS09 to S16the APB bridge (the basic transfer, then wait states and errors), GPIO, the UART from a FIFO and a transmitter, the timer, and the complete SoC
Sign-offS17a synthesis check of your SoC on a real cell library

Larger blocks come in parts. The manager port, the interconnect and the bridge keep the same module and ports through both of their exercises: the first part is graded on the simpler half of the behavior, the second adds the rest. The UART is built from two smaller blocks that you write and test on their own first, a FIFO and a serial transmitter, the way it would be built in industry.

From Blocks to a Running System

Two exercises are system exercises. In S08 you write the CPU subsystem that joins the core, your TCM and your manager port, and the tests connect it to your interconnect and SRAM and run three C programs on it. In S16 you write the top level, cvsoc_top, that connects everything, and the tests run four C programs that print on your UART. For a system exercise you submit one file with all your modules, the versions that passed their own exercises, plus the new one. Keep your passed modules in one project in the lab, one file per module, so you can copy them when you need them.

The core is the one thing the tests provide: a 3-stage RISC-V core, the design built in the Computer Architecture tutorial. If you built that core yourself, you can use it instead. Exercise S01 has you add the one feature an SoC needs from it, waiting for a slow memory, and from then on a line at the top of a system exercise switches the provided core off and uses yours. Either way the SoC is your work; only the instructions are executed by someone else's code if you choose the provided core.

What Your Finished SoC Does

At the end of chapter 13 your SoC runs C programs compiled with gcc. The first one, hello, touches every block once: it prints a greeting on the UART, reads the timer, writes a pattern to the GPIO pins, fills a buffer in the SRAM and prints a checksum of it. Its first line on the serial line is:

Output
Hello from cvsoc!

On the reference design, hello runs 7,666 instructions in 16,265 clock cycles. The core spends 43.3 percent of those cycles waiting for the bus, because every access outside the TCM takes several cycles: a TCM access takes 1 cycle, an SRAM access 4 and a peripheral access 6. Most of that waiting goes to the UART: the program checks the UART's status register before every character, because characters leave the serial line far more slowly than the core produces them. Running Programs on an SoC shows the full report, and Latency and Bandwidth explains why these numbers matter.

Where Is This Used?

The structure of cvsoc is the structure of a typical microcontroller: one small core with a fast local memory, an AXI or AHB bus to the larger memories, and a bridge to an APB bus where the slow register-based peripherals sit. Arm's reference subsystems for Cortex-M cores and many open-source RISC-V microcontroller platforms are organized the same way, with a few more managers (a debug port, a DMA engine) and many more peripherals.

The Tools

Everything runs in ChipVerify Lab in your browser. The exercises are simulated with Icarus Verilog or Verilator, two open-source simulators, and every test was checked on both. The C programs were compiled with the GNU compiler for RISC-V (riscv64-unknown-elf-gcc, version 13.2), and the synthesis check uses Yosys with the open SkyWater 130 nm cell library. All the exercises are free.

Quick Check

Q: hello takes 16,265 cycles and the core waits for the bus in 43.3 percent of them. About how many cycles would it take if every access outside the TCM took a single cycle, like the TCM?

Show Answer

Roughly 16,265 x (1 - 0.433), about 9,200 cycles. That is only an estimate: some of the waiting would turn into more polling of the UART's status register, because the characters still leave the serial line at the same speed. Removing bus waits helps the parts of the program that compute and copy, not the parts that wait for a slow device.

Common Mistakes

Mistake #1: Changing names, parameters and ports

The module names, parameter names, port names and widths, and the instance names the system tests look for (u_cpu, u_core, u_tcm), are part of the specification. A different name compiles in your own project but does not connect to the hidden testbench, and every test fails without a useful message.

Mistake #2: Skipping the block exercises and starting with the system

A system test can only tell you that a program ended with the wrong result; a block test tells you that your interconnect answered OKAY to a read of an address no block owns. Pass each block on its own first, and the system exercises become a matter of wiring.

Mistake #3: Trusting a block because it passed

A block test checks the block against its specification, but in a system it meets its neighbours, which may use it in a way you did not think of. When a system test fails, suspect your newest code first and your blocks second, and find the failing access in the waveform before you change anything.

Your Turn in the Lab

There is nothing to submit for this article. Open the course in ChipVerify Lab, look at the four chapters, and open exercise S02 to see what an exercise looks like: the statement, the empty module in the editor, the visible test next to it and the Submit Solution button. Then create one project in the lab for your own modules; you will start filling it in Your Core Learns to Wait or, with the provided core, in The TCM and the Local Decode.

Open the course SoC Design: Build an SoC Around Your Core in ChipVerify Lab

Summary

  • This section is hands-on: you write every block of a small SoC yourself, from an empty module, and hidden tests in ChipVerify Lab grade it. Verilog is a prerequisite.
  • cvsoc has a CPU subsystem (core, 64 KB TCM, AXI4-Lite manager port), an interconnect, a 16 KB SRAM, and an APB bridge to a UART, a timer, GPIO and simulation control.
  • Seventeen exercises in four chapters: block exercises test one module on its own, the two system exercises run compiled C programs on your blocks, and a synthesis check closes the section.
  • The tests provide the processor core; if you built it in the Computer Architecture tutorial, S01 makes it wait for slow memories and you can use it instead.
  • On the reference design, hello runs 7,666 instructions in 16,265 cycles, waiting for the bus in 43.3 percent of them: 1 cycle per TCM access, 4 per SRAM access, 6 per peripheral access.
Did you find what you were looking for?

Quiz

No quiz questions available for this article.