This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

SD Card: Creating filename using usprintf

Hello All,

  This work:

iFResult = f_open(&g_sFileObject,"data1.txt",
FA_CREATE_ALWAYS|FA_WRITE);
f_close(&g_sFileObject);

but this fails:

int filenumber=0;
static char filename[20];
usprintf(filename,"Datafile%d",filenumber++);
// TRIED THIS TOO: usprintf(&filename,"Datafile%d",filenumber++);
iFResult = f_open(&g_sFileObject,filename, FA_CREATE_ALWAYS|FA_WRITE);
f_close(&g_sFileObject);

It fails with error code 6 (FR_INVALID_NAME). Any ideas?

Thanks

Mike

  • Might be that your driver only supports short file names, ie DOS 8.3 filenames. To match the test that worked, try

    usprintf(filename,"data%d.txt",filenumber++);

  • I did change to small file names. For example:

    iFResult = f_open(&g_sFileObject,"datafile1.txt", FA_CREATE_ALWAYS|FA_WRITE);

     

    but 

    char filename[15];//or even 10

    usprintf(... etc)

    iFResult = f_open(&g_sFileObject,filename, FA_CREATE_ALWAYS|FA_WRITE);

    does not work. Even though the filename length is the same.

  • Hi Mike,

    Mike Launch said:
    It fails with error code 6 (FR_INVALID_NAME)

    Means, the given string is invalid as the path name.  

    Here is a link below, regarding format of path names.

    http://elm-chan.org/fsw/ff/en/filename.html

    -kel

  • Markel's link is doc for the current version which can support long file names. The last StellarisWare version used a very old version, "May 05, 2007  R0.04b". Don't know about TivaWare. The filename documentation is in the "Ware" source:

    \third_party\fatfs\doc\en\filename.html

    If you are using this old version then you must use 8.3 format, ie. 8 characters for the name part, 1 for the '.', and 3 for the extension part. The filename "datafile1.txt" is 9.3. It is one character too long.

  • Hi,

        Maybe, if you modify the size of fname array from the struct _FILINFO below, you can have a longer file name. I am not sure. I have not done that before.  (struct _FILINFO is at  \\third_party\fatfs\src)

    typedef struct _FILINFO {
        DWORD fsize;            /* Size */
        WORD fdate;                /* Date */
        WORD ftime;                /* Time */
        BYTE fattrib;            /* Attribute */
        char fname[8+1+3+1];    /* Name (8.3 format) */
    } FILINFO;

    -kel