SuperHouse / esp-open-rtos

Open source FreeRTOS-based ESP8266 software framework
BSD 3-Clause "New" or "Revised" License
1.52k stars 491 forks source link

Old SD card doesn't support CMD25, WRITE_MULTIPLE_BLOCK #666

Closed ChenHsiang closed 5 years ago

ChenHsiang commented 5 years ago

I noticed that sdio_write_sectors() return error when I using my lower end SD cards. My no-brand 128Mb and 256Mb cards having issue on f_mkdir() and the root cause is error in sdio_write_sectors(). To fix the issue, I have to replace the CMD25 (WRITE_MULTIPLE_BLOCK) with multiple CMD24 (single WRITE_BLOCK) to overcome the issue. To increase the compatability on different SD Cards, may I propose the change to replace CMD25?

(sdio_write_sectors() in extras/sdio/sdio.c)

#if 0
    if (command(card, CMD25, sector))
        return set_error(card, SDIO_ERR_IO);

    while (count--)
    {
        if (write_data_block(card, TOKEN_MULTI_TRAN, src) != SDIO_ERR_NONE)
            return card->error;
        src += SDIO_BLOCK_SIZE;
    }
    spi_transfer_8(BUS, TOKEN_STOP_TRAN);
#else
    // CHEN: Lower end card (EX: 128Mb) doesn't support
    //       multiple block write (CMD25)
    while (count--)
    {
        // single block
        if (command(card, CMD24, sector)) {
            return set_error(card, SDIO_ERR_IO);
        }
        if (write_data_block(card, TOKEN_SINGLE_TRAN, src) != SDIO_ERR_NONE)
            return card->error;
        src += SDIO_BLOCK_SIZE;
    }
#endif
UncleRus commented 5 years ago

Workarounded in #667, please test

UncleRus commented 5 years ago

Feel free to reopen issue if the error persists