From 630c4a0474c2453791c00bfe20298196473c9636 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=2E=20David=20Ib=C3=A1=C3=B1ez?= Date: Tue, 20 Sep 2022 09:52:29 +0200 Subject: [PATCH] boards/remote-revb: define default MTD device --- boards/remote-revb/Kconfig | 8 ++++++++ boards/remote-revb/Makefile.dep | 10 ++++++++++ boards/remote-revb/Makefile.features | 1 + boards/remote-revb/board.c | 29 ++++++++++++++++++++++++++++ boards/remote-revb/include/board.h | 7 +++++++ 5 files changed, 55 insertions(+) diff --git a/boards/remote-revb/Kconfig b/boards/remote-revb/Kconfig index 5fccd45823..690112b812 100644 --- a/boards/remote-revb/Kconfig +++ b/boards/remote-revb/Kconfig @@ -14,5 +14,13 @@ config BOARD_REMOTE_REVB select HAS_ARDUINO select HAVE_SAUL_ADC select HAVE_SAUL_GPIO + select HAS_SDCARD_SPI + + select HAVE_MTD_SDCARD + select HAVE_SDCARD_SPI + + select MODULE_FATFS_VFS if MODULE_VFS_DEFAULT + select MODULE_MTD if MODULE_VFS_DEFAULT + select MODULE_SDCARD_SPI if MODULE_MTD source "$(RIOTBOARD)/common/remote/Kconfig" diff --git a/boards/remote-revb/Makefile.dep b/boards/remote-revb/Makefile.dep index c2635c1556..e3e6879a63 100644 --- a/boards/remote-revb/Makefile.dep +++ b/boards/remote-revb/Makefile.dep @@ -1,3 +1,13 @@ USEMODULE += boards_common_remote +ifneq (,$(filter mtd,$(USEMODULE))) + USEMODULE += mtd_sdcard +endif + +# default to using fatfs on SD card +ifneq (,$(filter vfs_default,$(USEMODULE))) + USEMODULE += fatfs_vfs + USEMODULE += mtd +endif + include $(RIOTBOARD)/common/remote/Makefile.dep diff --git a/boards/remote-revb/Makefile.features b/boards/remote-revb/Makefile.features index 2a5c839637..85a55f8ecf 100644 --- a/boards/remote-revb/Makefile.features +++ b/boards/remote-revb/Makefile.features @@ -1,3 +1,4 @@ include $(RIOTBOARD)/common/remote/Makefile.features FEATURES_PROVIDED += arduino +FEATURES_PROVIDED += sdcard_spi diff --git a/boards/remote-revb/board.c b/boards/remote-revb/board.c index 608ad45fac..bc2765b299 100644 --- a/boards/remote-revb/board.c +++ b/boards/remote-revb/board.c @@ -24,6 +24,35 @@ #include "cpu.h" #include "fancy_leds.h" +#if defined(MODULE_MTD_SDCARD) +#include "mtd_sdcard.h" +#include "sdcard_spi.h" +#include "sdcard_spi_params.h" + +#if defined(MODULE_FATFS_VFS) +#include "fs/fatfs.h" +#include "vfs_default.h" +#endif + +/* this is provided by the sdcard_spi driver see drivers/sdcard_spi/sdcard_spi.c */ +extern sdcard_spi_t sdcard_spi_devs[ARRAY_SIZE(sdcard_spi_params)]; + +mtd_sdcard_t mtd_sdcard_dev = { + .base = { + .driver = &mtd_sdcard_driver, + }, + .sd_card = &sdcard_spi_devs[0], + .params = &sdcard_spi_params[0] +}; + +mtd_dev_t *mtd0 = (mtd_dev_t *)&mtd_sdcard_dev; + +#if IS_USED(MODULE_FATFS_VFS) +VFS_AUTO_MOUNT(fatfs, VFS_MTD(mtd_sdcard_dev), VFS_DEFAULT_SD(0), 0); +#endif /* MODULE_FATFS_VFS */ + +#endif /* MODULE_MTD_SDCARD */ + /** * @brief Initialize the boards on-board LEDs * diff --git a/boards/remote-revb/include/board.h b/boards/remote-revb/include/board.h index 239f833e12..d89dfc9ce4 100644 --- a/boards/remote-revb/include/board.h +++ b/boards/remote-revb/include/board.h @@ -23,6 +23,7 @@ #define BOARD_H #include "cpu.h" +#include "mtd.h" #include "board_common.h" #ifdef __cplusplus @@ -122,6 +123,12 @@ #define SDCARD_SPI_PARAM_POWER_AH false /** @} */ +/** Default MTD device */ +#define MTD_0 mtd0 + +/** mtd flash emulation device */ +extern mtd_dev_t *mtd0; + #ifdef __cplusplus } /* end extern "C" */ #endif