Skip to main content
scholar
Associate II
March 14, 2015
Question

read/write multiple files using fatfs

  • March 14, 2015
  • 1 reply
  • 2541 views
Posted on March 14, 2015 at 02:59

i require to open multiple files simultaneously and, read and write multiple files using stm32f4 and fatFs , as a test i used f_open with 4 different file names and file pointers but only two files got created in card at the end, and one contains data why fatfs never creates multiple files if we use f_open with different FIL pointers and different names??

as a reference following was test code

f_mount(0, &filesystem);

f_open(&file,  ''DATA.YUV'', FA_READ | FA_WRITE | FA_CREATE_ALWAYS);

f_open(&file2, ''DATA2.YUV'', FA_READ | FA_WRITE | FA_CREATE_ALWAYS);

f_open(&file3, ''DATA2.YUV'', FA_READ | FA_WRITE | FA_CREATE_ALWAYS);

f_open(&file4, ''DATA2.YUV'', FA_READ | FA_WRITE | FA_CREATE_ALWAYS);

f_write(&file, &buffer[0] , size*4, &bw);

if (bw<(size*4)) while(1);

f_write(&file2, &buffer[0] , size*4, &bw);

if (bw<(size*4)) while(1);

f_write(&file3, &buffer[0] , size*4, &bw);

if (bw<(size*4)) while(1);

f_write(&file4, &buffer[0] , size*4, &bw);

if (bw<(size*4)) while(1);

f_close(&file);

f_close(&file2);

f_close(&file3);

f_close(&file4);

if (f_mount(0, NULL) != FR_OK) {

printf(''could not close filesystem \n\r'');

}

    This topic has been closed for replies.

    1 reply

    francescatodiego
    Associate III
    March 14, 2015
    Posted on March 14, 2015 at 10:50

    f_open(&file,  ''DATA.YUV'', FA_READ | FA_WRITE | FA_CREATE_ALWAYS);

    f_open(&file2, ''

    DATA2.YUV

    '', FA_READ | FA_WRITE | FA_CREATE_ALWAYS);

    f_open(&file3, ''

    DATA2.YUV

    '', FA_READ | FA_WRITE | FA_CREATE_ALWAYS);

    f_open(&file4, ''

    DATA2.YUV

    '', FA_READ | FA_WRITE | FA_CREATE_ALWAYS);

    from

    http://elm-chan.org/fsw/ff/en/appnote.html#dup

    Duplicated File Access

    FatFs module does not support the read/write collision control of duplicated open to a file. The duplicated open is permitted only when each of open method to a file is read mode. The duplicated open with one or more write mode to a file is always prohibited, and also open file must not be renamed and deleted. A violation of these rules can cause data colluption.

    The file lock control can be enabled by _FS_LOCK option. The value of option defines the number of open objects to manage simultaneously. In this case, if any open, rename or remove that violating the file shareing rule that described above is attempted, the file function will fail with FR_LOCKED. If number of open objects, files and sub-directories, is equal to _FS_LOCK, an extra f_open/f_optndir/f_findfirst function will fail with FR_TOO_MANY_OPEN_FILES.