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.
- External
- Peripheral
- Pads
- Debug
- Processor
- Clock
- Data
- Out
The C test writes TXDATA. With its clock on and the pin mux set, UART0 sends a frame out of pad IO0.
- The bench checks
Only the bench sees the pad: its UART model reads each frame and compares the byte.
- Back
The bench sends its answer on pad IO1; the receiver raises RX_READY.
- 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.
| Question | |
|---|---|
| 1 | Why does a chip need its own UART test when the UART passed its block bench? |
| 2 | Which parts of the chip does one byte cross? |
| 3 | Who can check a byte that left the chip, and who a byte that came in? |
| 4 | What does each side catch, and what does it miss? |
| 5 | Why 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
| Word | Meaning |
|---|---|
| End-to-end test | A test that drives a function from one edge of the chip to the other and checks the result there. |
| Referee | The part of the test that decides pass or fail for one check: the bench or the C test. |
| UART model | Bench code on the pads that reads and sends UART frames at a fixed bit time. |
| Pin mux | PINMUX in ap_sysctl: two bits a pad that choose which block drives it. |
| Clock gate | CLK_GATE in ap_sysctl: one bit a block that lets its clock run. |
| Time limit | A bound on a wait, after which the test fails with its own code. |
The Smallest Example: Sort the Checks
| Check | Visible to | Checked by |
|---|---|---|
| The byte on pad IO0 is 0x70 | Only the pad | Bench (uart_expect row) |
| The frame has the right bit time | Only the pad | Bench (its UART model) |
| The byte that came back is 0x70 | RXDATA, read by the core | C test |
| A byte came back at all, in time | RX_READY, read by the core | C test, with a time limit |
| UART0 needs only its own clock bit | A run with other clocks off | C test, by how it sets CLK_GATE |
From the chip's registers (facts 27.3, 27.5) and the bench manual.
The Rules
Rule 1: Prove the path with a few bytes.
One rate and a few values; the block bench already proved the rest.
Rule 2: The bench checks what leaves the chip.
Only it sees the pads; give it the bytes to expect.
Rule 3: The C test checks what comes in.
Only it knows what it expected; compare and report a code.
Rule 4: Every wait has a limit.
A byte that never comes must become a fail code, not a hang.
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
#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;
}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 1The 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.
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=4On 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
This section looks ahead. One UART, one model.
Many instances
A chip with four UARTs runs the same test on each, because each has its own clock bit, mux field and pads.
Pin sharing
When pads carry several functions, the test also checks that the UART's pads stay quiet while another function owns them.
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.
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 3Check Yourself
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.