Skip to content

Commit c7347c9

Browse files
author
Deepika
authored
Merge pull request ARMmbed#50 from LemonBoy/sdcard-init-seq
Make the initialization sequence more flexible
2 parents 48c1b7e + 52f5e0d commit c7347c9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

SDBlockDevice.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,14 +278,13 @@ int SDBlockDevice::_initialise_card()
278278
return SD_BLOCK_DEVICE_ERROR_NO_DEVICE;
279279
}
280280

281-
// Send CMD8
282-
if (BD_ERROR_OK != (status = _cmd8())) {
281+
// Send CMD8, if the card rejects the command then it's probably using the
282+
// legacy protocol, or is a MMC, or just flat-out broken
283+
status = _cmd8();
284+
if (BD_ERROR_OK != status && SD_BLOCK_DEVICE_ERROR_UNSUPPORTED != status) {
283285
return status;
284286
}
285287

286-
// Disable CRC
287-
status = _cmd(CMD59_CRC_ON_OFF, 0);
288-
289288
// Read OCR - CMD58 Response contains OCR register
290289
if (BD_ERROR_OK != (status = _cmd(CMD58_READ_OCR, 0x0, 0x0, &response))) {
291290
return status;
@@ -337,6 +336,10 @@ int SDBlockDevice::_initialise_card()
337336
_card_type = SDCARD_V1;
338337
debug_if(SD_DBG, "Card Initialized: Version 1.x Card\n");
339338
}
339+
340+
// Disable CRC
341+
status = _cmd(CMD59_CRC_ON_OFF, 0);
342+
340343
return status;
341344
}
342345

0 commit comments

Comments
 (0)