Skip to content

Commit 4e0d5c9

Browse files
committed
fix(sdmmc_io): fixed fixed_addr mode will still increase addr when splitting
1 parent 096db75 commit 4e0d5c9

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

components/sdmmc/sdmmc_io.c

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,15 @@ esp_err_t sdmmc_io_rw_extended(sdmmc_card_t* card, int func,
336336
esp_err_t sdmmc_io_read_bytes(sdmmc_card_t* card, uint32_t function,
337337
uint32_t addr, void* dst, size_t size)
338338
{
339-
uint32_t arg = SD_ARG_CMD53_READ | SD_ARG_CMD53_INCREMENT;
340-
//Extract and unset the bit used to indicate the OP Code (inverted logic)
339+
uint32_t arg = SD_ARG_CMD53_READ;
340+
bool incr_addr = true;
341+
//Extract and unset the bit used to indicate the OP Code
341342
if (addr & SDMMC_IO_FIXED_ADDR) {
342-
arg &= ~SD_ARG_CMD53_INCREMENT;
343343
addr &= ~SDMMC_IO_FIXED_ADDR;
344+
incr_addr = false;
345+
}
346+
if (incr_addr) {
347+
arg |= SD_ARG_CMD53_INCREMENT;
344348
}
345349

346350
/* host quirk: SDIO transfer with length not divisible by 4 bytes
@@ -360,19 +364,25 @@ esp_err_t sdmmc_io_read_bytes(sdmmc_card_t* card, uint32_t function,
360364
}
361365
pc_dst += will_transfer;
362366
size -= will_transfer;
363-
addr += will_transfer;
367+
if (incr_addr) {
368+
addr += will_transfer;
369+
}
364370
}
365371
return ESP_OK;
366372
}
367373

368374
esp_err_t sdmmc_io_write_bytes(sdmmc_card_t* card, uint32_t function,
369375
uint32_t addr, const void* src, size_t size)
370376
{
371-
uint32_t arg = SD_ARG_CMD53_WRITE | SD_ARG_CMD53_INCREMENT;
372-
//Extract and unset the bit used to indicate the OP Code (inverted logic)
377+
uint32_t arg = SD_ARG_CMD53_WRITE;
378+
bool incr_addr = true;
379+
//Extract and unset the bit used to indicate the OP Code
373380
if (addr & SDMMC_IO_FIXED_ADDR) {
374-
arg &= ~SD_ARG_CMD53_INCREMENT;
375381
addr &= ~SDMMC_IO_FIXED_ADDR;
382+
incr_addr = false;
383+
}
384+
if (incr_addr) {
385+
arg |= SD_ARG_CMD53_INCREMENT;
376386
}
377387

378388
/* same host quirk as in sdmmc_io_read_bytes */
@@ -389,7 +399,9 @@ esp_err_t sdmmc_io_write_bytes(sdmmc_card_t* card, uint32_t function,
389399
}
390400
pc_src += will_transfer;
391401
size -= will_transfer;
392-
addr += will_transfer;
402+
if (incr_addr) {
403+
addr += will_transfer;
404+
}
393405
}
394406
return ESP_OK;
395407
}

0 commit comments

Comments
 (0)