Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/tec1g-emulation-review.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/platforms/tec1g/sd-spi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
24 changes: 24 additions & 0 deletions tests/platforms/tec1g/sd-spi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,28 @@ 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);
});

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);
});
});
Loading