Skip to content

Commit d5671e2

Browse files
author
Deepika
authored
Merge pull request ARMmbed#48 from ARMmbed/cmd41_init_issue
Fixed SD card intialization failure
2 parents 0ac12a0 + 1a02b05 commit d5671e2

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
@@ -697,7 +697,12 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
697697
for(int i = 0; i < 3; i++) {
698698
// Send CMD55 for APP command first
699699
if (isAcmd) {
700-
_cmd_spi(CMD55_APP_CMD, 0x0);
700+
response = _cmd_spi(CMD55_APP_CMD, 0x0);
701+
}
702+
703+
// Wait for card to be ready after CMD55
704+
if (false == _wait_ready(SD_COMMAND_TIMEOUT)) {
705+
debug_if(SD_DBG, "Card not ready yet \n");
701706
}
702707

703708
// Send command over SPI interface
@@ -717,20 +722,20 @@ int SDBlockDevice::_cmd(SDBlockDevice::cmdSupported cmd, uint32_t arg, bool isAc
717722
// Process the response R1 : Exit on CRC/Illegal command error/No response
718723
if (R1_NO_RESPONSE == response) {
719724
_deselect();
720-
debug_if(SD_DBG, "No response CMD:%d \n", cmd);
725+
debug_if(SD_DBG, "No response CMD:%d response: 0x%x\n",cmd, response);
721726
return SD_BLOCK_DEVICE_ERROR_NO_DEVICE; // No device
722727
}
723728
if (response & R1_COM_CRC_ERROR) {
724729
_deselect();
725-
debug_if(SD_DBG, "CRC error CMD:%d \n", cmd);
730+
debug_if(SD_DBG, "CRC error CMD:%d response 0x%x \n",cmd, response);
726731
return SD_BLOCK_DEVICE_ERROR_CRC; // CRC error
727732
}
728733
if (response & R1_ILLEGAL_COMMAND) {
729-
debug_if(SD_DBG, "Illegal command CMD:%d\n", cmd);
734+
_deselect();
735+
debug_if(SD_DBG, "Illegal command CMD:%d response 0x%x\n",cmd, response);
730736
if (CMD8_SEND_IF_COND == cmd) { // Illegal command is for Ver1 or not SD Card
731737
_card_type = CARD_UNKNOWN;
732738
}
733-
_deselect();
734739
return SD_BLOCK_DEVICE_ERROR_UNSUPPORTED; // Command not supported
735740
}
736741

@@ -1031,4 +1036,5 @@ void SDBlockDevice::_deselect() {
10311036
_cs = 1;
10321037
_spi.unlock();
10331038
}
1039+
10341040
#endif /* DEVICE_SPI */

0 commit comments

Comments
 (0)