Skip to content

Commit 203b98c

Browse files
committed
drivers/sdcard: Make ioctl(4), ioctl(5) return num blocks, block size.
For CSD v1.0 the computed size is in bytes, so convert it to number of 512-byte blocks, and then ioctl(4) will return the correct value. Also implement ioctl(5) to return the block size, which is always 512. Signed-off-by: Damien George <damien@micropython.org>
1 parent ab6ad86 commit 203b98c

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/sdcard/sdcard.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ def init_card(self, baudrate):
103103
c_size = (csd[6] & 0b11) << 10 | csd[7] << 2 | csd[8] >> 6
104104
c_size_mult = (csd[9] & 0b11) << 1 | csd[10] >> 7
105105
read_bl_len = csd[5] & 0b1111
106-
self.sectors = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len)
106+
capacity = (c_size + 1) * (2 ** (c_size_mult + 2)) * (2**read_bl_len)
107+
self.sectors = capacity // 512
107108
else:
108109
raise OSError("SD card CSD format not supported")
109110
# print('sectors', self.sectors)
@@ -282,3 +283,5 @@ def writeblocks(self, block_num, buf):
282283
def ioctl(self, op, arg):
283284
if op == 4: # get number of blocks
284285
return self.sectors
286+
if op == 5: # get block size in bytes
287+
return 512

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy