Skip to content

Commit 8bd35d9

Browse files
authored
Merge pull request #5688 from jepler/issue5600
sdcardio: Don't require reaching idle state during early init
2 parents cd47941 + bc9ef87 commit 8bd35d9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

shared-module/sdcardio/SDCard.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,18 @@ STATIC const compressed_string_t *init_card(sdcardio_sdcard_obj_t *self) {
230230

231231
common_hal_digitalio_digitalinout_set_value(&self->cs, false);
232232

233+
assert(!self->in_cmd25);
234+
self->in_cmd25 = false; // should be false already
235+
233236
// CMD0: init card: should return _R1_IDLE_STATE (allow 5 attempts)
234237
{
235238
bool reached_idle_state = false;
236239
for (int i = 0; i < 5; i++) {
237-
if (cmd(self, 0, 0, NULL, 0, true, true) == R1_IDLE_STATE) {
240+
// do not call cmd with wait=true, because that will return
241+
// prematurely if the idle state is not reached. we can't depend on
242+
// this when the card is not yet in SPI mode
243+
(void)wait_for_ready(self);
244+
if (cmd(self, 0, 0, NULL, 0, true, false) == R1_IDLE_STATE) {
238245
reached_idle_state = true;
239246
break;
240247
}
@@ -259,6 +266,7 @@ STATIC const compressed_string_t *init_card(sdcardio_sdcard_obj_t *self) {
259266
return result;
260267
}
261268
} else {
269+
DEBUG_PRINT("Reading card version, response=0x%02x\n", response);
262270
return translate("couldn't determine SD card version");
263271
}
264272
}

0 commit comments

Comments
 (0)