V8.3.2 The Flash That Never Answered

MediumDebug20 minap_soc v1.5 · recorded bootReview the topic

Bring-up firmware routes the SPI flash to its four pads and asks for its ID. The flash answers 0. Find the first transfer that went wrong.

A new SPI flash test runs on ap_soc v1.5, the good chip. It routes the SPI pins with a small helper, sends the ID command 9F, and prints what came back. The console shows flash 00000000, and the run ends with fail code 3.

The flash model on the board answers C0 FF EE to 9F whenever it sees a proper frame on its pads.

The trace below shows 48 of 69 retired loads and stores after main, cycles 183 to 621. Name the transfer that went wrong first: its cycle, the wrong part, its address and its register. Then choose the cause.

Full specification
The program of the recorded run (main.c).
#include "drivers/spi.h"
#include "tb.h"

/* Give pad `pad` the function `sel` of the pin table, and leave the other pads alone. */
static void pinmux_set(unsigned pad, unsigned sel)
{
    unsigned v = reg_read32(SYSCTL_PINMUX);
    v &= ~(3u << pad);
    v |= sel << pad;
    reg_write32(SYSCTL_PINMUX, v);
}

int main(void)
{
    for (unsigned pad = 2; pad <= 5; pad++)
        pinmux_set(pad, 2);                 /* the SPI flash on IO2 to IO5 */
    unsigned id = spi_transfer(0x9f);       /* the flash answers C0 FF EE */
    tb_puts("flash ");
    tb_put_hex(id);
    tb_puts("\n");
    if (id != 0xc0ffee) return 3;
    return 0;
}
PINMUX at 0x1000_4010: two bits a pad. pins.csv of ap_soc v1.5.
PadSelect 2 (serial)
IO2SPI clock (out)
IO3SPI data in (in)
IO4SPI data out (out)
IO5SPI select (out)

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.

Diagnose the Failing Run

Recorded Console and Result

CONSOLE 581: flash 00000000
verdict=fail
reason=status_fail
status=bad00003
cycles=629
traps=0
mismatches=0

Retired Memory Transfers

CyclePC (hex)OperationAddress (hex)Data (hex)
1838000007cstore1000402000000002
18980000274load1000401000000000
2028000028cstore1000401000000008
20480000290load1000401000000008
2098000029cstore1000401000000010
211800002a0load1000401000000010
216800002acstore1000401000000020
218800002b0load1000401000000020
223800002bcstore1000401000000040
227800002c8load1000500400000000
233800002d8store1000500400000002
237800002e4store100050000000009f
240800002ecload1000500400000001
247800002ecload1000500400000001
254800002ecload1000500400000001
261800002ecload1000500400000001
268800002ecload1000500400000001
275800002ecload1000500400000001
282800002ecload1000500400000001
289800002ecload1000500400000001
296800002ecload1000500400000001
303800002ecload1000500400000001
310800002ecload1000500400000001
317800002ecload1000500400000001
324800002ecload1000500400000001
331800002ecload1000500400000001
338800002ecload1000500400000001
345800002ecload1000500400000001
352800002ecload1000500400000001
359800002ecload1000500400000001
366800002ecload1000500400000002
372800002fcload1000500000000000
38980000230store1000402400000066
40180000230store100040240000006c
41380000230store1000402400000061
42580000230store1000402400000073
43780000230store1000402400000068
44980000230store1000402400000020
47780000264store1000402400000030
48980000264store1000402400000030
50180000264store1000402400000030
51380000264store1000402400000030
52580000264store1000402400000030
53780000264store1000402400000030
54980000264store1000402400000030
56180000264store1000402400000030
58280000230store100040240000000a
62180000210store10004020bad00003
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.

drivers/spi.h
#ifndef AP_SPI_H
#define AP_SPI_H
#include "hal.h"

static inline unsigned spi_transfer(unsigned char command)
{
    while (reg_read32(SPI_STATUS) & SPI_STATUS_BUSY_MASK) { }
    reg_write32(SPI_STATUS, SPI_STATUS_DONE_MASK);
    reg_write32(SPI_DATA, command);
    while (!FIELD_GET(SPI_STATUS_DONE, reg_read32(SPI_STATUS))) { }
    return FIELD_GET(SPI_DATA_RECEIVED, reg_read32(SPI_DATA));
}
#endif

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

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.
SPI · register manual
OffsetRegisterBitsFieldAccessResetHeld byMeaning
0x000DATA7:0commandwonot storedWrite: a command byte; the write starts a frame of 32 serial clocks. Read: the last 24 bits received. Command byte.
0x000DATA23:0receivedroblockLast 24 bits received.
0x004STATUS0busyroblockFrame state. A frame is running, and chip select is low.
0x004STATUS1donew1cblockA frame has ended (new in v1.5).
0x008IRQ_ENABLE0donerw0x0regsLets DONE raise interrupt source 4 (new in v1.5). 1 enables the request.