drivers/sdcard: Fix CSD version 1.0 device size calculation.

Signed-off-by: Yukai Li <yukaili.geek@gmail.com>
This commit is contained in:
Yukai Li 2022-04-12 22:51:00 -06:00 committed by Damien George
parent f63b4f85aa
commit ab6ad86793
1 changed files with 4 additions and 3 deletions

View File

@ -100,9 +100,10 @@ class SDCard:
if csd[0] & 0xC0 == 0x40: # CSD version 2.0
self.sectors = ((csd[8] << 8 | csd[9]) + 1) * 1024
elif csd[0] & 0xC0 == 0x00: # CSD version 1.0 (old, <=2GB)
c_size = csd[6] & 0b11 | csd[7] << 2 | (csd[8] & 0b11000000) << 4
c_size_mult = ((csd[9] & 0b11) << 1) | csd[10] >> 7
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2))
c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6
c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7
read_bl_len = csd[5] & 0b1111
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len)
else:
raise OSError("SD card CSD format not supported")
# print('sectors', self.sectors)