cancel
Showing results for 
Search instead for 
Did you mean: 

Any examples with f_findfirst/f_findnext for 746D?

LMI2
Lead
Posted on June 05, 2018 at 17:23

ST seems to do reading all files in a directory in a hard way.

I am combining two examples about Sdfat but ST uses unfamiliar commands for reading all files in a directory. I think I could do it with a hard way but isn't f_findfirst/f_findnext more common.

I have examples for reading all bmp files and an other showing one jpg file.

Edit: By the way. I still have to accept cookies several times in one session.

1 ACCEPTED SOLUTION

Accepted Solutions
Posted on June 05, 2018 at 23:03

In ffconf.h

♯ define _USE_FIND        1

/* This option switches filtered directory read functions, f_findfirst() and

/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */

They compile a short list, in much the same way as you might populate the entries in a COMBO_BOX, in much the same way I'd display a list of Firmware .BIN files and ask the user to pick one, then I can load the selected one immediately rather than enumerate the files. The latter being problematic in a multi-tasking system where new files could appear, or old ones get deleted, and the indexes would change.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..

View solution in original post

11 REPLIES 11
Posted on June 05, 2018 at 17:47

>>Any examples with f_findfirst/f_findnext for 746D?

Why make this F746 or STM32 specific, FatFS is platform agnostic.

Is there an issue with this example?

http://elm-chan.org/fsw/ff/doc/findfirst.html

 

>>ST uses unfamiliar commands for reading all files in a directory.

Ok, but what does that mean, unfamiliar to them, to you, others practiced in the art?

STM32Cube_FW_F7_V1.11.0\Projects\STM32746G-Discovery\Applications\Display\LTDC_PicturesFromSDCard\Src\fatfs_storage.c

/**

  * @brief  List up to 25 file on the root directory with extension .BMP

  * @param  None

  * @retval The number of the found files

  */

uint32_t Storage_GetDirectoryBitmapFiles (const char* DirName, char* Files[])

{

  FRESULT res;

  uint32_t index = 0;

  /* Open filesystem */

  if(f_mount(&fs, (TCHAR const*)'',0) != FR_OK)

  {

    return 0;

  }

  /* Start to search for wave files */

  res = f_findfirst(&dir, &fno, DirName, '*.bmp');

  /* Repeat while an item is found */

  while (fno.fname[0])

  {

    if(res == FR_OK)

    {

      if(index < MAX_BMP_FILES)

      {

        sprintf (Files[index++], '%s', fno.fname);

      }

      /* Search for next item */

      res = f_findnext(&dir, &fno);

    }

    else

    {

      index = 0;

      break;

    }

  }

  f_closedir(&dir);

  return index;

}

>>By the way. I still have to accept cookies several times in one session.

Some settings or plug-ins at your end, this isn't an issue for 99.99% of users here. If it becomes sufficiently annoying, then change your behaviour.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 05, 2018 at 22:41

My C or Sdfat skills are in no way perfect. I get this error just inserting the function

'STM32746G-DISCOVERY\Exe\Project.axf: Error: L6218E: Undefined symbol f_findfirst (referred from main.o).' and same from findnext. I use STM32Cube_FW_F7_V1.11.0\Projects\STM32746G-Discovery\Applications\LibJPEG as basis, it uses Sdfat but clearly something is missing.

>>ST uses unfamiliar commands for reading all files in a directory.

'Ok, but what does that mean, unfamiliar to them, to you, others practiced in the art?'

I wonder what is the reason not using f_findnext. I have probably used them elsewhere and it was easy enough I think. Having an array to store file names eats ram.

Posted on June 05, 2018 at 22:48

Hello

Michael.Lei

‌,

follow FatFS docs and you will see how to enable f_findfirst/next functions:

http://elm-chan.org/fsw/ff/doc/findfirst.html

Best regard,

Tilen

Posted on June 05, 2018 at 23:03

In ffconf.h

♯ define _USE_FIND        1

/* This option switches filtered directory read functions, f_findfirst() and

/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */

They compile a short list, in much the same way as you might populate the entries in a COMBO_BOX, in much the same way I'd display a list of Firmware .BIN files and ask the user to pick one, then I can load the selected one immediately rather than enumerate the files. The latter being problematic in a multi-tasking system where new files could appear, or old ones get deleted, and the indexes would change.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 05, 2018 at 23:14

I added #include 'ffconf.h' but still get the same undefined error. I wonder if this is some Keil 'feature' here you have to tell paths elsewhere too, but Sdfat is already working so I wonder.

I found

http://elm-chan.org/fsw/ff/doc/findfirst.html

after same searching and it is quite good information. But something is missing, includes or something or some other setting. Because I allways get errors.

This is the beginning of the main.c

/* Includes ------------------------------------------------------------------*/#include 'main.h'#include 'ffconf.h'/* Private typedef -----------------------------------------------------------*//* Private define ------------------------------------------------------------*/#include 'ff.h'/* Private macro -------------------------------------------------------------*//* Private variables ---------------------------------------------------------*/FATFS SDFatFs; /* File system object for SD card logical drive */FIL MyFile; /* File object */FRESULT res;DIR dir;static FILINFO fno;//char* pDirectoryFiles[MAX_BMP_FILES];char* pDirectoryFiles[30];uint8_t ubNumberOfFiles = 0;uint32_t uwBmplen = 0;char SDPath[4]; /* SD card logical drive path */RGB_typedef *RGB_matrix;uint8_t _aucLine[2048];uint32_t offset = 0;uint32_t line_counter = 239;/* Private function prototypes -----------------------------------------------*/static void SystemClock_Config(void);static void LCD_Config(void);static uint8_t Jpeg_CallbackFunction(uint8_t* Row, uint32_t DataLength);static void CPU_CACHE_Enable(void);/* Private functions ---------------------------------------------------------*//* Search a directory for objects and display it */�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

.

LMI2
Lead
Posted on June 06, 2018 at 01:15

The code combiled without errors. That

'In ffconf.h

#define _USE_FIND        1->0 helped. But I don't want edit shared include files. I have to do some testing still, copy the file in my main.c folder probably. It is also getting late here,I'll continue tomorrow.

I thank you Clive and Tilen. This is much better now.

Edit: ffconf.h is project specific in this project, no need to fear about messing other projects

Posted on June 05, 2018 at 23:16

I answered but included some code we'll see. But in short &sharpinclude 'ffconf.h' did not help

Posted on June 05, 2018 at 23:45

ff.c needs to build against ffconf.h settings..

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Posted on June 06, 2018 at 01:04

'In ffconf.h

&sharpdefine _USE_FIND        1

/* This option switches filtered directory read functions, f_findfirst() and

/  f_findnext(). (0:Disable, 1:Enable 2:Enable with matching altname[] too) */'

There is

no

&sharpdefine _USE_FIND        1 in

ffconf.h

from

\STM32Cube\Repository\STM32Cube_FW_F7_V1.11.0\Projects\STM32746G-Discovery\Applications\DisplayLTDC_PicturesFromSDCard\MDK-ARM

or

STM32Cube\Repository\STM32Cube_FW_F7_V1.11.0\Projects\STM32746G-Discovery\Applications\LibJPEGLibJPEG_Decoding\MDK-ARM

There is not &sharpdefine _USE_FIND        1 text because it is 0. My mistake. I have to change it