Skip to content

Commit 11c573e

Browse files
committed
sdcardio: Don't require reaching idle state during early init
.. which is what the addition of cmd25 made happen. We still signal an error when failing to reach the idle state at any other time, which _is_ different than adafruit_sdcard but I think that it is correct. This fixed #5600 according to Dan's testing on a GCM4 on the internal SD card slot. There are still some ambiguous results on the MM4 with external SD card slot on 6" jumper wires.
1 parent cd47941 commit 11c573e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

shared-module/sdcardio/SDCard.c

Lines changed: 8 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
}

0 commit comments

Comments
 (0)