Skip to content

fix(cosim): CS-gate QSPI MISO injection for shared-bus arbitration#183

Merged
robtaylor merged 1 commit into
mainfrom
fix/qspi-shared-bus-din
Jul 9, 2026
Merged

fix(cosim): CS-gate QSPI MISO injection for shared-bus arbitration#183
robtaylor merged 1 commit into
mainfrom
fix/qspi-shared-bus-din

Conversation

@robtaylor

@robtaylor robtaylor commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Problem

Plural QSPI memories can be configured on a shared SCK/SIO bus with distinct CS lines (same clk_gpio/d0_gpio, distinct csn_gpio) — but it never worked. gpu_apply_flash_din (and the CpuBackend mirror) wrote every instance's d_i to its d_in_pos unconditionally, regardless of CS. A deselected flash holds its last d_i (idle 0x0F) and, being iterated last, overwrote the selected flash's MISO on the shared line — last-writer-wins, silently corrupting reads.

Independent-pin plurality (tests/multi_mem_cosim) was fine; only the shared-bus topology was affected.

Fix

CS-gate the MISO injection: a deselected instance (prev_csn high) presents high-Z and does not drive. Mirrored across all backends:

  • CpuBackend::apply_flash_din_gated — extracted as a pure, GPU/netlist-free, unit-testable fn.
  • gpu_apply_flash_din — Metal (kernel_v1.metal) + the shared CUDA/HIP kernel_v1_impl.cuh.

Gating on prev_csn (the delayed CS that produced d_i) keeps the driven value and the selection decision in phase with the existing setup-delay model.

Tests

  • Unit (flash_din_tests): selected drives its lane; deselected is high-Z; shared-bus arbitration is order-independent; xmask cleared only when driven.
  • RTL integration (tests/qspi_shared_bus/): one master, two flashes on a shared bus with distinct CS, reads 0xA1 / 0xB2. Byte-exact golden (CpuBackend, verified byte-identical to Metal) + check.py content assertion, wired into the all + qspi scopes of cosim_cpu_check.sh (gates CpuBackend/Linux + the CUDA/HIP/Metal GPU suites).
  • Negative-verified: with the Metal gate temporarily removed, the fixture FAILS as expected (fa reads 0xFF, clobbered) — the test catches the bug.

Locally: full all cosim scope passes (12 fixtures, no regressions) on both CpuBackend and Metal; --check-with-cpu shows 0 output/SRAM mismatches (the input-state noise is pre-existing, identical on untouched multi_mem).

Also

  • Corrects a stale len() <= 1 doc comment (real cap is MAX_QSPI_MEMS = 4).
  • Amends ADR 0013 (2026-07-09).

Plural QSPI memories may share one SCK/SIO bus selected by distinct CS
lines (same clk_gpio/d0_gpio, distinct csn_gpio). That never worked:
gpu_apply_flash_din (and the CpuBackend mirror) wrote every instance's
d_i to its d_in_pos unconditionally, so a deselected flash — which holds
its last d_i and is often iterated last — clobbered the selected driver's
MISO. Last-writer-wins silently corrupted the shared-bus reads.

Gate the injection on selection: a deselected instance (prev_csn high)
presents high-Z and does not drive. Fix mirrored across all backends —
CpuBackend::apply_flash_din_gated (extracted as a pure, unit-testable fn)
and the gpu_apply_flash_din kernels (Metal + the shared CUDA/HIP
kernel_v1_impl.cuh). Gating on prev_csn (the delayed csn that produced
d_i) keeps the driven value and the selection decision in phase with the
setup-delay model. Independent-pin plurality (multi_mem_cosim) is
unaffected — a deselected flash on its own pins was always ignored.

Tests:
- flash_din_tests unit tests: selected drives, deselected is high-Z,
  shared-bus order-independence, xmask clear-only-when-driven.
- tests/qspi_shared_bus/: RTL fixture — two flashes on a shared bus,
  distinct CS; reads 0xA1 / 0xB2. Golden (CpuBackend, byte-identical to
  Metal/CUDA/HIP) + content check, wired into the all/qspi CI scopes.
  Verified it FAILS without the gate (fa reads 0xFF, clobbered).

Also corrects a stale `len() <= 1` doc comment (real cap is
MAX_QSPI_MEMS = 4) and amends ADR 0013.

Co-developed-by: Claude Code v2.1.203 (claude-opus-4-8[1m])
@robtaylor robtaylor merged commit 346b016 into main Jul 9, 2026
25 checks passed
@robtaylor robtaylor deleted the fix/qspi-shared-bus-din branch July 9, 2026 14:40
@robtaylor robtaylor restored the fix/qspi-shared-bus-din branch July 9, 2026 15:00
@robtaylor robtaylor deleted the fix/qspi-shared-bus-din branch July 9, 2026 15:01
robtaylor added a commit that referenced this pull request Jul 9, 2026
Rename derived-clock-185 → c64-cosim-blockers. The next Jacquard session's
two next steps are #185 (derived clock, in progress on this branch) and
#186 (SRAM macro panic, flatten.rs:1268, unstarted), plus context: #183
merged, #184 video tap ready. Cross-session coordination stays on the
GitHub issues, not in a handoff.

Co-developed-by: Claude Code v2.1.203 (claude-opus-4-8[1m])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant