cancel
Showing results for 
Search instead for 
Did you mean: 

PATH and File Name Length Limitation while using FATFS Middleware

Utkarash Patil
Associate III

Hello All,

I am using Cube MX (4.24) and Atollic truestudio (9.2.0) and want to implement a USB based boot loader part for my application .

Where i use STM32F777IITx MCU with "STM32Cube FW_F7 V1.9.0" firmware package.

Currently i was implementing USB binary file reading part,

However when i try the below given API's i am facing some issues which i have mentioned below

Issue 1.

If i use "f_open(&myFile, "OPENBLINKYFILE.TXT", FA_READ);" api i get error saying "FR_INVALID_NAME".

whereas, If i Use same api as follows "f_open(&SDFile, "BLINKY.TXT", FA_READ);"

I do not get any error it works i am able to open file and read data.

Issue 2.

If i use "f_stat("/TEST/BIN.TXT", &myFileinfo);" api i get error saying "FR_INVALID_NAME" also if i am not able to read file status.

whereas, If i Use same api as follows "f_open("/TEST/BLINKYOPEN.TXT", &myFileinfo);"

I do not get any error it works i am able to open file and read data.

I face such issue for many more api's whenever i want to access files with Long path name or long file name

I might be wrong but i think this is due to the small size of array declaration in FF.h which i have mentioned in bold

typedef struct {

   _FDID   obj;         /* Object identifier */

   DWORD   dptr;         /* Current read/write offset */

   DWORD   clust;         /* Current cluster */

   DWORD   sect;         /* Current sector (0:Read operation has terminated) */

   BYTE*   dir;         /* Pointer to the directory item in the win[] */

   BYTE   fn[12];         /* SFN (in/out) {body[8],ext[3],status[1]} */

#if _USE_LFN != 0

   DWORD   blk_ofs;      /* Offset of current entry block being processed (0xFFFFFFFF:Invalid) */

#endif

#if _USE_FIND

   const TCHAR* pat;      /* Pointer to the name matching pattern */

#endif

} DIR;

/* File information structure (FILINFO) */

typedef struct {

   FSIZE_t   fsize;         /* File size */

   WORD   fdate;         /* Modified date */

   WORD   ftime;         /* Modified time */

   BYTE   fattrib;      /* File attribute */

#if _USE_LFN != 0

   TCHAR   altname[13];         /* Alternative file name */

   TCHAR   fname[_MAX_LFN + 1];   /* Primary file name */

#else

   TCHAR   fname[13];      /* File name */

#endif

} FILINFO;

I request to please help me at the earliest at the earliest.

Also please help me with best firmware package version if i am using wrong.

Thanks and regards

Utkarsh

13 REPLIES 13

It seems that your own question has the answer, this part:

#if _USE_LFN != 0
   TCHAR   altname[13];         /* Alternative file name */
   TCHAR   fname[_MAX_LFN + 1];   /* Primary file name */
#else
   TCHAR   fname[13];      /* File name */
#endif

Do you see the pre-processor condition? If you are sure that the 13-length version is being used then edit ffconf.h to define the _USE_LFN so that long file name (LFN) support is activated. It can be defined as 0, 1, 2 or 3. Read the comments to know the difference.

Review configuration settings for aspects of FatFs in the ffconf.h include file used in your project. Pick those appropriate for your application.

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

Hello All,

Thank You For your Response and suggestion,

However When i change the macro _USE_LFN my code shows me 3 errors whose screen shot i have attached below, Whereas the errors are from the file "ff.c" where i have not even changed anything

0690X000009k9AmQAI.png

After checking the macros in "ffconf.h" file I understood that i have to change other two macro's also with enabling the _USE_LFN macro.

So as per my application i changed the _USE_LFN and _STRF_ENCODE macro's to the following values

#define _USE_LFN    2  /* Enable LFN with dynamic working buffer on the STACK.*/

#define _MAX_LFN    255 

#define _LFN_UNICODE   1

#define _STRF_ENCODE   1 //or 2 /* UTF -16LE or UTF-16BE anything will work

Then Also i faced the same errors which i have mentioned above Hence, i tried all the combinations, of the above 3 macros to resolve this error.

0690X000009k9GaQAI.png

So i request to please help me with this at the earliest,

Also Please let me Known If i am missing out on something,

Thanks and regards

Utkarash

Suggests that you are missing one of the FatFs middleware files containing these functions. Add it to the project. Not on a PC right now​, will check which later.

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

Hello Clive,

Waiting for your reply

Thank You for your consern and suggestions.

Thanks and regards

Utkarsh

Those functions are for unicode support, you must add the option/unicode.c file. Are you sure though that you need unicode? Maybe change _LFN_UNICODE and _STRF_ENCODE back to zero?

Make sure you have these:

Middlewares/Third_Party/FatFs/src/option/syscall.c

Middlewares/Third_Party/FatFs/src/option/unicode.c

Also possible to review docs, and "grep" the libraries to find the files required for linkage to complete.

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

Hello All,

Thank You for Your Response .

As per your suggestion i checked for the "sycall.c" and "unicode.c" files on the path "Middlewares/Third_Party/FatFs/src/option/", I was able to find syscall.c but i do not have "unicode.c" on the above mentioned path.

Please help me with how to find this unicode file and link it with my Project.

Also possible to review docs, and "grep" the libraries to find the files required for linkage to complete.

Sorry but i didn't understand the above Comment, Can please explain a little, also is there any library which i am missing out and need to download and link.

Please help at the earliest

Thanks and Regards

Utkarash

>> with "STM32Cube FW_F7 V1.9.0" firmware package.

That's some antiquated release

STM32Cube_FW_F7_V1.15.0\Middlewares\Third_Party\FatFs\src\option\unicode.c

STM32Cube_FW_F7_V1.9.0\Middlewares\Third_Party\FatFs\src\option\unicode.c

Perhaps you're overly dependent on CubeMX to copy a local instantiation into your project, if that's the case go manually fetch the files from the CubeF7 repository trees.

>>Sorry but i didn't understand the above Comment, Can please explain a little, also is there any library which i am missing out and need to download and link.

GREP is a UNIX/LINUX tool for finding things in files, it is a metaphor for going looking for stuff in the places where it might reasonably be found. Consider using a File Manager or similar tool to search files, it doesn't have to be a hunt-n-peck operation with you manually digging through files and directories, computers are good at automating such activities. For example looking at ALL the .C and .H files in the CubeF7 for "ff_convert", or perhaps limiting the search to the Middlewares tree.

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