Clocks, Resets and Straps from the Outside

A chip bench gives the chip only what a board gives it: a clock, a supply, a reset pad and the straps. Watch ap_soc turn those into its own clocks and resets, in a fixed order. Then learn the rules a bench's generators must follow.

You Will Be Able To

  • Explain why a chip bench drives the reference clock and the reset pad, not the internal clocks and resets.
  • Read a power-up timeline: power-on reset, clock switch-over, release order, first fetch.
  • State the release order of ap_soc and what a warm reset does to it.
  • Write a board generator whose pads never move on a clock edge.
Lesson
V3.2
Time
24 min
Runs on
Your browser
Check
5 questions

Picture a first boot in which the core fetches its first instruction while the bus is still in reset. The fetch hangs, the run hits its cycle limit, and the log says nothing useful. The fault is not in the core. It is in the order in which the resets let go.

Two Clocks and a Reset Pad, From Power-Up
01234567891011121314151617181920212223por_nresetn_aonpll_lockedon_pllresetn_sysresetn_corefetchpower-onPLL lockedPLL in usebus out of resetcore, first fetch
Scroll horizontally ↔

Recorded on ap_soc v1.5 by a probe beside an Icarus 12 build of soc_tb. Sampled every 20 ns from 1 ns.

Before You Start

Read The Bench in One Picture first. Clock and reset design itself is the subject of Reset Architecture in SoC Architecture; here you only test it from outside.

Five questions this page answers
Question
1What does a chip bench drive, and what does the chip make for itself?
2Why must two unrelated clocks be modelled as unrelated?
3In what order does ap_soc release its resets, and why that order?
4What does a strap do, and when is it read?
5Why does soc_tb move every pad at an even time?

The Idea: The Board Gives Three Things

A board gives a chip a reference clock, a supply and a reset pin. A few strap pins carry choices made before boot. Everything else is the chip's own work. Its oscillators and PLL make the internal clocks, and its reset controller decides when each part may run. So that is what a chip test must check.

What the Board Gives, What the Chip MakesThe bench drives the four inputs on the left. Everything on the right is the chip's own work, and so it is under test.
  • Clock / reset
  • Pads
  • Processor
  • Clock
  • Reset
  • Control
What the Board Gives, What the Chip MakesThe bench drives the four inputs on the left. Everything on the right is the chip's own work, and so it is under test. clock reset CLK pad board, 50 MHz clock reset RST_N and supply board pads BOOT strap board clock reset Oscillators, PLL,mux clk_sys, clk_aon clock reset Reset controller POR cell, sources,order processor Bus, then core first fetch at thereset vector referencepin, powerclk_sysresetn_sys,resetn_coresampled at reset
  1. clock reset CLK padboard, 50 MHz
    • reference → Oscillators, PLL, mux
  2. clock reset RST_N and supplyboard
    • pin, power → Reset controller
  3. pads BOOT strapboard
    • sampled at reset → Bus, then core
  4. clock reset Oscillators, PLL, muxclk_sys, clk_aon
    • clk_sys → Bus, then core
  5. clock reset Reset controllerPOR cell, sources, order
    • resetn_sys, resetn_core → Bus, then core
  6. processor Bus, then corefirst fetch at the reset vector
  1. The board

    Four inputs: the reference clock, the reset pin, the supply and the strap.

  2. The chip

    The chip makes its clocks and releases its resets in order. A bench that drove these would skip them.

Read the diagram as text
  • CLK pad: board, 50 MHz
  • RST_N and supply: board
  • BOOT strap: board
  • Oscillators, PLL, mux: clk_sys, clk_aon
  • Reset controller: POR cell, sources, order
  • Bus, then core: first fetch at the reset vector
  • CLK pad → Oscillators, PLL, mux: reference
  • RST_N and supply → Reset controller: pin, power
  • Oscillators, PLL, mux → Bus, then core: clk_sys
  • Reset controller → Bus, then core: resetn_sys, resetn_core
  • BOOT strap → Bus, then core: sampled at reset

ap_crg and the analog models of ap_soc v1.5 (facts 27.11).

If the bench drove clk_sys or resetn_core itself, it would test a chip with a perfect clock and reset controller. That chip does not exist. The bench drives the pads, and lets the chip get the rest right or wrong.

New Words

New words on this page
WordMeaning
Reference clockThe clock the board gives the chip; on ap_soc the CLK pad, 50 MHz.
Power-on resetA reset the chip makes itself when its supply comes up; ap_soc's cell holds it from 1 ns to 13 ns.
Power-goodA signal saying the supply is up and steady.
Warm resetA reset with the power on: from the reset pin, the watchdog or software. SRAM keeps its contents.
Release orderThe sequence in which resets let go: always-on logic, then the bus, then the core.
StrapA pin the chip samples once to choose a mode. ap_soc samples its BOOT strap after power-up, when the PLL has locked; it chooses where the first instruction comes from.
Unrelated clocksTwo clocks from separate sources, with no fixed phase between them.

The Smallest Example: Two Unrelated Clocks

The board's CLK has a period of 20 ns and rises at 5 ns. The chip's always-on clock, from its own oscillator, has a period of 14 ns and rises at 7 ns. Work out where the first slow edges land, measured from the last CLK edge before them.

Slow edges, by hand
Slow edgeTimeLast CLK edgePhase
17 ns52 ns
221 ns516 ns
335 ns2510 ns
8105 ns1050 ns

CLK rises at 5, 25, 45, 65, 85, 105 ns; the slow clock at 7 + 14k.

The phase walks through every even value and comes back after 140 ns, the least common multiple of 20 and 14. At 105 ns the two edges coincide. Unrelated clocks do that: they meet at every phase, including the same instant, so logic between them must work at every phase. The example below prints the full walk.

The Rules

  1. Rule 1: Drive the reference clock, the supply, the reset pad and the straps; nothing inside.

    The chip makes its own clocks and resets, and that is part of what is under test.

  2. Rule 2: Model unrelated clocks as unrelated.

    Separate generators with their own periods and offsets, never one derived from the other.

  3. Rule 3: Put every bench pad change off every clock edge.

    soc_tb's clock edges are at odd times and its pads move at even times. So two simulators agree on the order of events.

  4. Rule 4: Check the release order, not just the end state.

    ap_soc releases the bus 4 cycles of clk_aon after the cause has gone. The core follows 2 cycles of clk_aon (28 ns) later. Each release then passes through flip-flops on clk_sys, so the lab sees 30 ns.

  5. Rule 5: Set straps before the chip samples them, and keep them steady.

    ap_soc samples BOOT once after power-up, when the PLL has locked, and keeps it through every warm reset. A strap that moves near that moment gives a mode nobody chose.

Sources for These Rules

The board of soc_tb and the even-time rule: tools/soc/ap_soc/bench/soc_tb/README.md and soc_tb.sv; facts 27.12.

Clocks, the power-on reset cell, the release order and the reset vector by strap: facts 27.1 and 27.11 (ap_crg.sv).

Why two simulators can order same-time events differently: IEEE 1800-2023 clause 4 (scheduling semantics). It leaves the order of events in one region open.

The Lab: Power-Up, a Pin Reset, Two Straps

An Icarus build of soc_tb ran with a probe beside it that only reads. The program prints STRAPS and RESET_CAUSE, then asks the board to pull the reset pin. After the second boot it prints them again and passes.

The first nanoseconds: the board's CLK, the chip's always-on clock, the power-on reset cell.
CHANGE t=1 por_n=0
CHANGE t=1 resetn_aon=0
CHANGE t=5 CLK=1
CHANGE t=7 clk_aon=1
CHANGE t=13 por_n=1
CHANGE t=21 clk_aon=1
CHANGE t=25 CLK=1
CHANGE t=35 CLK=0
CHANGE t=35 clk_aon=1
CHANGE t=35 resetn_aon=1

Rule 1 at work: the bench drove CLK (rising at 5 and 25 ns) and nothing else. The chip made the rest. Its power-on reset cell went low at 1 ns and let go at 13 ns. Its own oscillator gave clk_aon, rising at 7 and 21 ns, and the always-on reset let go at 35 ns.

Then the switch to the PLL and the release order.
CHANGE t=165 pll_locked=1
CHANGE t=260 on_pll=1
CHANGE t=375 resetn_sys=1
CHANGE t=405 resetn_core=1
CHANGE t=5485 resetn_sys=1
CHANGE t=5515 resetn_core=1
FETCH t=425 addr=00000000

The PLL locked at 165 ns and the clock mux moved clk_sys onto it at 260 ns. Only then did the bus leave reset, at 375 ns, and the core 30 ns after it, at 405 ns: rule 4. The first fetch went to address 0, the reset vector for BOOT = 0.

The pin reset the program asked for.
WARM t=5168 RST_N=0
WARM t=5229 resetn_sys=0
WARM t=5229 resetn_core=0
WARM t=5368 RST_N=1
WARM t=5485 resetn_sys=1
WARM t=5515 resetn_core=1

The board pulled RST_N at 5168 ns; the resets fell 61 ns later, after the pin's synchronizer. It let go at 5368 ns. The bus came back at 5485 ns and the core 30 ns after it: the same order as at power-up.

Both straps: what firmware read, and where the first fetch went.
BOOT=0: straps=00000000 reset_cause=00000001
BOOT=0: straps=00000000 reset_cause=00000003
BOOT=1: straps=00000001 reset_cause=00000001
BOOT=1: straps=00000001 reset_cause=00000003
BOOT=0: FETCH t=425 addr=00000000
BOOT=1: FETCH t=425 addr=80000000

Rule 5 at work: with BOOT tied to 1 the chip read STRAPS = 1 and fetched from 0x8000_0000, SRAM. After the pin reset it fetched from SRAM again. The chip did not read the pad again: it kept the value it sampled at power-up. RESET_CAUSE reads 1 after power-on and 3 after the pin reset. The power-on bit stays set, and the pin bit joins it.

Why It Is Built This Way

Why put the core after the bus? Because the core's first act is a fetch over that bus. Released together, the two race; released in order, the bus is always ready first. A test that checks only "both resets are high by 1 µs" passes either way and misses the race.

Why odd and even times? Two events at the same simulated instant run in an order the standard does not fix. A bench whose pads move on clock edges can pass on one simulator and fail on another. soc_tb avoids the question: no pad ever moves on an edge.

Traps

The first trap is a bench that derives one clock from another. Someone writes the always-on clock as CLK divided by two to save a line. Now the two clocks have a fixed phase. Every crossing between them is tested at one phase only, and a synchronizer bug can hide for the whole project.

The second is a strap set at the wrong moment. Chips differ here. Many sample their straps when the reset pin lets go, but ap_soc samples BOOT once, after power-up, when its PLL locks. A bench that sets BOOT just before releasing RST_N has already missed that moment, and the chip boots from ROM. The log blames the program, so read the chip's own rule before you write the bench.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. ap_soc has one reference clock, an always-on oscillator and one strap.

  1. Many clocks

    A large SoC has tens of clock domains and several reference inputs. The bench models each board clock with its own frequency, often with jitter and a frequency offset.

  2. Reset sequences as a test plan

    Every reset source, cold and warm, and every order of overlapping causes becomes a row of the plan. Module V9 tests them.

  3. Straps by the dozen

    Boot device, debug enable, test modes: each strap value is a separate boot to verify.

Try It

Run it: each slow edge prints how long after the last CLK edge it landed.

Find the edge where the phase is 0. Both clocks rise at the same instant there.

Change the slow period to 20. What do you lose, and why would that hide a crossing bug?

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: slow edge 1 at 7 ns: 2 ns after the last CLK edge slow edge 2 at 21 ns: 16 ns after the last CLK edge slow edge 3 at 35 ns: 10 ns after the last CLK edge slow edge 4 at 49 ns: 4 ns after the last CLK edge slow edge 5 at 63 ns: 18 ns after the last CLK edge slow edge 6 at 77 ns: 12 ns after the last CLK edge slow edge 7 at 91 ns: 6 ns after the last CLK edge slow edge 8 at 105 ns: 0 ns after the last CLK edge slow edge 9 at 119 ns: 14 ns after the last CLK edge slow edge 10 at 133 ns: 8 ns after the last CLK edge slow edge 11 at 147 ns: 2 ns after the last CLK edge

Check Yourself

Predict the outputThe fast clock is now clk_sys: period 10 ns, first edge at 5. The slow one is unchanged. What is the last line printed?
`timescale 1ns/1ns
// CLK of the board (period 10 ns, first rising edge at 5) and an unrelated clock (period 14 ns, first at 7).
module tb;
  logic clk = 0, aon = 0;
  int last_clk = 0, n = 0;
  initial begin #5; forever begin clk = 1; #5; clk = 0; #5; end end
  initial begin #7; forever begin aon = 1; #7; aon = 0; #7; end end
  always @(posedge clk) last_clk = $time;
  // Sampled a little after each slow edge, so a CLK edge at the same instant is already counted.
  always @(posedge aon) begin
    #1;
    n++;
    $display("slow edge %0d at %0t ns: %0d ns after the last CLK edge", n, $time - 1, $time - 1 - last_clk);
    if (n == 6) $finish;
  end
endmodule
ConceptWhich of these does soc_tb drive?
ConceptIn the recorded power-up, why does the bus leave reset before the core?
ConceptAfter a pin reset with BOOT = 1, where did the first fetch go?
ConceptWhy does soc_tb move every pad at an even time?

Common Mistakes

Wrong Drive the chip's internal clock and reset from the bench.

The test then skips the chip's own clock and reset controller, which is part of what must be verified.

Fix Drive the reference clock, the supply, the reset pad and the straps.

Wrong Make the slow clock by dividing the fast one.

The two clocks get a fixed phase, so every crossing is tested at one phase only.

Fix Give each clock its own generator, period and offset.

Wrong Check only that every reset is released by some time.

A wrong order passes that check and races at the first fetch.

Fix Check the release order and the distance between releases.

Remember

  • The bench drives the reference clock, the supply, the reset pad and the straps; the chip makes its own clocks and resets.
  • Unrelated clocks meet at every phase; model them with separate generators.
  • ap_soc releases the always-on logic, then the bus, then the core; a warm reset repeats the same order.
  • Pads move off clock edges, and straps are steady before the chip samples them; ap_soc samples BOOT once, after power-up.

Practice

Report a problem with this page