diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index b12543d9be..fc18a5c5b0 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -23,6 +23,15 @@ config HAVE_MTD_NATIVE help Indicates that a native MTD is present. +config HAVE_MTD_SDCARD_DEFAULT + bool + imply MODULE_MTD_SDCARD if MODULE_MTD + imply MODULE_MTD_SDCARD_DEFAULT if MODULE_MTD + imply MODULE_SDCARD_SPI if MODULE_MTD + select HAS_SDCARD_SPI + help + Indicates that a sdcard MTD is present with generic configuration + config HAVE_MTD_SDCARD bool imply MODULE_MTD_SDCARD if MODULE_MTD @@ -86,6 +95,12 @@ config MODULE_MTD_MCI depends on CPU_FAM_LPC23XX select MODULE_MCI +config MODULE_MTD_SDCARD_DEFAULT + bool "Use Generic SD card configuration" + depends on MODULE_MTD_SDCARD + help + Automatically create a MTD device and mount point for the SD card. + config MODULE_MTD_SDCARD bool "MTD interface for SPI SD-Card" depends on MODULE_SDCARD_SPI diff --git a/drivers/mtd/Makefile.dep b/drivers/mtd/Makefile.dep index 5f740922fe..6c0bce41d7 100644 --- a/drivers/mtd/Makefile.dep +++ b/drivers/mtd/Makefile.dep @@ -6,6 +6,10 @@ ifneq (,$(filter mtd_at25xxx,$(USEMODULE))) USEMODULE += at25xxx endif +ifneq (,$(filter mtd_sdcard_default,$(USEMODULE))) + USEMODULE += mtd_sdcard +endif + ifneq (,$(filter mtd_sdcard,$(USEMODULE))) USEMODULE += sdcard_spi endif diff --git a/drivers/mtd_sdcard/Kconfig b/drivers/mtd_sdcard/Kconfig index e3d91253e0..3878e22e62 100644 --- a/drivers/mtd_sdcard/Kconfig +++ b/drivers/mtd_sdcard/Kconfig @@ -13,6 +13,14 @@ menuconfig KCONFIG_USEMODULE_MTD_SDCARD if KCONFIG_USEMODULE_MTD_SDCARD +config SDCARD_GENERIC_MTD_OFFSET + depends on MODULE_MTD_SDCARD_DEFAULT + int "Index of first auto-configured MTD SDcard device" + default 0 + help + If you have other MTD devices defined, set this number so that + the auto-configured SD Card(s) from mtd_sdcard_default will come after them. + config MTD_SDCARD_ERASE bool "Enable SD card erase" help diff --git a/drivers/mtd_sdcard/Makefile.include b/drivers/mtd_sdcard/Makefile.include new file mode 100644 index 0000000000..51040d0ef3 --- /dev/null +++ b/drivers/mtd_sdcard/Makefile.include @@ -0,0 +1 @@ +PSEUDOMODULES += mtd_sdcard_default diff --git a/drivers/mtd_sdcard/mtd_sdcard.c b/drivers/mtd_sdcard/mtd_sdcard.c index e302a3ee84..39136723dd 100644 --- a/drivers/mtd_sdcard/mtd_sdcard.c +++ b/drivers/mtd_sdcard/mtd_sdcard.c @@ -221,3 +221,37 @@ const mtd_desc_t mtd_sdcard_driver = { .erase_sector = mtd_sdcard_erase_sector, .power = mtd_sdcard_power, }; + +#if IS_USED(MODULE_MTD_SDCARD_DEFAULT) +#include "sdcard_spi_params.h" +#include "vfs_default.h" + +#define SDCARD_NUMOF ARRAY_SIZE(sdcard_spi_params) + +#ifndef CONFIG_SDCARD_GENERIC_MTD_OFFSET +#define CONFIG_SDCARD_GENERIC_MTD_OFFSET 0 +#endif + +#define MTD_SDCARD_DEV(n, m) \ + mtd_sdcard_t mtd_sdcard_dev ## n = { \ + .base = { \ + .driver = &mtd_sdcard_driver, \ + }, \ + .sd_card = &sdcard_spi_devs[n], \ + .params = &sdcard_spi_params[n] \ + }; \ + \ + mtd_dev_t CONCAT(*mtd, m) = (mtd_dev_t *)&mtd_sdcard_dev ## n + +#define MTD_SDCARD_DEV_FS(n, m, filesystem) \ + VFS_AUTO_MOUNT(filesystem, VFS_MTD(mtd_sdcard_dev ## n), VFS_DEFAULT_SD(n), m) + +/* this is provided by the sdcard_spi driver see drivers/sdcard_spi/sdcard_spi.c */ +extern sdcard_spi_t sdcard_spi_devs[SDCARD_NUMOF]; + +MTD_SDCARD_DEV(0, CONFIG_SDCARD_GENERIC_MTD_OFFSET); +#ifdef MODULE_FATFS_VFS +MTD_SDCARD_DEV_FS(0, CONFIG_SDCARD_GENERIC_MTD_OFFSET, fatfs); +#endif + +#endif