Skip to content

Commit d002168

Browse files
authored
drivers/storage/sdcard: updating sector calculation for CSD v2.0
C_SIZE is 22 bits[69:48], which is the low 6 bits of csd[7], 8bits from csd[8], and 8 bits from csd[9]. the high 2 bits of csd[7] are required to be 0, currently, so i'm not masking them off. The max value for C_SIZE is 0x3FFEFF, so (0x3FFEFF + 1) * 1024 would be 0xFFFC0000, which is still a 32-bit number. Signed-off-by: Ben Wynn <bwynn@glowie.com>
1 parent 3eaf027 commit d002168

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

micropython/drivers/storage/sdcard/sdcard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def init_card(self, baudrate):
9797
csd = bytearray(16)
9898
self.readinto(csd)
9999
if csd[0] & 0xC0 == 0x40: # CSD version 2.0
100-
self.sectors = ((csd[8] << 8 | csd[9]) + 1) * 1024
100+
self.sectors = ((csd[7] << 16 | csd[8] << 8 | csd[9]) + 1) * 1024
101101
elif csd[0] & 0xC0 == 0x00: # CSD version 1.0 (old, <=2GB)
102102
c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6
103103
c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7

0 commit comments

Comments
 (0)