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
#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;
}
| Pad | Select 2 (serial) |
|---|---|
| IO2 | SPI clock (out) |
| IO3 | SPI data in (in) |
| IO4 | SPI data out (out) |
| IO5 | SPI 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
| Cycle | PC (hex) | Operation | Address (hex) | Data (hex) |
|---|---|---|---|---|
| 183 | 8000007c | store | 10004020 | 00000002 |
| 189 | 80000274 | load | 10004010 | 00000000 |
| 202 | 8000028c | store | 10004010 | 00000008 |
| 204 | 80000290 | load | 10004010 | 00000008 |
| 209 | 8000029c | store | 10004010 | 00000010 |
| 211 | 800002a0 | load | 10004010 | 00000010 |
| 216 | 800002ac | store | 10004010 | 00000020 |
| 218 | 800002b0 | load | 10004010 | 00000020 |
| 223 | 800002bc | store | 10004010 | 00000040 |
| 227 | 800002c8 | load | 10005004 | 00000000 |
| 233 | 800002d8 | store | 10005004 | 00000002 |
| 237 | 800002e4 | store | 10005000 | 0000009f |
| 240 | 800002ec | load | 10005004 | 00000001 |
| 247 | 800002ec | load | 10005004 | 00000001 |
| 254 | 800002ec | load | 10005004 | 00000001 |
| 261 | 800002ec | load | 10005004 | 00000001 |
| 268 | 800002ec | load | 10005004 | 00000001 |
| 275 | 800002ec | load | 10005004 | 00000001 |
| 282 | 800002ec | load | 10005004 | 00000001 |
| 289 | 800002ec | load | 10005004 | 00000001 |
| 296 | 800002ec | load | 10005004 | 00000001 |
| 303 | 800002ec | load | 10005004 | 00000001 |
| 310 | 800002ec | load | 10005004 | 00000001 |
| 317 | 800002ec | load | 10005004 | 00000001 |
| 324 | 800002ec | load | 10005004 | 00000001 |
| 331 | 800002ec | load | 10005004 | 00000001 |
| 338 | 800002ec | load | 10005004 | 00000001 |
| 345 | 800002ec | load | 10005004 | 00000001 |
| 352 | 800002ec | load | 10005004 | 00000001 |
| 359 | 800002ec | load | 10005004 | 00000001 |
| 366 | 800002ec | load | 10005004 | 00000002 |
| 372 | 800002fc | load | 10005000 | 00000000 |
| 389 | 80000230 | store | 10004024 | 00000066 |
| 401 | 80000230 | store | 10004024 | 0000006c |
| 413 | 80000230 | store | 10004024 | 00000061 |
| 425 | 80000230 | store | 10004024 | 00000073 |
| 437 | 80000230 | store | 10004024 | 00000068 |
| 449 | 80000230 | store | 10004024 | 00000020 |
| 477 | 80000264 | store | 10004024 | 00000030 |
| 489 | 80000264 | store | 10004024 | 00000030 |
| 501 | 80000264 | store | 10004024 | 00000030 |
| 513 | 80000264 | store | 10004024 | 00000030 |
| 525 | 80000264 | store | 10004024 | 00000030 |
| 537 | 80000264 | store | 10004024 | 00000030 |
| 549 | 80000264 | store | 10004024 | 00000030 |
| 561 | 80000264 | store | 10004024 | 00000030 |
| 582 | 80000230 | store | 10004024 | 0000000a |
| 621 | 80000210 | store | 10004020 | bad00003 |
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
| 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. |
SPI · register manual
| Offset | Register | Bits | Field | Access | Reset | Held by | Meaning |
|---|---|---|---|---|---|---|---|
0x000 | DATA | 7:0 | command | wo | not stored | Write: a command byte; the write starts a frame of 32 serial clocks. Read: the last 24 bits received. Command byte. | |
0x000 | DATA | 23:0 | received | ro | block | Last 24 bits received. | |
0x004 | STATUS | 0 | busy | ro | block | Frame state. A frame is running, and chip select is low. | |
0x004 | STATUS | 1 | done | w1c | block | A frame has ended (new in v1.5). | |
0x008 | IRQ_ENABLE | 0 | done | rw | 0x0 | regs | Lets DONE raise interrupt source 4 (new in v1.5). 1 enables the request. |
## SPI (base 0x1000_5000, interrupt source 4, clk_sys, PD_PER) | Offset | Register | Bits | Field | Access | Reset | Held by | Meaning | | --- | --- | --- | --- | --- | --- | --- | --- | | `0x000` | DATA | 7:0 | command | wo | | not stored | Write: a command byte; the write starts a frame of 32 serial clocks. Read: the last 24 bits received. Command byte. | | `0x000` | DATA | 23:0 | received | ro | | block | Last 24 bits received. | | `0x004` | STATUS | 0 | busy | ro | | block | Frame state. A frame is running, and chip select is low. | | `0x004` | STATUS | 1 | done | w1c | | block | A frame has ended (new in v1.5). | | `0x008` | IRQ_ENABLE | 0 | done | rw | `0x0` | regs | Lets DONE raise interrupt source 4 (new in v1.5). 1 enables the request. |