mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
.. | ||
main.c | ||
Makefile | ||
README.md |
File system usage example
This is a basic example how to use a file system with RIOT in your embedded application.
This example shows:
- how to mount/format/unmount a filesystem, with spiffs, littlefs and constfs examples
- how to open/read/write/close a file with and without newlib
In RIOT, most filesystems use mtd
as flash interface. So to use this example
you must define MTD_0
. MTD_0
is a pointer to a mtd_dev_t
instance.
This example use littlefs
as default filesystem on the whole mtd
device.
A constfs
filesystem is also demonstrated with two files.
All the RIOT filesystems are used through the vfs
interface, and on most platform
they can be accessed transparently with open/close/read/write/...
functions.
With newlib, fopen/fclose/fread/fwrite/...
can also be used transparently.
The following commands are available:
format
: should be called the first time only, it will format themtd
device with the comfigured filesystemmount
: mount the filesystem on the configured mount point (default is/sda
but it can be configured withFLASH_MOUNT_POINT
define). Theconstfs
filesystem is mounted automatically when the application startsumount
: unmount/sda
cat <file>
: similarly to unixcat
unix command, it prints the given<file>
on stdouttee <file> <str>
: similarly totee
unix command, it writes<str>
in<file>
Apart from these commands, the default vfs
commands can be used, for instance:
vfs df
: shows all mountpoints and used/available memoryvfs ls <path>
: list files