sdcard: Set MISO high before readblocks/writeblocks.

Originally by @peterhinch.
See https://github.com/micropython/micropython/pull/6007 for discussion.

The summary is that on some cards (especially older Kingston ones) if the
bus is shared with other SPI devices, then it seems to require that MISO
is high for a few cycles before the transaction is initiated.

Because CS is high, this change should otherwise be a no-op.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
pull/574/head
Jim Mussared 2022-11-14 22:46:35 +11:00
rodzic 56dc65b6a7
commit 6fca45f4f5
1 zmienionych plików z 8 dodań i 0 usunięć

Wyświetl plik

@ -243,6 +243,10 @@ class SDCard:
self.spi.write(b"\xff")
def readblocks(self, block_num, buf):
# workaround for shared bus, required for (at least) some Kingston
# devices, ensure MOSI is high before starting transaction
self.spi.write(b"\xff")
nblocks = len(buf) // 512
assert nblocks and not len(buf) % 512, "Buffer length is invalid"
if nblocks == 1:
@ -270,6 +274,10 @@ class SDCard:
raise OSError(5) # EIO
def writeblocks(self, block_num, buf):
# workaround for shared bus, required for (at least) some Kingston
# devices, ensure MOSI is high before starting transaction
self.spi.write(b"\xff")
nblocks, err = divmod(len(buf), 512)
assert nblocks and not err, "Buffer length is invalid"
if nblocks == 1: