One Chip Test from Reset to Pass
Follow one real test on ap_soc from the moment the power is good to the moment the chip says pass. Meet the firmware, the bench, the console and the pass word, and read every step with numbers measured on the run.
You Will Be Able To
- Put one chip test in order: power, clocks, resets, first fetch, start-up code, main, register writes, pass word.
- Say what the firmware does, what the bench does, and how the chip says pass.
- Read the console and the main keys of a run's result block.
- Explain why printed text is never the verdict of a chip test.
- Lesson
- VF.3
- Time
- 28 min
- Runs on
- Your browser
- Check
- 5 questions
You press run on your first chip test. For a few hundred nanoseconds nothing you wrote has happened yet, and then a line of text appears. This page walks the whole run, step by step, so the line is no longer a surprise.
- Test
- Clock / reset
- Memory
- Processor
- Peripheral
- Control / FSM
- Power
- Reset
- Data
- 13 ns: power is good
The power-on reset lets go. Every flip-flop is still held in reset while the oscillators start.
- 45 to 260 ns: clocks
The oscillator gives a first clock. The PLL locks at 165 ns, and the system clock moves to it at 260 ns.
- 375 and 405 ns: resets let go
The bus leaves reset first, then the core, so the bus is ready when the core asks for its first instruction.
- 415 ns: the first fetch
The core asks the boot ROM for address 0. Its first instruction retires at cycle 9.
- Cycles 9 to 152: start-up code
It sets the stack and writes 1 to TB_STATUS. Then it copies and clears memory and writes 2: main is about to run.
- Cycle 156: main
The test says hello, reads CHIP_ID at cycle 389 and checks it.
- Cycles 398 and 402: two register writes
PINMUX gives pad IO0 to the UART, and TXDATA starts the byte K. The bench's UART model reads it off the pad.
- Cycle 720: the pass word
main returns 0, and the start-up code writes 0x900D to TB_STATUS. The run ends at cycle 728 with verdict pass.
Read the diagram as text
- Bench: clock, supply, reset pin, the program
- Clocks and resets: PLL locked 165 ns; bus out of reset 375 ns
- Boot ROM: first fetch 415 ns
- Core: start-up code, then main at cycle 156
- UART0 and pad IO0: byte K on the pad from cycle 402
- Mailbox: pass word at cycle 720
- Bench → Clocks and resets: power good
- Clocks and resets → Boot ROM: reset released
- Boot ROM → Core: instructions
- Core → UART0 and pad IO0: register writes
- Core → Mailbox: status, characters
- Mailbox → Bench: verdict
One run of first_test.c on ap_soc v1.5. Cycles from soc_tb on Verilator 5.052 (GCC 14.2, -Os); times in ns from Icarus 12.
Before You Start
Read An SoC as a Verifier Sees It and From IP to Chip to System first. A little C helps: a function, an if statement, a return value. If C registers are new, A Register Is an Address explains them. The companion track shows a test that can fail in The Simplest Test That Can Fail. It shows the four ways a test ends in How a Test Ends.
This site runs ap_soc v1.5 in simulation: Verilator for graded runs, Icarus for small slices. It has no emulator and no FPGA board. The run on this page is a real one: the numbers come from its recording.
| Question | |
|---|---|
| 1 | In what order does one chip test happen, from power to pass? |
| 2 | What does the firmware do, and what does the bench do? |
| 3 | How does the chip tell the bench that the test passed? |
| 4 | What do the console and the result block show? |
| 5 | Why is a line of text never the verdict? |
The Idea: A Program on the Chip, Checked from Outside
A chip test with a processor is a small program that runs on the chip itself. That program is the firmware: the code the chip's own processor runs. It drives the chip from the inside, through the same registers a product's software would use. Before its first line runs, the chip must boot: its clocks start, its resets let go, and start-up code prepares memory.
Around the chip sits the bench, the simulated board. It gives the chip its clock, supply and reset pin, loads the program, and watches the pads. The bench decides the result. The firmware cannot declare itself a winner; it can only report, and the bench checks the report against what it saw.
So every run has two sides talking. The firmware writes words into a few special registers, the mailbox. The bench reads those writes and prints them as the console. One of those words, the pass word, is the chip's way of saying "my checks all held".
New Words
| Word | Meaning |
|---|---|
| Firmware | The program the chip's own processor runs. Here, a test written in C. |
| Bench | The simulated board around the chip: clock, supply, reset, program loading, pad models and checks. |
| Boot | What happens from reset to the first line of the program: clocks start, resets let go, start-up code runs. |
| Power-on reset | A reset that holds the whole chip while its supply comes up, then lets go. |
| Oscillator, PLL | An oscillator makes a first, rough clock. A PLL turns a reference clock into the fast system clock; it locks when that clock is steady. |
| Fetch | The core reads its next instruction from memory. |
| Retire | An instruction retires when it has finished and its result counts. |
| Retire trace | One record for each retired instruction: its cycle, its address, the instruction and what it changed. |
| Stack | Memory a C program uses for local variables and return addresses. |
| Start-up code | The few instructions before main that set the stack and prepare memory. |
| Cycle | One tick of the system clock, clk_sys, here 10 ns. The bench counts cycles from the bus reset. |
| Mailbox | Four registers in ap_sysctl that the firmware writes and the bench watches. |
| Console | The text the firmware writes to the mailbox one character at a time. The bench prints each line. |
| Pass word | The value 0x900D written to TB_STATUS: the test says all its checks held. |
| Fail word | 0xBAD0_0000 plus a code: the test says which check failed. |
| Result block | The lines the bench prints at the end: the verdict, the reason and counters. |
| Checker | Bench code that watches signals and reports a broken rule, such as a wrong bus transfer. |
| Cycle limit | The longest a run may last. A run that reaches it without a verdict fails. |
| UART frame | One byte on a serial line. A start bit at 0, eight data bits with the low bit first, then a stop bit at 1. |
| Reference model | A program that predicts what each instruction should do, so the bench can compare. |
The Test Itself, Read by Hand
Here is the whole test. Read it as a list of requests to the chip. For each one, ask what the bench can see.
/* first_test.c: say hello, check the chip's identity, send one byte out of a pad, pass. */
#include "hal.h"
#include "tb.h"
int main(void)
{
tb_puts("hello from ap_soc\n"); /* a console line */
unsigned id = reg_read32(SYSCTL_CHIP_ID); /* read a register */
if (id != 0x2A5310C5u) {
tb_puts("wrong chip\n");
return 1; /* fail word 0xBAD00001 */
}
reg_write32(SYSCTL_PINMUX, 2); /* pad IO0 now carries UART TX */
unsigned byte = 'K';
reg_write32(UART0_TXDATA, byte); /* one byte leaves the chip */
while ((reg_read32(UART0_STATUS) & UART0_STATUS_ROOM_MASK) == 0) { }
tb_puts("byte sent\n");
return 0; /* pass word 0x900D */
}
| Line | The chip does | The bench sees |
|---|---|---|
tb_puts("hello ...") | Writes 18 characters to TB_PUTC in the mailbox | One console line |
reg_read32(SYSCTL_CHIP_ID) | Reads the chip's identity register | Nothing directly; the test checks it |
return 1 on a wrong identity | Start-up code writes the fail word 0xBAD0_0001 | Verdict fail, code 1 |
reg_write32(SYSCTL_PINMUX, 2) | Gives pad IO0 to the UART | The pad is driven high, idle |
reg_write32(UART0_TXDATA, byte) | Starts one byte on the UART | Ten bit times on pad IO0: the byte K |
while (... ROOM ...) | Waits until UART0 has sent the whole frame | Nothing; it only waits |
return 0 | Start-up code writes the pass word 0x900D | Verdict pass, if nothing else went wrong |
Count the console bytes before you look at the run. "hello from ap_soc" plus its newline is 18; "byte sent" plus its newline is 10. The result block should say console_bytes = 28.
The Rules
Rule 1: The bench owns the clock, the reset and the verdict.
The firmware cannot end a run as a pass by itself.
Rule 2: The firmware reports through the mailbox.
Console text is only text. The verdict comes from TB_STATUS.
Rule 3: A pass needs three things.
TB_STATUS = 2 (main ran) first, then the pass word, and no checker error during the run.
Rule 4: Every run ends one way.
A checker error, a fail word, the cycle limit, a stall with no progress, or the pass word. The first one decides.
Sources for These Rules
The bench's end of test, its order of authority and the mailbox: tools/soc/ap_soc/bench/soc_tb/README.md; docs/soc/ap_soc-facts.md 27.12.
The power-up numbers of the clock and reset block: docs/soc/ap_soc-facts.md 27.1 and 27.11.
Why software must run with the RTL before a chip is ready: Mehta, ASIC/SoC Functional Design Verification, section 12.1.
Now Run It: The Recorded Run
The test ran on the chip bench used by the problems of this track. The bench printed two console lines, each with the cycle of its newline:
CONSOLE 375: hello from ap_soc
CONSOLE 691: byte sentWalk the timeline at the top of the page with the rules. Power is good at 13 ns, the PLL locks at 165 ns, and the bus leaves reset at 375 ns. The core follows at 405 ns and fetches its first instruction at 415 ns. From here the bench counts cycles.
Start-up code writes 1 to TB_STATUS at cycle 23 and 2 at cycle 152: rule 3's first condition. main starts at cycle 156, and the hello line is complete at cycle 375. The identity read returns 0x2A53_10C5 at cycle 389.
Then the two register writes, at cycles 398 and 402. A probe, bench code that only reads signals, saw pad IO0 fall for the start bit at cycle 402. Its last edge, the stop bit, came at cycle 546, nine bit times later. Each bit took 16 cycles, the reset value of UART0's divider. The test polled ROOM 24 times while the frame went out.
23 | 00000028 | sw t1, 0(t0) | mem[10004020] = 00000001
152 | 00000088 | sw t1, 0(t0) | mem[10004020] = 00000002
389 | 00000258 | lw a4, 0(a5) | x14 = 2a5310c5, read mem[10004000] = 2a5310c5
398 | 00000288 | sw a4, 16(a5) | mem[10004010] = 00000002
402 | 00000294 | sw a4, 0(a5) | mem[10000000] = 0000004b
720 | 00000200 | sw a5, 32(a4) | mem[10004020] = 0000900dNow read the result block, before the console, as rule 2 asks:
| Key | Value | Meaning |
|---|---|---|
| verdict, reason | pass, pass | How the run ended, by the bench's rules |
| status | 0x0000900D | The word that ended the test: the pass word |
| main_entered | 1 | TB_STATUS = 2 was seen: the test really started |
| cycles, retired | 728, 354 | Cycles from the bus reset to the end; instructions finished |
| compares, mismatches | 354, 0 | Instructions checked against the reference model; how many differed |
| checker_errors | 0 | Errors from the checkers: broken bus rules and failed block checks |
| uart_bytes, uart_frames | 1, 1 | What the bench's UART model received on pad IO0 |
| console_bytes | 28 | Characters written to the console |
| visited | 0099 | Regions touched: bit 0 ROM, 3 SRAM, 4 UART0, 7 ap_sysctl |
Measured on soc_tb (Verilator 5.052; GCC 14.2, -Os). cycles and retired change with the compiler; the verdict does not.
Every key agrees with the reading by hand. Twenty-eight console bytes, one byte on the pad, the pass word, and every instruction matched the reference model.
A Slice of the Bench's Decision
The lab at the end of this page replays this run's own mailbox writes, taken from its trace. It applies rules 2 to 4. It builds the console from TB_PUTC, notes main, and stops at the first pass or fail word.
console 376: hello from ap_soc
console 692: byte sent
verdict 720: passNow delete the pass word from the list and run it again. Both console lines still print, and still look fine. Yet the verdict becomes a fail at the cycle limit, because no pass word ever came.
Why It Is Built This Way
Why a mailbox and not the UART for the verdict? A mailbox write is one bus transfer and works before any device is set up. A UART byte costs a whole frame on the pad, here from cycle 402 to past cycle 546. It also needs the pin mux first.
Why does the test check the chip itself, with the identity compare? Because only the firmware knows what it meant to happen. The bench checks what it can see from outside: the pad, the mailbox, the bus rules and the reference model. Together they leave little room for a false pass.
Traps
The first trap is believing the console. A test can print every line you hoped for and still fail, as the slice shows. Read verdict and reason first, then the counters, and only then the text.
The second trap is a test that passes without doing its work. Delete the TXDATA write and this test still returns 0. That is why the bench also counts the bytes on the pad, and why the problems of this track grade them.
The third trap is reading a slow first step as a broken chip. The first instruction does not retire until cycle 9 after the bus reset. That wait is boot, not a bug. The lesson on the first run shows how to climb from clocks to main when nothing prints at all.
At Scale
This section looks ahead. This run takes 728 cycles from the bus reset.
Long boots
A product boot loader can run millions of cycles before main. Teams keep a short boot for most tests and test the full one separately.
Many tests, one image style
A regression runs thousands of such tests. Each one reports through the same mailbox, so one bench decides them all the same way.
First silicon
On real chips, the same kind of test is often the first program run. The verdict then comes over a UART or a debugger.
Where This Goes Next
Each step of this tour has a lesson of its own later in the track. Start with the practice problem: change this test yourself.
| Lesson | What it adds |
|---|---|
| The Flow From Hand-Off to Sign-Off | The phases of a project, from the hand-off package to sign-off. |
| The First Run | The first run in depth: the console, the trace and the waves, and what to do when nothing prints. |
| Before main | Start-up code and the linker script, line by line. |
| The Life of a C Test | The life of a C test, stage by stage. |
| Parameters From the Bench | Parameters from the bench, as the practice problem uses one. |
| Ending a Test Honestly | Ending a test honestly: every way a run can end. |
Try It
Run the slice and compare its console lines with the bench's lines above.
Delete the pass word, the last write in the list, and predict the verdict before you run it.
Change the 2 written to TB_STATUS into a 3, and predict what the pass word now means.
console 376: hello from ap_soc console 692: byte sent verdict 720: passCheck Yourself
Common Mistakes
Wrong Call a run passed because the console looks right.
The console is only what the firmware wrote.
Fix Read verdict and reason first.
Wrong Let the firmware decide the result alone.
A test can skip its work and still return 0.
Fix Have the bench check effects it can see: pads, bus rules, the model compare.
Wrong Count cycles from time 0.
Power-up takes a fixed time no test can change.
Fix Count from the bus reset, as the bench does.
Remember
- A chip test is firmware on the chip and a bench around it.
- Order: power good, clocks, resets, first fetch, start-up code, main, register writes, pass word.
- The firmware reports through the mailbox; the bench prints the console and decides.
- Read the result block before the console: text is never the verdict.