浏览代码

RP2040: Fix reading very last SD card sector

For some reason last SD card sector cannot be accessed with
multiblock read.

Same as commit 8aa229dcd/3c41957068 for GD32.
Petteri Aimonen 3 年之前
父节点
当前提交
a5cb1cabcb
共有 1 个文件被更改,包括 5 次插入2 次删除
  1. 5 2
      lib/ZuluSCSI_platform_RP2040/sd_card_sdio.cpp

+ 5 - 2
lib/ZuluSCSI_platform_RP2040/sd_card_sdio.cpp

@@ -17,6 +17,7 @@ static csd_t g_sdio_csd;
 static int g_sdio_error_line;
 static sdio_status_t g_sdio_error;
 static uint32_t g_sdio_dma_buf[128];
+static uint32_t g_sdio_sector_count;
 
 #define checkReturnOk(call) ((g_sdio_error = (call)) == SDIO_OK ? true : logSDError(__LINE__))
 static bool logSDError(int line)
@@ -128,6 +129,8 @@ bool SdioCard::begin(SdioConfig sdioConfig)
         return false;
     }
 
+    g_sdio_sector_count = sectorCount();
+
     // Select card
     if (!checkReturnOk(rp2040_sdio_command_R1(CMD7, g_sdio_rca, &reply)))
     {
@@ -429,9 +432,9 @@ bool SdioCard::readSector(uint32_t sector, uint8_t* dst)
 
 bool SdioCard::readSectors(uint32_t sector, uint8_t* dst, size_t n)
 {
-    if (((uint32_t)dst & 3) != 0)
+    if (((uint32_t)dst & 3) != 0 || sector + n >= g_sdio_sector_count)
     {
-        // Unaligned read, execute sector-by-sector
+        // Unaligned read or end-of-drive read, execute sector-by-sector
         for (size_t i = 0; i < n; i++)
         {
             if (!readSector(sector + i, dst + 512 * i))