File tree Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Expand file tree Collapse file tree 1 file changed +7
-2
lines changed Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments