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 ++++++ 1 file changed, 6 insertions(+) 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; + } if (sdbus_data_ready(&s->sdbus)) { DPRINTF("Data read\n"); s->mode = SSI_SD_DATA_START; -- 2.41.0
