← index #7051Issue #7129
Duplicate · high · value 4.164
QUERY · ISSUE

sdcard.py - OSError: timeout waiting for response

openby Leniwcowatyopened 2021-03-18updated 2024-09-08
drivers

I am using 8 GB microSD card, format FAT32. During mount code detects it as v2 card, but gives "OSError: timeout waiting for response". Tried to format as 4 GB FAT, did not work.
Raspberry Pi Pico

CANDIDATE · ISSUE

Pico: sdcard.py timeout waiting for response

closedby jbeale1opened 2021-04-18updated 2025-02-02
drivers

I was unable to use the https://github.com/micropython/micropython/blob/master/drivers/sdcard/sdcard.py code as-is on my Raspberry Pi Pico, I would get "timeout waiting for response" when accessing my microSD card device, I presume from this part of the code:

        # read until start byte (0xff)
        for i in range(_CMD_TIMEOUT):
            self.spi.readinto(self.tokenbuf, 0xFF)
            if self.tokenbuf[0] == _TOKEN_DATA:
                break
        else:
            self.cs(1)
            raise OSError("timeout waiting for response")

I was able to fix this by simply changing the _CMD_TIMEOUT from 100 to 1000:
_CMD_TIMEOUT = const(1000)

I don't know if the Pico board is faster, or my old SanDisk 8GB is slower than what was tested, but there is an existence proof that more cards will work with a longer timeout. Also, another Pico user with other SanDisk uSD cards reported the same problem, and found the same fix worked for them as well: https://www.raspberrypi.org/forums/viewtopic.php?f=146&t=308819&start=25

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied