Can't always read files on SD card if nested in subfolder.
I'm trying to work with the ESP vfs and SDMMC drivers to read data from an SD card. The data will eventually be served on a mongoose webserver, so I'm trying to implement the virtual file system layer for mongoose.
I'm having a really hard time reading certain files from my SD card, it seems like the ESP file system has a different idea of what the names of the files should be vs what the names appear to be on Windows.
This first screenshot is a snippet of code that lists files and folder in a given directory, in this case the/sdcard/web directory. This works well, and works with any directory, nested or not.
The output from the code above lists all of the files in /sdcard (the mount point) /web. One oddity I can't figure out is why some of the files have different names than the file names that appear on windows. For example, /sdcard/web/INDEX~1.HTM should be /sdcard/web/index.html.
Below you can see the files in the /web directory on Windows, and index.html is in fact named index.html, not INDEX~1.HTM.
Now, if I try to run the stat function on the file /sdcard/web/index.html It returns -1 and can't find the file. However, if I change the path to /sdcard/web/index~1.htm it works just fine, so the ESP is clearly using different file names.
the \"correct\" file name does not work
the \"incorrect\" file name does work
So why is the directory listing (specifically the call to the readdir() function) finding the files, but finding them with (sometimes) changed names? What am I doing wrong here? Any pointers or insights would be greatly appreiciated!
Posted Feb 14, 2023, 6:43 PM UTC
You should use 8.3 filenames
Now you are using vfat/fat32 long file names and the esp32 code shows the old school 8.3 version of those names..
Read this for a much better explanation.
https://en.m.wikipedia.org/wiki/Long_filename
E:spelling.
That was it! I’m glad to see there’s support for long filenames in the IDF already, all I needed to do was enable it. Thanks
Sorry for asking this but i can't get an sd card to work reliably. Would you mind answering a few questions?
Does sd card work reliably in your case with esp32? Which module are you using and how long are the connections? Are you using spi or sdmmc or sdio protocol? Do you have any pullup resistors connected?
In my case the card fails to mount every other time. I'm using the standard Arduino 5v module with regulator and what appears to be a level converter i think. Like this: sd card module without any resistors in spi mode.
Hi,
So far I haven't had any issues with reliability of SD card reading. Right now I have a bare micro SD slot with magnet wire soldered to the pads connected to a breadboard, which is obviously not great at all for signal integrity. I have 10K pullups to 3.3 on all of the pins. I am running in 4 bit SDMMC mode. I have no problems mounting at all.
I don't like SPI mode for SD cards, since that has seemed to be pretty hit or miss for me.
That particular module isn't a great choice for use with an ESP since that module is expecting 5v power and 5v signals. The problem you're having is likely due to the AMS1117 that's dropping the voltage too low for your SD card. Maybe try 5v on the voltage input for that, but then the bus transceiver chip might not play nice if it's expecting 5v as a logical high on its inputs.
If you feel like modifying that module, I'd remove the LDO and bus transceiver and just wire up the pins from the card holder directly to the 2.54mm pin header, and try to keep the bypass caps on the 3.3v rail.