Skip to content

Commit 42670e4

Browse files
committed
sdcard: Updating sector calculation for SDXC.
The current code only calculates sectors for SDHC, with a max of 32G The new code will calculate sectors for SDXC, with a max of 2T C_SIZE is 22 bits[69:48] and 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 C_SIZE+1*1024 is a 32-bit number. Signed-off-by: Ben Wynn <[email protected]>
1 parent 3eaf027 commit 42670e4

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)