1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

examples/filesystem: add support for fatfs

This commit is contained in:
Benjamin Valentin 2020-05-20 11:58:46 +02:00
parent 9ada10609f
commit ccdbbfa53c
2 changed files with 35 additions and 16 deletions

View File

@ -34,7 +34,7 @@ USEMODULE += vfs
# Use a file system
USEMODULE += littlefs
# USEMODULE += spiffs
# USEMODULE += fatfs
# USEMODULE += fatfs_vfs
USEMODULE += constfs
# USEMODULE += devfs
@ -44,6 +44,8 @@ ifneq (,$(filter littlefs, $(USEMODULE)))
else ifneq (,$(filter spiffs, $(USEMODULE)))
SPIFFS_NB_FD ?= 8
CFLAGS += '-DSPIFFS_FS_FD_SPACE_SIZE=(32 * $(SPIFFS_NB_FD))'
else ifneq (,$(filter fatfs_vfs, $(USEMODULE)))
CFLAGS += -DVFS_FILE_BUFFER_SIZE=72 -DVFS_DIR_BUFFER_SIZE=44
endif
include $(RIOTBASE)/Makefile.include

View File

@ -26,18 +26,26 @@
#include "shell.h"
#include "board.h" /* MTD_0 is defined in board.h */
/* Configure MTD device for SD card if none is provided */
#if !defined(MTD_0) && MODULE_MTD_SDCARD
#include "mtd_sdcard.h"
#include "sdcard_spi.h"
#include "sdcard_spi_params.h"
#define SDCARD_SPI_NUM ARRAY_SIZE(sdcard_spi_params)
/* SD card devices are provided by auto_init_sdcard_spi */
extern sdcard_spi_t sdcard_spi_devs[SDCARD_SPI_NUM];
mtd_sdcard_t mtd_sdcard_devs[SDCARD_SPI_NUM];
/* always default to first sdcard*/
static mtd_dev_t *mtd0 = (mtd_dev_t*)&mtd_sdcard_devs[0];
/* Configure MTD device for the first SD card */
static mtd_sdcard_t mtd_sdcard_dev = {
.base = {
.driver = &mtd_sdcard_driver
},
.sd_card = &sdcard_spi_devs[0],
.params = &sdcard_spi_params[0],
};
static mtd_dev_t *mtd0 = (mtd_dev_t*)&mtd_sdcard_dev;
#define MTD_0 mtd0
#endif
@ -77,6 +85,21 @@ static spiffs_desc_t fs_desc = {
/* spiffs driver will be used */
#define FS_DRIVER spiffs_file_system
#elif defined(MODULE_FATFS_VFS)
/* include file system header */
#include "fs/fatfs.h"
/* file system specific descriptor
* as for littlefs, some fields can be changed if needed,
* this example focus on basic usage, i.e. entire memory used */
static fatfs_desc_t fs_desc;
/* provide mtd devices for use within diskio layer of fatfs */
mtd_dev_t *fatfs_mtd_devs[FF_VOLUMES];
/* fatfs driver will be used */
#define FS_DRIVER fatfs_file_system
#endif
/* this structure defines the vfs mount point:
@ -130,7 +153,7 @@ static int _mount(int argc, char **argv)
{
(void)argc;
(void)argv;
#if defined(MTD_0) && (defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS))
#if defined(MTD_0) && (defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS) || defined(MODULE_FATFS_VFS))
int res = vfs_mount(&flash_mount);
if (res < 0) {
printf("Error while mounting %s...try format\n", FLASH_MOUNT_POINT);
@ -149,7 +172,7 @@ static int _format(int argc, char **argv)
{
(void)argc;
(void)argv;
#if defined(MTD_0) && (defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS))
#if defined(MTD_0) && (defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS) || defined(MODULE_FATFS_VFS))
int res = vfs_format(&flash_mount);
if (res < 0) {
printf("Error while formatting %s\n", FLASH_MOUNT_POINT);
@ -168,7 +191,7 @@ static int _umount(int argc, char **argv)
{
(void)argc;
(void)argv;
#if defined(MTD_0) && (defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS))
#if defined(MTD_0) && (defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS) || defined(MODULE_FATFS_VFS))
int res = vfs_umount(&flash_mount);
if (res < 0) {
printf("Error while unmounting %s\n", FLASH_MOUNT_POINT);
@ -259,18 +282,12 @@ static const shell_command_t shell_commands[] = {
int main(void)
{
#if MODULE_MTD_SDCARD
for (unsigned int i = 0; i < SDCARD_SPI_NUM; i++){
mtd_sdcard_devs[i].base.driver = &mtd_sdcard_driver;
mtd_sdcard_devs[i].sd_card = &sdcard_spi_devs[i];
mtd_sdcard_devs[i].params = &sdcard_spi_params[i];
}
#endif
#if defined(MTD_0) && (defined(MODULE_SPIFFS) || defined(MODULE_LITTLEFS))
/* spiffs and littlefs need a mtd pointer
* by default the whole memory is used */
fs_desc.dev = MTD_0;
#elif defined(MTD_0) && defined(MODULE_FATFS_VFS)
fatfs_mtd_devs[fs_desc.vol_idx] = MTD_0;
#endif
int res = vfs_mount(&const_mount);
if (res < 0) {