Skip to main content
LMI2
Senior III
Jun 5, 2018 3:23 PM UTC
Solved

Any examples with f_findfirst/f_findnext for 746D?

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.

    This topic has been closed for replies.
    Tesla DeLorean
    Tesla DeLoreanBest answer
    Guru
    Jun 5, 2018 11:03 PM UTC
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..

    11 replies

    Tesla DeLorean
    Guru
    Jun 5, 2018 3:47 PM UTC
    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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
    LMI2
    LMI2Author
    Senior III
    Jun 5, 2018 10:41 PM UTC
    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.

    Tilen MAJERLE
    ST Employee
    Jun 5, 2018 10:48 PM UTC
    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

    LMI2
    LMI2Author
    Senior III
    Jun 5, 2018 11:15 PM UTC
    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