A First Peripheral Test: UART End to End

A peripheral test at chip level proves the path, not the block: clock, pin mux, pads, the outside world and back. Write the UART's first end-to-end test, and decide who checks which half: the bench at the pads, or the C test inside.

You Will Be Able To

  • List every part of the chip a UART byte crosses on its way out and back.
  • Split the checks of a peripheral test between the bench and the C test.
  • Read who caught a fault: a bench check, a fail code, or nobody.
  • Explain why a chip-level UART test does not redo the UART's block tests.
Lesson
V4.6
Time
26 min
Runs on
Your browser
Check
5 questions

The UART passed its block bench with every divider, parity and framing case. On the first chip build, no character reaches the lab's terminal. The UART is fine. Something on the way to the pad is not.

A Byte's Path Through the Chip and BackStep through the path of one byte out and back. Each end has its own checker.
  • External
  • Peripheral
  • Pads
  • Debug
  • Processor
  • Clock
  • Data
A Byte's Path Through the Chip and BackStep through the path of one byte out and back. Each end has its own checker. external CLK_GATE bit 0 UART0's clock inap_sysctl peripheral UART0transmitter TXDATA, DIV = 8 pads Pin mux, pad IO0 PINMUX value 2 debug Bench UART model checks what left thechip pads Pad IO1, pin mux PINMUX value 2 peripheral UART0 receiver RX_READY, RXDATA processor C test checks what came in clockframelineanswerframeload
  1. external CLK_GATE bit 0UART0's clock in ap_sysctl
    • clock → UART0 transmitter
  2. peripheral UART0 transmitterTXDATA, DIV = 8
    • frame → Pin mux, pad IO0
  3. pads Pin mux, pad IO0PINMUX value 2
    • line → Bench UART model
  4. debug Bench UART modelchecks what left the chip
    • answer → Pad IO1, pin mux
  5. pads Pad IO1, pin muxPINMUX value 2
    • frame → UART0 receiver
  6. peripheral UART0 receiverRX_READY, RXDATA
    • load → C test
  7. processor C testchecks what came in
  1. Out

    The C test writes TXDATA. With its clock on and the pin mux set, UART0 sends a frame out of pad IO0.

  2. The bench checks

    Only the bench sees the pad: its UART model reads each frame and compares the byte.

  3. Back

    The bench sends its answer on pad IO1; the receiver raises RX_READY.

  4. The C test checks

    Only the firmware knows what it expected back: it compares and reports a code.

Read the diagram as text
  • CLK_GATE bit 0: UART0's clock in ap_sysctl
  • UART0 transmitter: TXDATA, DIV = 8
  • Pin mux, pad IO0: PINMUX value 2
  • Bench UART model: checks what left the chip
  • Pad IO1, pin mux: PINMUX value 2
  • UART0 receiver: RX_READY, RXDATA
  • C test: checks what came in
  • CLK_GATE bit 0 → UART0 transmitter: clock
  • UART0 transmitter → Pin mux, pad IO0: frame
  • Pin mux, pad IO0 → Bench UART model: line
  • Bench UART model → Pad IO1, pin mux: answer
  • Pad IO1, pin mux → UART0 receiver: frame
  • UART0 receiver → C test: load

ap_soc v1.5: UART0 at 0x1000_0000, pads IO0 and IO1, the bench's UART at 8 cycles a bit.

Before You Start

Read Serial Peripherals and Printing Without Paying for a UART first.

Five questions this page answers
Question
1Why does a chip need its own UART test when the UART passed its block bench?
2Which parts of the chip does one byte cross?
3Who can check a byte that left the chip, and who a byte that came in?
4What does each side catch, and what does it miss?
5Why must every wait in such a test have a limit?

The Idea: The Path Is the Test

A block bench proved the UART against its own specification. It cannot see the wires around it. Those are the clock gate that feeds it, the pin mux that gives it pads, and the pads themselves. Those are the chip's, and the chip-level test is about them.

So the test sends a few bytes out and takes a few back. It does not try every divider; one rate that matches the bench is enough. Each byte proves the path: the clock is on, the mux is right, the pad drives, the receiver sees the line.

The two directions have different referees. A byte that left the chip is visible only at the pad, so the bench checks it. A byte that came in is visible only to the firmware, so the C test checks it and reports a code.

New Words

New words on this page
WordMeaning
End-to-end testA test that drives a function from one edge of the chip to the other and checks the result there.
RefereeThe part of the test that decides pass or fail for one check: the bench or the C test.
UART modelBench code on the pads that reads and sends UART frames at a fixed bit time.
Pin muxPINMUX in ap_sysctl: two bits a pad that choose which block drives it.
Clock gateCLK_GATE in ap_sysctl: one bit a block that lets its clock run.
Time limitA bound on a wait, after which the test fails with its own code.

The Smallest Example: Sort the Checks

Who can check what
CheckVisible toChecked by
The byte on pad IO0 is 0x70Only the padBench (uart_expect row)
The frame has the right bit timeOnly the padBench (its UART model)
The byte that came back is 0x70RXDATA, read by the coreC test
A byte came back at all, in timeRX_READY, read by the coreC test, with a time limit
UART0 needs only its own clock bitA run with other clocks offC test, by how it sets CLK_GATE

From the chip's registers (facts 27.3, 27.5) and the bench manual.

The Rules

  1. Rule 1: Prove the path with a few bytes.

    One rate and a few values; the block bench already proved the rest.

  2. Rule 2: The bench checks what leaves the chip.

    Only it sees the pads; give it the bytes to expect.

  3. Rule 3: The C test checks what comes in.

    Only it knows what it expected; compare and report a code.

  4. Rule 4: Every wait has a limit.

    A byte that never comes must become a fail code, not a hang.

  5. Rule 5: Configure everything the path needs.

    Clock gate, pin mux, divider: each is part of the test, set by the test.

Sources for These Rules

The registers and reset values: docs/soc/ap_soc-facts.md 27.3 (PINMUX, CLK_GATE) and 27.5 (UART0 DIV).

The bench's UART model, uart_expect and uart_send rows: tools/soc/ap_soc/bench/soc_tb/README.md; facts 27.12.

The chip level must not redo a block's insides: plan §2.1. The faults are seeded faults of stage E9 (docs/soc/fault-table.md).

Now Run It: Four Chips, Two Referees

E2E_C: "ping" out, "pong" back, with a time limit.
#include "drivers/uart.h"
#include "tb.h"

static int get(unsigned char *byte)          /* one byte, or 0 after a time limit */
{
    for (unsigned t = 0; t < 3000; t++)
        if (FIELD_GET(UART0_STATUS_RX_READY, reg_read32(UART0_STATUS))) { *byte = reg_read32(UART0_RXDATA); return 1; }
    return 0;
}

int main(void)
{
    static const char out[] = "ping", back[] = "pong";
    reg_write32(SYSCTL_PINMUX, (2u << 0) | (2u << 2));   /* IO0 TX, IO1 RX */
    reg_write32(UART0_DIV, 8);
    tb_event(0x7e2e);                        /* bench: check what I send, then answer */
    for (int i = 0; i < 4; i++) uart_putc(out[i]);
    for (int i = 0; i < 4; i++) {
        unsigned char b;
        if (!get(&b)) { tb_puts("timeout\n"); return 3; }
        if (b != (unsigned char)back[i]) { tb_puts("wrong byte "); tb_put_hex(b); tb_putc('\n'); return 2; }
    }
    tb_puts("e2e ok\n");
    return 0;
}
The bench's rows: wait for the event, check four bytes on the pad, send four back.
tb wait_event 00007e2e 00000000 ffffffff 00000000 0 1
tb uart_expect 00000000 00000000 000000ff 00000070 0 1
tb uart_expect 00000000 00000000 000000ff 00000069 0 1
tb uart_expect 00000000 00000000 000000ff 0000006e 0 1
tb uart_expect 00000000 00000000 000000ff 00000067 0 1
tb uart_send 00000000 00000070 ffffffff 00000000 0 1
tb uart_send 00000000 0000006f ffffffff 00000000 0 1
tb uart_send 00000000 0000006e ffffffff 00000000 0 1
tb uart_send 00000000 00000067 ffffffff 00000000 0 1

The test ran on the good chip and on two chips with one seeded fault each. A fourth run used the good chip with a bench that sends back only three bytes.

Measured on our bench (soc_tb, Verilator 5.052 2026-09-05); the faulty chips are selected at run time on the bench's fault build.
good (the chip as designed):
  EVENT 210: 00007e2e
  CONSOLE 1025: e2e ok
  reason=pass status=0000900d uart_bytes=4
Q026 (The transmitter shifts two data bits per tick):
  EVENT 210: 00007e2e
  BENCH 306: row 1: UART byte = 000000f4, expected 00000070 (mask 000000ff)
  MONITOR uart: frame 0 on tx is 3e8, the byte written was 70
  reason=checker status=00000002 uart_bytes=1
Q027 (The receive FIFO complements each incoming byte):
  EVENT 210: 00007e2e
  CONSOLE 942: wrong byte 0000008f
  reason=status_fail status=bad00002 uart_bytes=4
short bench (the chip as designed; the bench sends back three of the four bytes):
  EVENT 210: 00007e2e
  CONSOLE 33952: timeout
  reason=status_fail status=bad00003 uart_bytes=4

On Q026 the transmitter shifts two bits per tick. The bench's first uart_expect row failed at cycle 306, and its UART monitor said why: rule 2. The C test never knew.

On Q027 every received byte is inverted. The bench saw nothing wrong; the C test compared and failed with code 2: rule 3. In the last run the fourth byte never came. Only the time limit turned that into code 3, after 33995 cycles: rule 4. A chip whose receive flag never rises looks exactly the same.

Why It Is Built This Way

The firmware could loop the UART back on itself and check both halves alone. Then a transmitter and a receiver that are wrong in the same way agree. And the pad is never tested. A model on the pads is an independent checker.

The bench could check both halves, too, by watching RXDATA inside the chip. That is a white-box check: it breaks when the RTL changes and cannot follow the test onto silicon. Splitting the judging between the pad and the firmware keeps each check where it can see.

The Trap: The Test That Waited Politely

A UART test calls uart_getc for each byte it expects. On a chip whose receive flag never rises, it waits until the cycle limit. The report says "cycle limit", the same words as for a slow test, a hung bus or a lost interrupt. Someone then has to work out which.

The other trap is a test that never touches the clock gate. On a chip that wired the UART's clock to another block's bit, everything works while every clock runs. A chip-level test should set what the path needs and turn off what it does not.

At Scale

ap_soc~12 blocks
Phone-class SoChundreds of blocks

This section looks ahead. One UART, one model.

  1. Many instances

    A chip with four UARTs runs the same test on each, because each has its own clock bit, mux field and pads.

  2. Pin sharing

    When pads carry several functions, the test also checks that the UART's pads stay quiet while another function owns them.

  3. Real protocols

    On larger chips the same split holds for SPI, I2C and USB. The bench's model checks the wire; the firmware checks what it received.

Try It

Run the slice: it says who caught each chip.

Which run would nobody catch if the C test had no time limit?

The predict question below gives the runs in another order.

RUNIcarus Verilog · in your browser
Edit the code, then run it
Expected: good: passed Q026: caught by the bench (a check of the pad) Q027: caught by the C test, fail code 2 short bench: caught by the C test, fail code 3

Check Yourself

Predict the outputThe slice now reads the same four runs in another order. What is the last line it prints?
// One C test (send "ping", take "pong" back) on several chips and benches, as the bench ended each run.
// reason: how the run ended; code: the fail code the C test wrote, if any.
module tb;
  localparam int N = 4;
  string chip [N], reason [N];
  int    code [N];
  initial begin
    chip[0] = "Q027"; reason[0] = "status_fail"; code[0] = 2;
    chip[1] = "short bench"; reason[1] = "status_fail"; code[1] = 3;
    chip[2] = "good"; reason[2] = "pass"; code[2] = 36877;
    chip[3] = "Q026"; reason[3] = "checker"; code[3] = 2;
    for (int i = 0; i < N; i++)
      if (reason[i] == "pass") $display("%s: passed", chip[i]);
      else if (reason[i] == "checker") $display("%s: caught by the bench (a check of the pad)", chip[i]);
      else if (reason[i] == "status_fail") $display("%s: caught by the C test, fail code %0d", chip[i], code[i]);
      else $display("%s: not caught, the run ended at a limit (%s)", chip[i], reason[i]);
  end
endmodule
ConceptWhy does a chip need a UART test when the UART passed its block bench?
ConceptOn a chip whose receiver inverts each byte, who catches the fault?
ConceptWithout a time limit, which fault leaves the report saying only "cycle limit"?
ConceptWhy should a UART test switch other blocks' clocks off?

Common Mistakes

Wrong Retest every divider and parity mode at chip level.

The block bench proved them; the chip adds only the path.

Fix Send a few bytes at one rate and prove the path.

Wrong Wait for a received byte with no limit.

A fault becomes a hang that says nothing.

Fix Poll with a limit and fail with a code.

Wrong Loop the UART back on itself in firmware.

Matching faults in both halves agree, and the pad is not tested.

Fix Let the bench's model check the pad.

Remember

  • A chip-level peripheral test proves the path: clock gate, pin mux, pads, the outside world and back.
  • The bench checks what leaves the chip; the C test checks what comes in.
  • The bench caught the transmit fault, the C test the receive fault, and only the time limit caught the missing byte.
  • Every wait has a limit, or a fault becomes a hang.

Practice

Report a problem with this page