Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

examples/filesystem: Update README and increase default stack size #20439

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/filesystem/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ USEMODULE += constfs
# Enable to automatically format if mount fails
#USEMODULE += vfs_auto_format

# For LittleFS on real devices, the main stack size has to be
# increased:
CFLAGS += -DTHREAD_STACKSIZE_MAIN=2048

include $(RIOTBASE)/Makefile.include
66 changes: 59 additions & 7 deletions examples/filesystem/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,19 @@ application.

In particular, this example shows:

- how to mount/format/unmount a file system, either with spiffs, littlefs, fatfs
or constfs
- how to mount/format/unmount a file system, either with constfs for all
devices and the default fs for devices that have a filesystem mountpoint
configured by the board.
- how to open/read/write/close a file with and without newlib

In RIOT, most file systems use a `mtd` as flash interface. So to use this
example one must define `MTD_0`. `MTD_0` is a pointer to a `mtd_dev_t`
instance.
A `constfs` file system is demonstrated with two files for all targets
to demonstrate the file system functionality without an external mass
storage device.

For targets that feature an onboard external mass storage device with a
mount point configured, like the Nordic nRF52840 Development Kit
(see `boards/nrf52840dk`), the flash chip is automatically added by VFS.

This example uses `littlefs` as default file system on the whole `mtd`.
A `constfs` file system is also demonstrated with two files.

All the RIOT file systems are used through the `vfs` interface, and on most
platforms files can be accessed transparently with `open/close/read/write/...`
Expand Down Expand Up @@ -75,3 +78,52 @@ Hello World!
cat /const/hello-riot
Hello RIOT!
```

## Example on `nrf52840dk` with `littlefs`

- Build and flash `filesystem` example application of the `nrf52840dk` target

```
make BOARD=nrf52840dk -C examples/filesystem all flash
[...]
```

- When connecting to the board via the serial console, it should display the
following output:
```
main(): This is RIOT! (Version: 2024.04-devel-254-gee0f6d)
constfs mounted successfully
>
```

- The flash chip is empty by default and has to be formatted, which can be
done with the `vfs format /nvm0` command. After that it has to be mounted
with `vfs mount /nvm0`. Once the flash is formatted, it will be
automatically mounted during boot.
```
> vfs format /nvm0
> vfs mount /nvm0
> vfs df
Mountpoint Total Used Available Use%
/const 27 B 27 B 0 B 100%
/nvm0 8 MiB 8 KiB 8184 KiB 0%
```

- After formatting, the flash is empty, but new files can be created
with `tee` and printed with `cat`.

```
> ls /nvm0
./
../
total 0 files
>
> tee /nvm0/testfile "This is written to the flash!"
> cat /nvm0/testfile
This is written to the flash!>
> vfs ls /nvm0
./
../
testfile 30 B
total 1 files
```
Loading