From c5953bd0e988c7dbdce7430e5f9b5f3df5873581 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 13 Mar 2015 07:26:16 -0600 Subject: [PATCH] Debugging and manuals (this one https://www.sdcard.org/downloads/pls/simplified_specs/part1_410.pdf and this one https://www.sdcard.org/downloads/pls/simplified_specs/part1_410.pdf) shows that ACMD23 must be preceeded with CMD55 command as any other ACMD commands. Also, after the block reading wait loop must be inserted before writing the next block of data to the sd card From Dmitry Nikolaev via Jussi Kivilinna --- drivers/mmcsd/mmcsd_spi.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/drivers/mmcsd/mmcsd_spi.c b/drivers/mmcsd/mmcsd_spi.c index 3990e517ac..19f0552cde 100644 --- a/drivers/mmcsd/mmcsd_spi.c +++ b/drivers/mmcsd/mmcsd_spi.c @@ -1243,7 +1243,7 @@ static ssize_t mmcsd_read(FAR struct inode *inode, unsigned char *buffer, response = mmcsd_sendcmd(slot, &g_cmd18, offset); if (response != MMCSD_SPIR1_OK) { - fdbg("CMD118 failed: R1=%02x\n", response); + fdbg("CMD18 failed: R1=%02x\n", response); goto errout_with_eio; } @@ -1402,6 +1402,13 @@ static ssize_t mmcsd_write(FAR struct inode *inode, const unsigned char *buffer, if (IS_SD(slot->type)) { + response = mmcsd_sendcmd(slot, &g_cmd55, 0); + if (response != MMCSD_SPIR1_OK) + { + fdbg("CMD55 failed: R1=%02x\n", response); + goto errout_with_sem; + } + response = mmcsd_sendcmd(slot, &g_acmd23, nsectors); if (response != MMCSD_SPIR1_OK) { @@ -1431,6 +1438,12 @@ static ssize_t mmcsd_write(FAR struct inode *inode, const unsigned char *buffer, goto errout_with_sem; } buffer += SECTORSIZE(slot); + + if (mmcsd_waitready(slot) != OK) + { + fdbg("Failed: card is busy\n"); + goto errout_with_sem; + } } /* Send the stop transmission token */