From 353e9cc29e20a22f57a5d85280673dfd2c7df216 Mon Sep 17 00:00:00 2001 From: John Hardy Date: Mon, 9 Feb 2026 15:23:37 +1100 Subject: [PATCH 1/2] Add SD SPI CMD13 status response --- docs/tec1g-emulation-review.md | 1 + src/platforms/tec1g/sd-spi.ts | 6 ++++++ tests/platforms/tec1g/sd-spi.test.ts | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/docs/tec1g-emulation-review.md b/docs/tec1g-emulation-review.md index c360f76..f9f23bb 100644 --- a/docs/tec1g-emulation-review.md +++ b/docs/tec1g-emulation-review.md @@ -756,6 +756,7 @@ External add-on emulation. Fully independent of other stages. - [x] CMD58 (READ_OCR): respond with OCR register - [x] CMD17 (READ_SINGLE_BLOCK): respond with data token + 512 bytes from virtual image - [x] CMD24 (WRITE_SINGLE_BLOCK): accept data token + 512 bytes and write into virtual image +- [x] CMD13 (SEND_STATUS): respond with R2 status bytes - [x] Unit tests: full initialization sequence (CMD0 -> CMD8 -> ACMD41 -> CMD58) #### 6C — SD card integration with runtime diff --git a/src/platforms/tec1g/sd-spi.ts b/src/platforms/tec1g/sd-spi.ts index 7fb7591..cb396b0 100644 --- a/src/platforms/tec1g/sd-spi.ts +++ b/src/platforms/tec1g/sd-spi.ts @@ -254,6 +254,12 @@ export class SdSpi { this.delayBytes = 1; break; } + case 13: { + const r1 = this.ready ? 0x00 : 0x01; + this.pendingResponse = [r1, 0x00]; + this.delayBytes = 1; + break; + } case 17: { if (!this.ready) { this.pendingResponse = [0x01]; diff --git a/tests/platforms/tec1g/sd-spi.test.ts b/tests/platforms/tec1g/sd-spi.test.ts index 975081f..8644605 100644 --- a/tests/platforms/tec1g/sd-spi.test.ts +++ b/tests/platforms/tec1g/sd-spi.test.ts @@ -178,4 +178,20 @@ describe('SdSpi', () => { expect(image[1]).toBe(0x34); expect(image[2]).toBe(0x56); }); + + it('responds to CMD13 with status', () => { + const spi = new SdSpi({ csMask: CS_BIT }); + writeSpi(spi, 0x00); + sendCommand(spi, [0x77, 0x00, 0x00, 0x00, 0x00, 0x65]); + readResponseByte(spi); + sendCommand(spi, [0x69, 0x40, 0x00, 0x00, 0x00, 0x77]); + readResponseByte(spi); + sendCommand(spi, [0x77, 0x00, 0x00, 0x00, 0x00, 0x65]); + readResponseByte(spi); + sendCommand(spi, [0x69, 0x40, 0x00, 0x00, 0x00, 0x77]); + readResponseByte(spi); + sendCommand(spi, [0x4d, 0x00, 0x00, 0x00, 0x00, 0xff]); + expect(readResponseByte(spi)).toBe(0x00); + expect(readByte(spi)).toBe(0x00); + }); }); From f12f5bb169157a8108bb129a5a1f9c9263798cdf Mon Sep 17 00:00:00 2001 From: John Hardy Date: Mon, 9 Feb 2026 17:56:28 +1100 Subject: [PATCH 2/2] Test CMD13 idle status --- tests/platforms/tec1g/sd-spi.test.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/platforms/tec1g/sd-spi.test.ts b/tests/platforms/tec1g/sd-spi.test.ts index 8644605..babbc4b 100644 --- a/tests/platforms/tec1g/sd-spi.test.ts +++ b/tests/platforms/tec1g/sd-spi.test.ts @@ -194,4 +194,12 @@ describe('SdSpi', () => { expect(readResponseByte(spi)).toBe(0x00); expect(readByte(spi)).toBe(0x00); }); + + it('returns idle status for CMD13 before init', () => { + const spi = new SdSpi({ csMask: CS_BIT }); + writeSpi(spi, 0x00); + sendCommand(spi, [0x4d, 0x00, 0x00, 0x00, 0x00, 0xff]); + expect(readResponseByte(spi)).toBe(0x01); + expect(readByte(spi)).toBe(0x00); + }); });