Recovery from SD fault - diskio_sdmmc: sdmmc_write_blocks failed (263)

PeterR
Posts: 621
Joined: Mon Jun 04, 2018 2:47 pm

Recovery from SD fault - diskio_sdmmc: sdmmc_write_blocks failed (263)

Postby PeterR » Tue Dec 11, 2018 1:10 pm

I am testing the performance&reliability of SD card operations.
I copy a file using fread()/fwrite() over & over.
We use single data SPI with no card detect.

If I briefly remove and replace the card during test then I get:

Code: Select all

I (21299) SDCardTest: COMPARE
E (22249) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x107
E (22259) diskio_sdmmc: sdmmc_read_blocks failed (263)
E (22259) SDCardTest: COMPARE - File system error, source(0), destination(1)
I (22269) SDCardTest: COPY - fopen('source.txt')
E (22919) sdmmc_cmd: sdmmc_read_sectors_dma: sdmmc_send_cmd returned 0x108
E (22919) diskio_sdmmc: sdmmc_read_blocks failed (264)
E (22919) SDCardTest: COPY - Failed to open 'source.txt'
I (22979) SDCardTest: COPY - fopen('source.txt')
I (22979) SDCardTest: COPY - fopen('dest.txt')
E (28289) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (28289) task_wdt:  - IDLE0 (CPU 0)
E (28289) task_wdt: Tasks currently running:
E (28289) task_wdt: CPU 0: SDCardTester
E (28289) task_wdt: CPU 1: IDLE1
E (28289) sdmmc_cmd: sdmmc_write_sectors_dma: sdmmc_send_cmd returned 0x107
E (28309) diskio_sdmmc: sdmmc_write_blocks failed (263)
E (28319) SDCardTest: COPY - File system error, source(0), destination(1)
I (28319) SDCardTest: COPY - Closing files
Subsequent attempts to fopen() result in watchdog timeouts and sdmmc_send_cmd failure either in sdmmc_read_blocks or sdmmc_write_blocks.

I expect that SD cards may be removed at inopportune moments and/or vibration may from time to time cause similar errors.
How best then to:
1) Detect this condition
2) Recover and restart the device (ideally forcing all existing handles to error).
3) Reduce the device blocking period such that task watchdog does not get triggered.

I suppose that ideally the driver level would either just recover and/or offer an error callback such that I could hide the connect/disconnect process from user space i.e. all the user application knows about is <stdio.h>

EDIT: (2) esp_vfs_fat_sdmmc_unmount() and then esp_vfs_fat_sdmmc_mount() recovers.
I still want to be able to detect the latched error condition rather than fopen(), ferror() which are user & handle based.
& I also believe that IDF CAN should be fixed.

Who is online

Users browsing this forum: No registered users and 125 guests