Skip to content

Commit b90f51f

Browse files
aykevldpgeorge
authored andcommitted
drivers/sdcard: Support old SD cards (<=2GB).
1 parent f16c775 commit b90f51f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

drivers/sdcard/sdcard.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,14 @@ def init_card(self):
9696
raise OSError("no response from SD card")
9797
csd = bytearray(16)
9898
self.readinto(csd)
99-
if csd[0] & 0xc0 != 0x40:
99+
if csd[0] & 0xc0 == 0x40: # CSD version 2.0
100+
self.sectors = ((csd[8] << 8 | csd[9]) + 1) * 2014
101+
elif csd[0] & 0xc0 == 0x00: # CSD version 1.0 (old, <=2GB)
102+
c_size = csd[6] & 0b11 | csd[7] << 2 | (csd[8] & 0b11000000) << 4
103+
c_size_mult = ((csd[9] & 0b11) << 1) | csd[10] >> 7
104+
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2))
105+
else:
100106
raise OSError("SD card CSD format not supported")
101-
self.sectors = ((csd[8] << 8 | csd[9]) + 1) * 2014
102107
#print('sectors', self.sectors)
103108

104109
# CMD16: set block length to 512 bytes

0 commit comments

Comments
 (0)