|
|
@@ -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))
|