Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
8 years, 6 months ago.
SDFileSystem functions and examples
Is there any information and simple usage examples for all the functions of SDFileSystem. For instance how to use fseek(fp, 0, SEEK_SET), fseek(fp, 0, SEEK_END) etc. Can I read/write a chunk of data in the middle of a block or only append data. I want to set a pointer to a random position in a file and read 96 bytes into a container, how would I do this. Read a complete 12K file into a container, these kind a things. Simple quickie examples.
This is a list I found in the library, I think simple example code for these functions is what I'm looking for.
FatFs module application interface
FRESULT f_mount (BYTE, FATFS*); /* Mount/Unmount a logical drive */ FRESULT f_open (FIL*, const TCHAR*, BYTE); /* Open or create a file */ FRESULT f_read (FIL*, void*, UINT, UINT*); /* Read data from a file */ FRESULT f_lseek (FIL*, DWORD); /* Move file pointer of a file object */ FRESULT f_close (FIL*); /* Close an open file object */ FRESULT f_opendir (FATFS_DIR*, const TCHAR*); /* Open an existing directory */ FRESULT f_readdir (FATFS_DIR*, FILINFO*); /* Read a directory item */ FRESULT f_stat (const TCHAR*, FILINFO*); /* Get file status */ FRESULT f_write (FIL*, const void*, UINT, UINT*); /* Write data to a file */ FRESULT f_getfree (const TCHAR*, DWORD*, FATFS**); /* Get number of free clusters on the drive */ FRESULT f_truncate (FIL*); /* Truncate file */ FRESULT f_sync (FIL*); /* Flush cached data of a writing file */ FRESULT f_unlink (const TCHAR*); /* Delete an existing file or directory */ FRESULT f_mkdir (const TCHAR*); /* Create a new directory */ FRESULT f_chmod (const TCHAR*, BYTE, BYTE); /* Change attribute of the file/dir */ FRESULT f_utime (const TCHAR*, const FILINFO*); /* Change times-tamp of the file/dir */ FRESULT f_rename (const TCHAR*, const TCHAR*); /* Rename/Move a file or directory */ FRESULT f_chdrive (BYTE); /* Change current drive */ FRESULT f_chdir (const TCHAR*); /* Change current directory */ FRESULT f_getcwd (TCHAR*, UINT); /* Get current directory */ FRESULT f_forward (FIL*, UINT(*)(const BYTE*,UINT), UINT, UINT*); /* Forward data to the stream */ FRESULT f_mkfs (BYTE, BYTE, UINT); /* Create a file system on the drive */ FRESULT f_fdisk (BYTE, const DWORD[], void*); /* Divide a physical drive into some partitions */ int f_putc (TCHAR, FIL*); /* Put a character to the file */ int f_puts (const TCHAR*, FIL*); /* Put a string to the file */ int f_printf (FIL*, const TCHAR*, ...); /* Put a formatted string to the file */ TCHAR* f_gets (TCHAR*, int, FIL*); /* Get a string from the file */
edit.....
I have found this:
http://www.cplusplus.com/reference/clibrary/cstdio/
So unless there is any 'Mbed' information, this will have to do.
1 Answer
8 years, 6 months ago.
Basically, SDFileSystem is built on top of FATFileSystem which is built on top of FatFs. Those functions you found are part of FatFs, and FATFileSystem provides some C++ objects to glue them to the C stdio library using a retarget layer buried deep within the mbed library. Ideally you should be using the C stdio API, but in practice I've found it to be slow and a memory hog. As an alternative, you can use the C++ objects in FATFileSystem directly. There's no official documentation on these, but this program should get you started:
Import programSDFileSystem_HelloWorld
A simple serial test program for the re-written SDFileSystem library.