From 9c05f3aa1d201ba943c7852bee975f8b7d48e235 Mon Sep 17 00:00:00 2001 From: robert-hh Date: Tue, 15 Feb 2022 18:02:09 +0100 Subject: [PATCH] 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) --- drivers/sdcard/sdcard.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/sdcard/sdcard.py b/drivers/sdcard/sdcard.py index 0ba3076a3d..2c3e99d3c0 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):