Skip to main content
Explorer
October 25, 2023
Solved

Open multiple files with FileX

  • October 25, 2023
  • 4 replies
  • 4675 views

Hi all,

I am using FileX with my Nucleo-U575ZI-Q, and I want to be able to open multiple files at the same time.

Now every time I try to do this, the first file opens fine no problems but when I try to open another file (without closing the first) I get the error - FX_NOT_FOUND.

When I use FATFS there is an option in the IOC to increase the number of files allowed open (FS_LOCK). But with FileX I cannot seem to find anything in the IOC or in the headers files.

Also Google is not useful at all for any FileX related information, its very sparse!

Thanks!

    This topic has been closed for replies.
    Best answer by joeSD

    Hi all,

    Firstly the code snippet was very rough code and is not used, it was me just grabbing little bits of code to show what I was doing, there is wrapper code around all of it that I could not share.

    The solution to this problem was... a bit of user error. Turns out the system, which is a big project, was searching the SD card in folders when something else triggered and wanted to read a file from root, meaning the default directory was not as expected. Fixed by adding a "/" to the file name as it was in root.

    The big question that no one can seem to answer is, what is the max number of files allowed to be open at the same time. There is no FX_MAX_FILE_OPTIONS or filex.cfg anywhere, is filex using a dynamic approach and is limited by memory instead?

    4 replies

    ST Employee
    October 25, 2023

    Hi @joeSD 

    Thanks for reaching out :smiling_face_with_smiling_eyes:!

    Could you please share a code snippet how are you opening the files in FileX?

    regards

    Haithem.

    joeSDAuthor
    Explorer
    October 26, 2023
    static uint8_t media_memory[SECTOR_SIZE / sizeof(uint8_t)];
     
    fx_media_open(&fxmSDCard, "/", fx_stm32_sd_driver, (VOID *)FX_NULL, (VOID *) media_memory, sizeof(media_memory));
    
    FX_FILE fx_file1;
    uint32_t result = fx_file_open(&fxmSDCard, fx_file1, "test1.txt", FX_OPEN_FOR_READ);
    
    ULONG bytesRead = 0u;
    uint8_t* data = {0}
    fx_file_read(fx_file1, data, 512, &bytesRead))
    	 
    FX_FILE fx_file2;
    result = fx_file_open(&fxmSDCard, fx_file2, "test2.txt", FX_OPEN_FOR_READ);

     

    This is a rough code snippet. Opening files is fine, it just only allows me one at a time.

     

    Thanks.

    ST Employee
    October 26, 2023

    Hi @joeSD 

    Except the "uint8_t* data" declaration, I can't see any issues in this snippet.
    you may try to compare your code to the following one where two threads are accessing 2 files in R/W modes on the smae uSD.
    https://github.com/STMicroelectronics/STM32CubeU5/blob/main/Projects/STM32U575I-EV/Applications/FileX/Fx_MultiAccess/FileX/App/app_filex.c

    Hope This Helps.

    regards
    haithem.

    ST Employee
    October 26, 2023

    Hi,

    Opening a file using the full path, doesn't alter the default directory.

    you can check yourself by calling the fx_directory_default_get().

    https://learn.microsoft.com/en-us/azure/rtos/filex/chapter4#prototype-3

    Super User
    October 26, 2023

    > Except the "uint8_t* data" declaration, I can't see any issues in this snippet.

    Did you fix that line [EDIT: as mentioned by @Haithem Rahmani)?  As written in your post above, you create a pointer to uint8_t then assign zero to it, making it a NULL pointer.  The read function then tries to write data to address zero - which is NOT what you want.  What happens when that write occurs depends on your CPU and how you have memory mapped.  If 0 is mapped to RAM then you are overwriting other variables.

    joeSDAuthorAnswer
    Explorer
    November 2, 2023

    Hi all,

    Firstly the code snippet was very rough code and is not used, it was me just grabbing little bits of code to show what I was doing, there is wrapper code around all of it that I could not share.

    The solution to this problem was... a bit of user error. Turns out the system, which is a big project, was searching the SD card in folders when something else triggered and wanted to read a file from root, meaning the default directory was not as expected. Fixed by adding a "/" to the file name as it was in root.

    The big question that no one can seem to answer is, what is the max number of files allowed to be open at the same time. There is no FX_MAX_FILE_OPTIONS or filex.cfg anywhere, is filex using a dynamic approach and is limited by memory instead?