Thought I'd have another go at this so I pasted the contents of the IDF release 3.3.2 to
C:\Users\Dude\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.4\tools\sdk\include\fatfs and edited the config to allow f_find commands
Now it compiles but it crashes at line fr = f_findfirst(...
From the Exception Decoder it looks like line 4548 in ff.c is as far as it gets:
Code: Select all
dp->pat = pattern; /* Save pointer to pattern string */
Should I just give up on this and use the Arduino version of ESP32 code for directory reads? Fuil code below.
Code: Select all
#include "driver/sdmmc_host.h"
#include "driver/sdmmc_defs.h"
#include "sdmmc_cmd.h"
#include "esp_vfs_fat.h"
// copy fatfs from https://github.com/espressif/esp-idf/releases/tag/v3.3.2
// to C:\Users\Dude\Documents\ArduinoData\packages\esp32\hardware\esp32\1.0.4\tools\sdk\include\fatfs
#include "ff.c"
// in ffconf.h #define FF_USE_FIND 2
void setup() {
Serial.begin(115200);
esp_err_t ret = ESP_FAIL;
sdmmc_host_t host = SDMMC_HOST_DEFAULT();
host.flags = SDMMC_HOST_FLAG_1BIT; // using 1 bit mode
sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT();
//slot_config.width = 1; // using 1 bit mode
esp_vfs_fat_sdmmc_mount_config_t mount_config = {
.format_if_mount_failed = false,
.max_files = 1,
};
sdmmc_card_t *card;
Serial.println("Mounting SD card...");
ret = esp_vfs_fat_sdmmc_mount("/sdcard", &host, &slot_config, &mount_config, &card);
if (ret == ESP_OK) {
Serial.println("SD card mount successfully!");
} else {
Serial.printf("Failed to mount SD card VFAT filesystem. Error: %s", esp_err_to_name(ret));
}
FF_DIR* dp;
FRESULT dj = f_opendir(dp, "/sdcard");
FRESULT fr;
FILINFO fno;
fr = f_findfirst(dp, &fno, "", "*");
while (fr == FR_OK && fno.fname[0]) {
printf("%s\n", fno.fname);
fr = f_findnext(dp, &fno);
}
f_closedir(dp);
}
void loop() {}