-
Notifications
You must be signed in to change notification settings - Fork 7.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Writing to SD card fails in diskio_sdmmc: sdmmc_erase_sectors failed (262) (IDFGH-7094) #8704
Comments
Hi @zinke-ct-video, thanks for reporting this. I am able to reproduce this behavior. Error code 262 signifies ESP_ERR_NOT_SUPPORTED. This error is reported from line 520 of the file components/sdmmc/sdmmc_cmd.c I see there is a bug in, validating the CMD38 argument. SDMMC_MMC_TRIM_ARG and SDMMC_SD_DISCARD_ARG have the same value 1 causing the wrong condition check and resulting in ESP_ERR_NOT_SUPPORTED. You have rightly figured out, disabling FF_USE_TRIM does not invoke I assure, that the error message on the serial log output: Please help to replace lines 519-525 of components/sdmmc/sdmmc_cmd.c (sdmmc_erase_sectors) with the folowing snippet and share your observation with SanDisk Ultra 32GB Class 10
@igrr , I see we can replace the line-80 of components/fatfs/diskio/diskio_sdmmc.c (information instead of errror to avoid panic) |
Good to hear that it doesn't affect file system integrity. Just out of curiosity ... What's the purpose of these TRIM and DISCARD commands if file system is also fully functional without them? Performance improvement? As requested I replaced lines 519-525 of components/sdmmc/sdmmc_cmd.c (sdmmc_erase_sectors) with the code from your response and tested the SanDisk Ultra 32GB Class 10 again. The error doesn't occur anymore. Thank's a lot for the quick reply and fix! |
@zinke-ct-video thanks for the confirmation. TRIM/DISCARD will let the FTL (Flash Translation Layer) of the card to mark the sectors for erasing so that GC (garbage colleciton)can erase these sectors in the background to improve the WRITE performance (implementation is specific to card vendor). With this, WRITE operation need not wait for ERASE to complete in certain cases. I understand Samsung EVO 32GB is working as expected, please confirm. |
Thanks for the explanation. Yes, I can confirm this. Both card types I am using are working as expected with your patch. |
Can you say where you have added the : |
I think I added this line after the call to the |
I know, it has been fixed, however, i am using 128 GB sd card which apparently works fine with the file system just isn't able to be formatted when using SDMMC(currently i am formatting with SPI then switching to MMC for speed) :) |
Okay, this sounds like another bug. Maybe you should open another issue to get help formatting the 128 GB SD card? |
Environment
Problem Description
TL;DR
File write operations on SD cards having DISCARD or FULE support fail. This bug was introduced with the commits 964592 and ffdbee
In-depth explanation
My ESP32 is connected to an SD card. The ESP32 performs lots of read and write operations on files on the SD card. Before the commits mentioned above came in, everything was fine. After these commits came in, I noticed that on some types of SD cards errors occur during file write operations. The following error message appears on the serial log output for every failed operation:
E (13146) diskio_sdmmc: sdmmc_erase_sectors failed (262)
I further investigated the bug and found that this error occurs only on some types of SD cards. To find the difference between the cards I wrote the following code to dump the SD card registers:
I tested two types of SD cards, the SanDisk Ultra doesn't work, the Samsung EVO works fine. Here the is the log output for both cards:
SanDisk Ultra 32GB Class 10:
Samsung EVO 32GB:
As you can see, the only significant differences are card->ssr.discard_support and card->ssr.fule_support.
Next, I have checked if I can make the error disappear if I disable these flags on the SanDisk Ultra card manually. To do so, I added the following two lines.
Doing so the SanDisk Ultra card with discard and fule support works fine now, too.
The last test I did was disabling TRIM support in the fatfs component. So let's go back and remove the above workaround that disabled discard_support and fule_support. Then go to the file esp-idf/components/fatfs/src/ffconf.h and change the line 238 from
#define FF_USE_TRIM 1
to#define FF_USE_TRIM 0
. Also this step makes the error disappear and both cards work fine.So I conclude that there must be an issue with the newly introduced function
sdmmc_erase_sectors
in the file esp-idf/components/fatfs/diskio/diskio_sdmmc.cExpected Behavior
All file I/O should succeed even with cards that support DISCARD and FULE.
The text was updated successfully, but these errors were encountered: