6 years ago.

LocalFileSystem For NUCLEO-F746GZ not work

NUCLEO-F746GZ File System Hi,

Is there a way to access the file system in NUCLEO family? I would hope to save some temporary files by using standard C file input/output functions, such as FILE *fin = fopen(...), fprintf(), etc. I've found this so far:

https://developer.mbed.org/handbook/LocalFileSystem

I imported the sample code, and update the mbed.h library, but the compiler complains that it cannot find LocalFileSystem identifier. Is there a way to access local file system over NUCLEO-F746GZ?

  1. Repost

1 Answer

6 years ago.

LocalFileSystem works only on LPC1768 and LPC11U24.

Using an SD card with SDFileSystem might work for you.

Accepted Answer

Since you'd like to save just some temporary files another option is to use a RAM disk:

#include "mbed.h"
#include "FATFileSystem.h"
#include "HeapBlockDevice.h"
#include "errno.h"

Serial          pc(USBTX, USBRX);
HeapBlockDevice bd(192 * 512, 512); // 192 * 512 bytes with a block size of 512 bytes
FATFileSystem   fs("fs");           // FAT file sytem

/**
* @brief
* @note
* @param
* @retval
*/
int main()
{
    // Try to format the filesystem.
    pc.printf("Formatting the filesystem... \r\n");

    int err = FATFileSystem::format(&bd, 512);
    pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));

    if (err)
        return err;

    // Try to mount the filesystem.
    pc.printf("Mounting the filesystem... \r\n");
    err = fs.mount(&bd);
    pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));

    if (err)
        return err;

    // Open a file.
    pc.printf("Opening \"/fs/test.txt\"... \r\n");

    FILE*   fp = fopen("/fs/test.txt", "r+");
    pc.printf("%s\r\n", (!fp ? "Failed :(\r\n" : "OK\r\n"));

    if (!fp)
    {
        // Create the test file if it doesn't exist yet.
        pc.printf("No file found, creating a new one...\r\n");
        fp = fopen("/fs/test.txt", "w+");
        pc.printf("%s\r\n", (!fp ? "Failed :(" : "OK"));
        if (!fp)
            error("error: %s (%d)\r\n", strerror(errno), -errno);

        for (int i = 0; i < 10; i++)
        {
            pc.printf("\rWriting numbers (%d/%d)... ", i, 10);
            err = fprintf(fp, "    %d\n", i);
            if (err < 0)
            {
                pc.printf("Fail :(\r\n");
                error("error: %s (%d)\n", strerror(errno), -errno);
            }
        }

        pc.printf("\rWriting numbers (%d/%d)... OK\r\n", 10, 10);

        pc.printf("Closing file...");
        fclose(fp);
        printf(" done.\r\n");
    }

    while (1)
    { }
}

NOTE: The minimum size of the HeapBlockDevice required by the FAT file system was 192 * 512 Bytes = 96 kB.

posted by Zoltan Hudak 04 Apr 2018

I imported SDFileSystem library to my program. It have an error when compiled. I use Nucleo STM32f746zg board and my source code i use MBED-OS (finally version)

ERROR is : Error: Class "FATFileSystem" has no member "_ffs" in "SDFileSystem/FATFileSystem/ChaN/diskio.cpp", Line: 25, Col: 37 I fix it : File path : SDFileSystem\ChaN\diskio.cpp line:12 #include "FATFileSystem.h" -> #include "../FatFileSystem.h"

and I have an error again : Error: Identifier "_VOLUMES" is undefined in "SDFileSystem_Warning_Fixed/FATFileSystem/ChaN/../FATFileSystem.h", Line: 41, Col: 34

How to fix it? Help me please.

Sorry for English language

posted by Teerawat Khamsat 06 Apr 2018

I think the SDFileSystem was written for mbed os-2. With mbed-os (aka mbed os-5) you should import the https://github.com/ARMmbed/sd-driver/ into your project and remove SDFileSystem. Then you can test it as below:

#include "mbed.h"
#include "SDBlockDevice.h"
#include "FATFileSystem.h"
#include "errno.h"
 
Serial              pc(USBTX, USBRX);
SDBlockDevice       bd(p5, p6, p7, p8); // SD card SPI driver pins: mosi, miso, sclk, cs
FATFileSystem       fs("sd");           // FAT file sytem
 
#define USE_DHCP
 
/**
 * @brief
 * @note
 * @param
 * @retval
 */
int main()
{
    // Try to mount the filesystem.
    pc.printf("Mounting the filesystem... ");
 
    int err = fs.mount(&bd);
    pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
    if (err)
        return err;
 
    // Open a file.
    pc.printf("Opening file '/sd/test.txt'... ");
 
    FILE*   fp = fopen("/sd/test.txt", "w+");
    pc.printf("%s\r\n", (!fp ? "Failed :(\r\n" : "OK\r\n"));
 
    if (!fp)
    {
        // Create the test file if it doesn't exist
        pc.printf("No file found, creating a new oine...\r\n");
        fp = fopen("/sd/test.txt", "w+");
        pc.printf("%s\r\n", (!fp ? "Failed :(" : "OK"));
        if (!fp)
        {
            error("error: %s (%d)\r\n", strerror(errno), -errno);
            return errno;
        }
    }
    
    for (int i = 0; i < 10; i++)
    {
        pc.printf("Writing numbers (%d/%d)... ", i, 10);
        err = fprintf(fp, "    %d\r\n", i);
        if (err < 0)
        {
            pc.printf("Fail :(\r\n");
            error("error: %s (%d)\r\n", strerror(errno), -errno);
            return errno;
        }
        else
            pc.printf("OK\r\n");
    }
 
    pc.printf("Writing numbers (%d/%d)... OK\r\n\r\n", 10, 10);
    
    err = fclose(fp);
    pc.printf("Closing file '/sd/test.txt'... ");
    pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
    if (err)
      return err;
  
    while (1)
    { }
}

See the mbed-os storage overview documentation for more details.

NOTE: Please note that there is known bug when using SD card with high frequency boards (most like also with yours). Until it's fixed by the mbed/STM team you can give the RAM disk a try.

posted by Zoltan Hudak 06 Apr 2018

It's work. Thank you so much.

posted by Teerawat Khamsat 18 Apr 2018