Skip to content

Commit 2465222

Browse files
committed
drivers/sdcard: Allow up to 5 retries to initialise SD card.
Apparently some cards need more than 2 retries. See issue micropython#1482.
1 parent 845b5a2 commit 2465222

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

drivers/sdcard/sdcard.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,12 @@ def init_card(self):
5151
for i in range(16):
5252
self.spi.send(0xff)
5353

54-
# CMD0: init card; should return R1_IDLE_STATE (allow 2 attempts)
55-
if self.cmd(0, 0, 0x95) != R1_IDLE_STATE:
56-
if self.cmd(0, 0, 0x95) != R1_IDLE_STATE:
57-
raise OSError("no SD card")
54+
# CMD0: init card; should return R1_IDLE_STATE (allow 5 attempts)
55+
for _ in range(5):
56+
if self.cmd(0, 0, 0x95) == R1_IDLE_STATE:
57+
break
58+
else:
59+
raise OSError("no SD card")
5860

5961
# CMD8: determine card version
6062
r = self.cmd(8, 0x01aa, 0x87, 4)

0 commit comments

Comments
 (0)