Skip to content

Commit a24397e

Browse files
authored
Merge pull request #5694 from adafruit/7.1.x
Merge 7.1.x into main (for sdcard fix)
2 parents 3bdf2a5 + 8bd35d9 commit a24397e

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)