From b71fe6086349a2d2d12664ed678629f1c07e8e31 Mon Sep 17 00:00:00 2001 From: Mikey Sklar Date: Mon, 18 May 2026 11:54:28 -0700 Subject: [PATCH] sdcardio: fix card size for SDXC cards > 32 GB The CSD v2.0 C_SIZE field is 22 bits but only the bottom 16 were being read. Cards > 32 GB reported roughly half their actual block count over USB MSC. Fix reads all 22 bits. Co-Authored-By: Claude Sonnet 4.6 --- shared-module/sdcardio/SDCard.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shared-module/sdcardio/SDCard.c b/shared-module/sdcardio/SDCard.c index 3630e4ea16743..cadd2ba8a094a 100644 --- a/shared-module/sdcardio/SDCard.c +++ b/shared-module/sdcardio/SDCard.c @@ -316,7 +316,7 @@ static mp_rom_error_text_t init_card(sdcardio_sdcard_obj_t *self) { } if (csd_version == 1) { - self->sectors = ((csd[8] << 8 | csd[9]) + 1) * 1024; + self->sectors = (((uint32_t)(csd[7] & 0x3F) << 16 | (uint32_t)csd[8] << 8 | csd[9]) + 1) * 1024; } else { uint32_t block_length = 1 << (csd[5] & 0xF); uint32_t c_size = ((csd[6] & 0x3) << 10) | (csd[7] << 2) | ((csd[8] & 0xC) >> 6);