V4.4.2 The Byte That Was Not There Yet

MediumDebug20 minap_soc v1.5 · recorded bootReview the topic

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.

The firmware of the recorded run (main.c).
#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.

WhoOperationAddressDataMaskExpectDelayRepeat
tbwait_event0000010100000000ffffffff0000000001
tbuart_send0000000000000041ffffffff0000000001
tbarg0000000000000201ffffffff0000000001
tbwait_event0000010200000000ffffffff0000000001
tbarg0000000000000202ffffffff0000000001
tbuart_send0000000000000042ffffffff0000000001

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

CyclePC (hex)OperationAddress (hex)Data (hex)
2008000026cstore8000fff000000000
20380000274store1000401000000008
2098000027cstore1000001000000008
2168000023cstore1000402800000101
2278000024cload1000402c00000000
2338000024cload1000402c00000000
2398000024cload1000402c00000000
2458000024cload1000402c00000000
2518000024cload1000402c00000000
2578000024cload1000402c00000000
2638000024cload1000402c00000000
2698000024cload1000402c00000000
2758000024cload1000402c00000000
2818000024cload1000402c00000000
2878000024cload1000402c00000000
2938000024cload1000402c00000000
2998000024cload1000402c00000201
30780000294load1000000400000003
313800002a4load1000000c00000041
32480000220load8000034c00000072
33280000230store1000402400000072
33680000220load8000034d0000006f
34480000230store100040240000006f
34880000220load8000034e00000075
35680000230store1000402400000075
36080000220load8000034f0000006e
36880000230store100040240000006e
37280000220load8000035000000064
38080000230store1000402400000064
38480000220load8000035100000020
39280000230store1000402400000020
39680000220load800003520000006f
40480000230store100040240000006f
40880000220load800003530000006b
41680000230store100040240000006b
42080000220load800003540000000a
42880000230store100040240000000a
43280000220load8000035500000000
4458000023cstore1000402800000102
4578000024cload1000402c00000202
464800002d4load1000000400000001
478800002f8load8000fffc80000084
480800002fcload8000fff800000000
48280000300load8000fff400000000
48680000304load8000fff000000000
50480000210store10004020bad00012
Step 1 · The first bad cycle and signal
Step 2 · The cause

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
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000TXDATA7:0datawonot storedThe low byte is the next byte to send. Byte to send.
0x004STATUS0roomroblockTransmit room and receive queue state. The transmitter can take a byte.
0x004STATUS1rx_readyroblockAt least one received byte waits.
0x004STATUS2rx_fullroblockThe receive queue is full.
0x008IRQ_ENABLE0roomrw0x0regsWhich status bits raise interrupt source 1. ROOM raises the request.
0x008IRQ_ENABLE1rx_readyrw0x0regsRX_READY raises the request (new in v1.5).
0x00CRXDATA7:0dataroblockThe oldest received byte. The read removes it from the queue. Received byte.
0x010DIV15:0cyclesrw0x0010regsBit time in clk_sys cycles (new in v1.5). clk_sys cycles a bit.
ap_sysctl · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000CHIP_ID31:0valuero0x2A5310C5constThe chip's identity: the IDCODE of the TAP. Fixed number.
0x004RESET_CAUSE0power_onroblockSticky record of reset sources since power-on. Power-on reset.
0x004RESET_CAUSE1pinroblockReset pin.
0x004RESET_CAUSE2watchdogroblockWatchdog.
0x004RESET_CAUSE3softwareroblockSoftware request.
0x004RESET_CAUSE4debugroblockDebug request.
0x008SOFT_RESET0timerwonot storedReset requests from software. 1 arms one restart of the timer.
0x008SOFT_RESET1chipwonot stored1 requests the software reset (new in v1.5).
0x00CSTRAPS0bootroblockStraps as sampled at power-up (new in v1.5). 0: start in the boot ROM. 1: start in SRAM.
0x010PINMUX31:0selectrw0x00000000regsTwo bits for each of sixteen pads: 0 released, 1 GPIO, 2 serial, 3 auxiliary. Pad n uses bits 2n+1 and 2n.
0x014CLK_GATE0uart0rw0x1regs1 lets that block's clock run (new in v1.5). UART0.
0x014CLK_GATE1gpiorw0x1regsGPIO.
0x014CLK_GATE2timerrw0x1regsTimer and PWM.
0x014CLK_GATE3spirw0x1regsSPI.
0x014CLK_GATE4dmarw0x1regsDMA.
0x018LOCK0pinmuxw1s0x0regsWrite-once locks. Only a reset clears one (new in v1.5). 1: PINMUX ignores writes.
0x018LOCK1clk_gatew1s0x0regs1: CLK_GATE ignores writes.
0x018LOCK2debugw1s0x0regs1: the debug lock is closed.
0x020TB_STATUS31:0valuerw0x00000000regs (power-on reset only)Scratch word 0. The firmware kit reports progress, pass and fail here. Plain storage.
0x024TB_PUTC31:0valuerw0x00000000regs (power-on reset only)Scratch word 1. The firmware kit writes one character here. Plain storage.
0x028TB_EVENT31:0valuerw0x00000000regs (power-on reset only)Scratch word 2. The firmware kit writes an event number here. Plain storage.
0x02CTB_ARG31:0valuerw0x00000000regs (power-on reset only)Scratch word 3. A bench leaves a word for the firmware here. Plain storage.