Skip to content

Commit 52f5e0d

Browse files
committed
Make the initialization sequence more flexible
According to the SD specification v2.00 we this is the right way to initialize a card using the v1 protocol in a forward-compatible way.
1 parent 2d24758 commit 52f5e0d

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
@@ -274,14 +274,13 @@ int SDBlockDevice::_initialise_card()
274274
return SD_BLOCK_DEVICE_ERROR_NO_DEVICE;
275275
}
276276

277-
// Send CMD8
278-
if (BD_ERROR_OK != (status = _cmd8())) {
277+
// Send CMD8, if the card rejects the command then it's probably using the
278+
// legacy protocol, or is a MMC, or just flat-out broken
279+
status = _cmd8();
280+
if (BD_ERROR_OK != status && SD_BLOCK_DEVICE_ERROR_UNSUPPORTED != status) {
279281
return status;
280282
}
281283

282-
// Disable CRC
283-
status = _cmd(CMD59_CRC_ON_OFF, 0);
284-
285284
// Read OCR - CMD58 Response contains OCR register
286285
if (BD_ERROR_OK != (status = _cmd(CMD58_READ_OCR, 0x0, 0x0, &response))) {
287286
return status;
@@ -333,6 +332,10 @@ int SDBlockDevice::_initialise_card()
333332
_card_type = SDCARD_V1;
334333
debug_if(SD_DBG, "Card Initialized: Version 1.x Card\n");
335334
}
335+
336+
// Disable CRC
337+
status = _cmd(CMD59_CRC_ON_OFF, 0);
338+
336339
return status;
337340
}
338341

0 commit comments

Comments
 (0)