Skip to the content.

E18 — SD first read after init

   
ID E18
Date 2026-12-02
Status done (cause still open)
Decisions D96 (DECISIONS.md)
Board #1 (rev A), 29.8 GB SDHC card (read-only test)
Firmware + results fw/tests/2026-12-02-12-ramloops-v5f-156mhz (sources, six SD variant binaries, results.txt)
Scripts sdfirst.py

Summary: Without the throw-away read, the first SD read after init misses bytes 0–3 whenever the code is slow (from flash, or from RAM at HCLK 48 MHz); from RAM at 96 MHz it never does. RST_LGC and the CMD6 fix are not the cause; the throw-away read stays.

What

B2/D75 found the first DMA transfer after sd_init leaves bytes 0–3 (and then 0x1F0–0x1FF) unwritten, hidden since by a throw-away read. D86 (RST_LGC) and D91 (CMD6 stray transfer) were candidate fixes. sdinit 0 now skips the throw-away read; sdrd pre-fills the buffer with 0xEE so unwritten bytes show; builds vary clock, code location and RST_LGC.

Results

sdinit 0 then sdrd twice, block 0 (MBR) and block 0x800 (FAT boot sector), 5 rounds each = 10 first reads per build (final run, results.txt; an earlier exploratory run gave the same pattern):

build (HCLK, code, RST_LGC before reads) first read wrong
96 MHz, RAM, RST_LGC (default) 0 / 10
96 MHz, RAM, no RST_LGC 0 / 10
96 MHz, flash, no RST_LGC 10 / 10
48 MHz, RAM, no RST_LGC 4 / 10 (exploratory run: 6 / 10)
48 MHz, flash, no RST_LGC (B2 conditions) 10 / 10
48 MHz, flash, RST_LGC 10 / 10

Lesson

A bug that disappears after a speed-up may only be hidden. Bisect the factors before removing a workaround.

Chip facts and numbers: fw/LEARNINGS.md. All experiments: index.