On 4/11/26 13:31, Manuele Conti wrote:
When a write start token immediately follows the R1 response,
the SPI SD controller may still be in SSI_SD_RESPONSE state
and discard the token.
Recognize single-block and multi-block write start tokens
when the SD card is ready to receive data, allowing the
write operation to proceed without an additional dummy byte.
Signed-off-by: Manuele Conti <[email protected]>
hw/sd/ssi-sd.c | 6 +
tests/qtest/ssi-sd-token-local-test.c | 165 ++++++++++++++++++++++++++
2 files changed, 171 insertions(+)
create mode 100644 tests/qtest/ssi-sd-token-local-test.c
diff --git a/hw/sd/ssi-sd.c b/hw/sd/ssi-sd.c
index a3a9f0c7efd..13c87c49cfb 100644
--- a/hw/sd/ssi-sd.c
+++ b/hw/sd/ssi-sd.c
@@ -185,6 +185,12 @@ static uint32_t ssi_sd_transfer(SSIPeripheral *dev,
uint32_t val)
s->mode = SSI_SD_CMD;
return SSI_DUMMY;
}
+ /* The next byte after R1 may already be the write start token. */
+ if (sdbus_receive_ready(&s->sdbus) &&
+ (val == SSI_TOKEN_SINGLE || val == SSI_TOKEN_MULTI_WRITE)) {
+ s->mode = SSI_SD_DATA_WRITE;
+ return SSI_DUMMY;
IIUC this does not check that the token type matches the command
(0xFC for CMD25, 0xFE for CMD24), and accepts a zero-gap 0xFC
right after a CMD25 data response. Is that deliberate? (I don't
think, but if so this should be mentioned in commit description).
+ }
if (sdbus_data_ready(&s->sdbus)) {
DPRINTF("Data read\n");
s->mode = SSI_SD_DATA_START;