Skip to content

_cmd() hangs waiting for 0xfe after large write #11

Closed
@dhalbert

Description

@dhalbert

This forum thread provoked this issue: https://forums.adafruit.com/viewtopic.php?f=60&t=141707. The poster had this problem with all the SD cards they tried and I had trouble with the one I tried as well. The failures are not consistently at the same place across different cards or even multiple trials, so it appears to be timing-related (probably due to something the SD card is doing).

After the second or so writeblocks() of a 7168-byte buffer, a readblocks() follows, which calls
_cmd(12, wait=False). This hangs in _cmd() in the loop below; it never receives a 0xfe.

                            # Wait for the start block byte
                            while buf[1] != 0xfe:
                                spi.readinto(buf, start=1, end=2, write_value=0xff)

I tried setting wait=True and it made no difference.

Attached is an instrumented version of adafruit_sdcard.py, which produces the output below. Notice that a 0x7 is received first, which doesn't show up anywhere else, followed by 0xff indefinitely. Also attached is the test program (test.py).
adafruit_sdcard.py.txt
test.py.txt

Output:

>>> import test




waiting for 0xfe 0x0 
readblocks 512
waiting for 0xfe 0x0 0xff 
readblocks 512
waiting for 0xfe 0x0 0xff 
readblocks 512
waiting for 0xfe 0x0 0xff 
readblocks 512
waiting for 0xfe 0x0 0xff 
readblocks 512
waiting for 0xfe 0x0 0xff 
WRITE 10
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
WRITE 10
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
WRITE 4106
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
writeblocks 3584
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
WRITE 4106
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
writeblocks 3072
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
writeblocks 512
writeblocks 512
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
readblocks 512
waiting for 0xfe 0x0 0xff 
WRITE 8202
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
writeblocks 7168
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
writeblocks 512
writeblocks 512
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
writeblocks 512
readblocks 512
waiting for 0xfe 0x0 0xff 
readblocks 512
waiting for 0xfe 0x0 0xff 
WRITE 8202
readblocks 512
waiting for 0xfe 0x0 0xff 
writeblocks 512
writeblocks 7168
readblocks 512
waiting for 0xfe 0x0 0x7 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff [[[typed ctrl-c here]]] Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "test.py", line 20, in <module>
  File "test.py", line 20, in <module>
OSError: [Errno 5] Input/output error
>>> 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions