summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrobert-hh <robert@hammelrath.com>2022-02-15 18:02:09 +0100
committerDamien George <damien@micropython.org>2022-02-18 14:37:44 +1100
commit9c05f3aa1d201ba943c7852bee975f8b7d48e235 (patch)
tree9e94499f507977e0d2cb2bf4bee5c2d1cf3f276f
parent465b74e78daf50f5bd92625ba57bf2f5597cb712 (diff)
drivers/sdcard: Allow setting the final SPI baudrate.
This baudrate is supplied in the constructor. The default is 1320000 as before. Example: sd = sdcard.SDCard(spi, cs, baudrate=20_000_000)
-rw-r--r--drivers/sdcard/sdcard.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/drivers/sdcard/sdcard.py b/drivers/sdcard/sdcard.py
index 0ba3076a3..2c3e99d3c 100644
--- a/drivers/sdcard/sdcard.py
+++ b/drivers/sdcard/sdcard.py
@@ -39,7 +39,7 @@ _TOKEN_DATA = const(0xFE)
class SDCard:
- def __init__(self, spi, cs):
+ def __init__(self, spi, cs, baudrate=1320000):
self.spi = spi
self.cs = cs
@@ -51,7 +51,7 @@ class SDCard:
self.dummybuf_memoryview = memoryview(self.dummybuf)
# initialise the card
- self.init_card()
+ self.init_card(baudrate)
def init_spi(self, baudrate):
try:
@@ -63,7 +63,8 @@ class SDCard:
# on pyboard
self.spi.init(master, baudrate=baudrate, phase=0, polarity=0)
- def init_card(self):
+ def init_card(self, baudrate):
+
# init CS pin
self.cs.init(self.cs.OUT, value=1)
@@ -111,7 +112,7 @@ class SDCard:
raise OSError("can't set 512 block size")
# set to high data rate now that it's initialised
- self.init_spi(1320000)
+ self.init_spi(baudrate)
def init_card_v1(self):
for i in range(_CMD_TIMEOUT):