From d82f084f11fc968fe70dd19280595c7f3b5e98c1 Mon Sep 17 00:00:00 2001 From: Deepika Date: Tue, 27 Jun 2017 14:01:40 -0500 Subject: [PATCH] Retry command sending on SD card Sometimes card is busy programming multiple blocks and responds with 0xFF i.e. response. Re-trying 3 times to send the command. --- features/filesystem/sd/SDBlockDevice.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/features/filesystem/sd/SDBlockDevice.cpp b/features/filesystem/sd/SDBlockDevice.cpp index a162875ee1..7d0e78ebe4 100644 --- a/features/filesystem/sd/SDBlockDevice.cpp +++ b/features/filesystem/sd/SDBlockDevice.cpp @@ -603,15 +603,22 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc debug_if(SD_DBG, "Card not ready yet \n"); } + // Re-try command + for(int i = 0; i < 3; i++) { + // Send CMD55 for APP command first + if (isAcmd) { + _cmd_spi(CMD55_APP_CMD, 0x0); + } - // Send CMD55 for APP command first - if (isAcmd) { - _cmd_spi(CMD55_APP_CMD, 0x0); + // Send command over SPI interface + response = _cmd_spi(cmd, arg); + if (R1_NO_RESPONSE == response) { + debug_if(SD_DBG, "No response CMD:%d \n", cmd); + continue; + } + break; } - // Send command over SPI interface - response = _cmd_spi(cmd, arg); - debug_if(_dbg, "CMD:%d \t arg:0x%x \t Response:0x%x \n", cmd, arg, response); // Pass the response to the command call if required if (NULL != resp) { *resp = response;