Should f_findfirst be available when the define FF_USE_FIND is set?

xgarbxgarb
Posts: 21
Joined: Fri Jan 25, 2019 3:36 pm

Should f_findfirst be available when the define FF_USE_FIND is set?

Postby xgarbxgarb » Thu May 30, 2019 4:03 pm

I'm trying to build a directory lister using FatFs with VFS for an SD card reader.

I get an undefined reference error when I try to use f_findfirst even when I change the FF_USE_FIND define in ffconf.h

Should I be able to use f_findfirst in the Arduino IDE? Basic code below:

Code: Select all

#include "Arduino.h"
#include "driver/sdmmc_host.h"
#include "driver/sdmmc_defs.h"
#include "sdmmc_cmd.h"
#include "esp_vfs_fat.h"

static esp_err_t card_err;

void setup() {
  Serial.begin(115200);
  card_err = init_sdcard();

#ifdef FF_USE_FIND
  Serial.print("defined: ");
  Serial.println( FF_USE_FIND ); // shows 2 in the serial monitor
#endif

  FF_DIR* dp;
  FRESULT dj = f_opendir(dp, "/sdcard");

  FRESULT fr;
  FILINFO fno;

  fr = f_findfirst(dp, &fno, "", "*");  // errors with "undefined reference to `f_findfirst'"

  while (fr == FR_OK && fno.fname[0]) {
    printf("%s\n", fno.fname);
    fr = f_findnext(dp, &fno);
  }

  f_closedir(dp);
}

xgarbxgarb
Posts: 21
Joined: Fri Jan 25, 2019 3:36 pm

Re: Should f_findfirst be available when the define FF_USE_FIND is set?

Postby xgarbxgarb » Tue May 12, 2020 4:29 pm

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() {}

Who is online

Users browsing this forum: No registered users and 115 guests