Skip to content

Commit 1a02b05

Browse files
author
deepikabhavnani
committed
Fixed SD card intialization failure
Few SD cards were failing for CMD41 as device was not ready after CMD55. Added busy delay loop to make sure device is ready and than proceed.
1 parent 2d24758 commit 1a02b05

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

SDBlockDevice.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,12 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
690690
for(int i = 0; i < 3; i++) {
691691
// Send CMD55 for APP command first
692692
if (isAcmd) {
693-
_cmd_spi(CMD55_APP_CMD, 0x0);
693+
response = _cmd_spi(CMD55_APP_CMD, 0x0);
694+
}
695+
696+
// Wait for card to be ready after CMD55
697+
if (false == _wait_ready(SD_COMMAND_TIMEOUT)) {
698+
debug_if(SD_DBG, "Card not ready yet \n");
694699
}
695700

696701
// Send command over SPI interface
@@ -710,20 +715,20 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
710715
// Process the response R1 : Exit on CRC/Illegal command error/No response
711716
if (R1_NO_RESPONSE == response) {
712717
_deselect();
713-
debug_if(SD_DBG, "No response CMD:%d \n", cmd);
718+
debug_if(SD_DBG, "No response CMD:%d response: 0x%x\n",cmd, response);
714719
return SD_BLOCK_DEVICE_ERROR_NO_DEVICE; // No device
715720
}
716721
if (response & R1_COM_CRC_ERROR) {
717722
_deselect();
718-
debug_if(SD_DBG, "CRC error CMD:%d \n", cmd);
723+
debug_if(SD_DBG, "CRC error CMD:%d response 0x%x \n",cmd, response);
719724
return SD_BLOCK_DEVICE_ERROR_CRC; // CRC error
720725
}
721726
if (response & R1_ILLEGAL_COMMAND) {
722-
debug_if(SD_DBG, "Illegal command CMD:%d\n", cmd);
727+
_deselect();
728+
debug_if(SD_DBG, "Illegal command CMD:%d response 0x%x\n",cmd, response);
723729
if (CMD8_SEND_IF_COND == cmd) { // Illegal command is for Ver1 or not SD Card
724730
_card_type = CARD_UNKNOWN;
725731
}
726-
_deselect();
727732
return SD_BLOCK_DEVICE_ERROR_UNSUPPORTED; // Command not supported
728733
}
729734

@@ -1024,4 +1029,5 @@ void SDBlockDevice::_deselect() {
10241029
_cs = 1;
10251030
_spi.unlock();
10261031
}
1032+
10271033
#endif /* DEVICE_SPI */

0 commit comments

Comments
 (0)