A UART test asks the bench for two bytes, one hand-shake each. The first round passes; the second fails with code 0x12. Find the transfer where the run first went wrong, and say why.
The firmware routes pad IO1 to the UART receiver and sets DIV to 8. Then it runs two rounds of a hand-shake, one byte each. A round asks with TB_EVENT 0x100 + r and waits for the reply 0x200 + r in TB_ARG. Then it reads UART0 STATUS: no byte ready gives code 0x10 + r.
#include "drivers/uart.h"
#include "tb.h"
int main(void)
{
reg_write32(SYSCTL_PINMUX, 2u << 2); /* pad IO1 carries UART RX */
reg_write32(UART0_DIV, 8);
for (unsigned r = 1; r <= 2; r++) {
tb_event(0x100 + r); /* bench: send byte r */
tb_wait_event(0x200 + r); /* bench: byte r has been sent */
if (!FIELD_GET(UART0_STATUS_RX_READY, reg_read32(UART0_STATUS))) return 0x10 + r; /* no byte */
if (reg_read32(UART0_RXDATA) != 0x40 + r) return 0x20 + r; /* wrong byte */
tb_puts("round ok\n");
}
return 0;
}
The bench's side of the run is a table of rows, run in order. Each row waits for its delay, then acts.
| Who | Operation | Address | Data | Mask | Expect | Delay | Repeat |
|---|---|---|---|---|---|---|---|
| tb | wait_event | 00000101 | 00000000 | ffffffff | 00000000 | 0 | 1 |
| tb | uart_send | 00000000 | 00000041 | ffffffff | 00000000 | 0 | 1 |
| tb | arg | 00000000 | 00000201 | ffffffff | 00000000 | 0 | 1 |
| tb | wait_event | 00000102 | 00000000 | ffffffff | 00000000 | 0 | 1 |
| tb | arg | 00000000 | 00000202 | ffffffff | 00000000 | 0 | 1 |
| tb | uart_send | 00000000 | 00000042 | ffffffff | 00000000 | 0 | 1 |
The trace below shows 46 of 68 retired loads and stores, cycles 200 to 504. Name the first transfer that went wrong: its cycle, the wrong part, its address and its register or variable. Then choose the cause.
Full specification
The register list names every address the answer may use. Addresses are in hex without 0x in the trace; write them with or without 0x in the form.
Data in the trace is the word as the bus carried it. A load's data is what came back; a store's is what was written.
Diagnose the Failing Run
Recorded Console and Result
EVENT 215: 00000101 ARG 298: 00000201 CONSOLE 427: round ok EVENT 444: 00000102 ARG 446: 00000202 verdict=fail reason=status_fail status=bad00012 cycles=535 traps=0 interrupts=0 mismatches=0
Retired Memory Transfers
| Cycle | PC (hex) | Operation | Address (hex) | Data (hex) |
|---|---|---|---|---|
| 200 | 8000026c | store | 8000fff0 | 00000000 |
| 203 | 80000274 | store | 10004010 | 00000008 |
| 209 | 8000027c | store | 10000010 | 00000008 |
| 216 | 8000023c | store | 10004028 | 00000101 |
| 227 | 8000024c | load | 1000402c | 00000000 |
| 233 | 8000024c | load | 1000402c | 00000000 |
| 239 | 8000024c | load | 1000402c | 00000000 |
| 245 | 8000024c | load | 1000402c | 00000000 |
| 251 | 8000024c | load | 1000402c | 00000000 |
| 257 | 8000024c | load | 1000402c | 00000000 |
| 263 | 8000024c | load | 1000402c | 00000000 |
| 269 | 8000024c | load | 1000402c | 00000000 |
| 275 | 8000024c | load | 1000402c | 00000000 |
| 281 | 8000024c | load | 1000402c | 00000000 |
| 287 | 8000024c | load | 1000402c | 00000000 |
| 293 | 8000024c | load | 1000402c | 00000000 |
| 299 | 8000024c | load | 1000402c | 00000201 |
| 307 | 80000294 | load | 10000004 | 00000003 |
| 313 | 800002a4 | load | 1000000c | 00000041 |
| 324 | 80000220 | load | 8000034c | 00000072 |
| 332 | 80000230 | store | 10004024 | 00000072 |
| 336 | 80000220 | load | 8000034d | 0000006f |
| 344 | 80000230 | store | 10004024 | 0000006f |
| 348 | 80000220 | load | 8000034e | 00000075 |
| 356 | 80000230 | store | 10004024 | 00000075 |
| 360 | 80000220 | load | 8000034f | 0000006e |
| 368 | 80000230 | store | 10004024 | 0000006e |
| 372 | 80000220 | load | 80000350 | 00000064 |
| 380 | 80000230 | store | 10004024 | 00000064 |
| 384 | 80000220 | load | 80000351 | 00000020 |
| 392 | 80000230 | store | 10004024 | 00000020 |
| 396 | 80000220 | load | 80000352 | 0000006f |
| 404 | 80000230 | store | 10004024 | 0000006f |
| 408 | 80000220 | load | 80000353 | 0000006b |
| 416 | 80000230 | store | 10004024 | 0000006b |
| 420 | 80000220 | load | 80000354 | 0000000a |
| 428 | 80000230 | store | 10004024 | 0000000a |
| 432 | 80000220 | load | 80000355 | 00000000 |
| 445 | 8000023c | store | 10004028 | 00000102 |
| 457 | 8000024c | load | 1000402c | 00000202 |
| 464 | 800002d4 | load | 10000004 | 00000001 |
| 478 | 800002f8 | load | 8000fffc | 80000084 |
| 480 | 800002fc | load | 8000fff8 | 00000000 |
| 482 | 80000300 | load | 8000fff4 | 00000000 |
| 486 | 80000304 | load | 8000fff0 | 00000000 |
| 504 | 80000210 | store | 10004020 | bad00012 |
Given Files
Use the register map to identify the transfer in the recording.
tb.h
#ifndef AP_TB_H
#define AP_TB_H
_Noreturn void tb_pass(void);
_Noreturn void tb_fail(unsigned code);
void tb_putc(char byte);
void tb_puts(const char *text);
void tb_put_hex(unsigned value);
void tb_event(unsigned id);
/* Slot zero is the single bench-to-firmware argument word. */
unsigned tb_arg(unsigned n);
void tb_wait_event(unsigned id);
#endif
drivers/uart.h
#ifndef AP_UART_H
#define AP_UART_H
#include "hal.h"
static inline void uart_flush(void)
{
while (!FIELD_GET(UART0_STATUS_ROOM, reg_read32(UART0_STATUS))) { }
}
static inline void uart_putc(unsigned char byte)
{
uart_flush();
reg_write32(UART0_TXDATA, byte);
}
static inline unsigned char uart_getc(void)
{
while (!FIELD_GET(UART0_STATUS_RX_READY, reg_read32(UART0_STATUS))) { }
return reg_read32(UART0_RXDATA);
}
static inline void uart_enable_rx_irq(void)
{
reg_write32(UART0_IRQ_ENABLE, UART0_IRQ_ENABLE_RX_READY_MASK);
}
#endif
UART0 · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | TXDATA | 7:0 | data | wo | not stored | The low byte is the next byte to send. Byte to send. | |
0x004 | STATUS | 0 | room | ro | block | Transmit room and receive queue state. The transmitter can take a byte. | |
0x004 | STATUS | 1 | rx_ready | ro | block | At least one received byte waits. | |
0x004 | STATUS | 2 | rx_full | ro | block | The receive queue is full. | |
0x008 | IRQ_ENABLE | 0 | room | rw | 0x0 | regs | Which status bits raise interrupt source 1. ROOM raises the request. |
0x008 | IRQ_ENABLE | 1 | rx_ready | rw | 0x0 | regs | RX_READY raises the request (new in v1.5). |
0x00C | RXDATA | 7:0 | data | ro | block | The oldest received byte. The read removes it from the queue. Received byte. | |
0x010 | DIV | 15:0 | cycles | rw | 0x0010 | regs | Bit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit. |
## UART0 (base 0x1000_0000, interrupt source 1, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | TXDATA | 7:0 | data | wo | | not stored | The low byte is the next byte to send. Byte to send. | | `0x004` | STATUS | 0 | room | ro | | block | Transmit room and receive queue state. The transmitter can take a byte. | | `0x004` | STATUS | 1 | rx_ready | ro | | block | At least one received byte waits. | | `0x004` | STATUS | 2 | rx_full | ro | | block | The receive queue is full. | | `0x008` | IRQ_ENABLE | 0 | room | rw | `0x0` | regs | Which status bits raise interrupt source 1. ROOM raises the request. | | `0x008` | IRQ_ENABLE | 1 | rx_ready | rw | `0x0` | regs | RX_READY raises the request (new in v1.5). | | `0x00C` | RXDATA | 7:0 | data | ro | | block | The oldest received byte. The read removes it from the queue. Received byte. | | `0x010` | DIV | 15:0 | cycles | rw | `0x0010` | regs | Bit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit. |
ap_sysctl · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | CHIP_ID | 31:0 | value | ro | 0x2A5310C5 | const | The chip's identity: the IDCODE of the TAP. Fixed number. |
0x004 | RESET_CAUSE | 0 | power_on | ro | block | Sticky record of reset sources since power-on. Power-on reset. | |
0x004 | RESET_CAUSE | 1 | pin | ro | block | Reset pin. | |
0x004 | RESET_CAUSE | 2 | watchdog | ro | block | Watchdog. | |
0x004 | RESET_CAUSE | 3 | software | ro | block | Software request. | |
0x004 | RESET_CAUSE | 4 | debug | ro | block | Debug request. | |
0x008 | SOFT_RESET | 0 | timer | wo | not stored | Reset requests from software. 1 arms one restart of the timer. | |
0x008 | SOFT_RESET | 1 | chip | wo | not stored | 1 requests the software reset (new in v1.5). | |
0x00C | STRAPS | 0 | boot | ro | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | |
0x010 | PINMUX | 31:0 | select | rw | 0x00000000 | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. |
0x014 | CLK_GATE | 0 | uart0 | rw | 0x1 | regs | 1 lets that block's clock run (new in v1.5). UART0. |
0x014 | CLK_GATE | 1 | gpio | rw | 0x1 | regs | GPIO. |
0x014 | CLK_GATE | 2 | timer | rw | 0x1 | regs | Timer and PWM. |
0x014 | CLK_GATE | 3 | spi | rw | 0x1 | regs | SPI. |
0x014 | CLK_GATE | 4 | dma | rw | 0x1 | regs | DMA. |
0x018 | LOCK | 0 | pinmux | w1s | 0x0 | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. |
0x018 | LOCK | 1 | clk_gate | w1s | 0x0 | regs | 1: CLK_GATE ignores writes. |
0x018 | LOCK | 2 | debug | w1s | 0x0 | regs | 1: the debug lock is closed. |
0x020 | TB_STATUS | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. |
0x024 | TB_PUTC | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. |
0x028 | TB_EVENT | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. |
0x02C | TB_ARG | 31:0 | value | rw | 0x00000000 | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |
## ap_sysctl (base 0x1000_4000, clk_sys, PD_MAIN) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | CHIP_ID | 31:0 | value | ro | `0x2A5310C5` | const | The chip's identity: the IDCODE of the TAP. Fixed number. | | `0x004` | RESET_CAUSE | 0 | power_on | ro | | block | Sticky record of reset sources since power-on. Power-on reset. | | `0x004` | RESET_CAUSE | 1 | pin | ro | | block | Reset pin. | | `0x004` | RESET_CAUSE | 2 | watchdog | ro | | block | Watchdog. | | `0x004` | RESET_CAUSE | 3 | software | ro | | block | Software request. | | `0x004` | RESET_CAUSE | 4 | debug | ro | | block | Debug request. | | `0x008` | SOFT_RESET | 0 | timer | wo | | not stored | Reset requests from software. 1 arms one restart of the timer. | | `0x008` | SOFT_RESET | 1 | chip | wo | | not stored | 1 requests the software reset (new in v1.5). | | `0x00C` | STRAPS | 0 | boot | ro | | block | Straps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM. | | `0x010` | PINMUX | 31:0 | select | rw | `0x00000000` | regs | Two bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n. | | `0x014` | CLK_GATE | 0 | uart0 | rw | `0x1` | regs | 1 lets that block's clock run (new in v1.5). UART0. | | `0x014` | CLK_GATE | 1 | gpio | rw | `0x1` | regs | GPIO. | | `0x014` | CLK_GATE | 2 | timer | rw | `0x1` | regs | Timer and PWM. | | `0x014` | CLK_GATE | 3 | spi | rw | `0x1` | regs | SPI. | | `0x014` | CLK_GATE | 4 | dma | rw | `0x1` | regs | DMA. | | `0x018` | LOCK | 0 | pinmux | w1s | `0x0` | regs | Write-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes. | | `0x018` | LOCK | 1 | clk_gate | w1s | `0x0` | regs | 1: CLK_GATE ignores writes. | | `0x018` | LOCK | 2 | debug | w1s | `0x0` | regs | 1: the debug lock is closed. | | `0x020` | TB_STATUS | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage. | | `0x024` | TB_PUTC | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 1. The firmware kit writes one character here. Plain storage. | | `0x028` | TB_EVENT | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 2. The firmware kit writes an event number here. Plain storage. | | `0x02C` | TB_ARG | 31:0 | value | rw | `0x00000000` | regs (power-on reset only) | Scratch word 3. A bench leaves a word for the firmware here. Plain storage. |