Skip to content

Commit ab6ad86

Browse files
GMMandpgeorge
authored andcommitted
drivers/sdcard: Fix CSD version 1.0 device size calculation.
Signed-off-by: Yukai Li <yukaili.geek@gmail.com>
1 parent f63b4f8 commit ab6ad86

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

drivers/sdcard/sdcard.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ def init_card(self, baudrate):
100100
if csd[0] & 0xC0 == 0x40: # CSD version 2.0
101101
self.sectors = ((csd[8] << 8 | csd[9]) + 1) * 1024
102102
elif csd[0] & 0xC0 == 0x00: # CSD version 1.0 (old, <=2GB)
103-
c_size = csd[6] & 0b11 | csd[7] << 2 | (csd[8] & 0b11000000) << 4
104-
c_size_mult = ((csd[9] & 0b11) << 1) | csd[10] >> 7
105-
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2))
103+
c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6
104+
c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7
105+
read_bl_len = csd[5] & 0b1111
106+
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len)
106107
else:
107108
raise OSError("SD card CSD format not supported")
108109
# print('sectors', self.sectors)

0 commit comments

Comments
 (0)