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

Merge pull request #13993 from benpicco/examples/filesystem-fatfs

examples/filesystem: add support for fatfs on SD card
This commit is contained in:
Koen Zandberg 2020-05-26 19:20:47 +02:00 committed by GitHub
commit eee5bf178d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 48 additions and 5 deletions

View File

@ -637,6 +637,7 @@ endif
ifneq (,$(filter sdcard_spi,$(USEMODULE)))
FEATURES_REQUIRED += periph_gpio
FEATURES_REQUIRED += periph_spi
DEFAULT_MODULE += auto_init_storage
USEMODULE += checksum
USEMODULE += xtimer
endif

View File

@ -26,6 +26,7 @@ USEMODULE += ps
# Use MTD (flash layer)
USEMODULE += mtd
# USEMODULE += mtd_sdcard
# Use VFS
USEMODULE += vfs
@ -33,7 +34,7 @@ USEMODULE += vfs
# Use a file system
USEMODULE += littlefs
# USEMODULE += spiffs
# USEMODULE += fatfs
# USEMODULE += fatfs_vfs
USEMODULE += constfs
# USEMODULE += devfs
@ -43,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,6 +26,29 @@
#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];
/* 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
/* Flash mount point */
#define FLASH_MOUNT_POINT "/sda"
@ -62,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:
@ -115,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);
@ -134,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);
@ -153,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);
@ -249,6 +287,8 @@ int main(void)
/* 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) {

View File

@ -1,5 +1,4 @@
USEMODULE += fatfs_diskio_mtd
DEFAULT_MODULE += auto_init_storage
USEMODULE += mtd
# Use RTC for timestamps if available