1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00
19216: drivers/mtd_sdcard: add mtd_sdcard_default module r=benpicco a=benpicco



Co-authored-by: Benjamin Valentin <benpicco@beuth-hochschule.de>
Co-authored-by: Benjamin Valentin <benjamin.valentin@ml-pa.com>
This commit is contained in:
bors[bot] 2023-02-05 20:30:12 +00:00 committed by GitHub
commit ebc869a83f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 105 additions and 175 deletions

View File

@ -14,13 +14,8 @@ 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 HAVE_MTD_SDCARD_DEFAULT
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"

View File

@ -1,7 +1,7 @@
USEMODULE += boards_common_remote
ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += mtd_sdcard
USEMODULE += mtd_sdcard_default
endif
# default to using fatfs on SD card

View File

@ -24,35 +24,6 @@
#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
*

View File

@ -23,4 +23,7 @@ config BOARD_SENSEBOX_SAMD21
select HAVE_SAUL_GPIO
select HAVE_MTD_SDCARD_DEFAULT
select MODULE_FATFS_VFS if MODULE_VFS_DEFAULT
source "$(RIOTBOARD)/common/samdx1-arduino-bootloader/Kconfig"

View File

@ -2,5 +2,15 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif
ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += mtd_sdcard_default
endif
# default to using fatfs on SD card
ifneq (,$(filter vfs_default,$(USEMODULE)))
USEMODULE += fatfs_vfs
USEMODULE += mtd
endif
# setup the samd21 arduino bootloader related dependencies
include $(RIOTBOARD)/common/samdx1-arduino-bootloader/Makefile.dep

View File

@ -13,6 +13,7 @@ FEATURES_PROVIDED += periph_usbdev
# Put other features for this board (in alphabetical order)
FEATURES_PROVIDED += highlevel_stdio
FEATURES_PROVIDED += sdcard_spi
# This configuration enables modules that are only available when using Kconfig
# module modelling

View File

@ -21,26 +21,6 @@
#include "cpu.h"
#include "board.h"
#include "periph/gpio.h"
#include "sdcard_spi_params.h"
#include "mtd_sdcard.h"
#if defined(MODULE_MTD_SDCARD) || defined(DOXYGEN)
/* 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 sensebox_sd_dev = {
.base = {
.driver = &mtd_sdcard_driver,
.page_size = MTD_SD_CARD_PAGE_SIZE,
.pages_per_sector = MTD_SD_CARD_PAGES_PER_SECTOR,
.sector_count = MTD_SD_CARD_SECTOR_COUNT
},
.sd_card = &sdcard_spi_devs[0],
.params = &sdcard_spi_params[0]
};
mtd_dev_t *mtd0 = (mtd_dev_t *)&sensebox_sd_dev;
#endif /* MODULE_MTD_SDCARD || DOXYGEN */
void board_init(void)
{

View File

@ -25,7 +25,7 @@
#include "cpu.h"
#include "periph_conf.h"
#include "periph_cpu.h"
#include "mtd_sdcard.h"
#include "mtd.h"
#ifdef __cplusplus
extern "C" {
@ -170,23 +170,6 @@ extern "C" {
extern mtd_dev_t *mtd0;
#define MTD_0 mtd0
/** @} */
/**
* @brief Attributes for the mtd_sdcard driver
* @{
*/
#ifndef MTD_SD_CARD_PAGE_SIZE
#define MTD_SD_CARD_PAGE_SIZE (512)
#endif
#ifndef MTD_SD_CARD_PAGES_PER_SECTOR
#define MTD_SD_CARD_PAGES_PER_SECTOR (128)
#endif
#ifndef MTD_SD_CARD_SECTOR_COUNT
#define MTD_SD_CARD_SECTOR_COUNT (3921920UL)
#endif
/** @} */
#endif /* MODULE_MTD_SDCARD || DOXYGEN */
#ifdef __cplusplus

View File

@ -22,6 +22,9 @@ config BOARD_SIPEED_LONGAN_NANO
select HAS_PERIPH_UART
select HAVE_SAUL_GPIO
select HAVE_MTD_SDCARD_DEFAULT
select MODULE_FATFS_VFS if MODULE_VFS_DEFAULT
config SIPEED_LONGAN_NANO_WITH_TFT
bool "Board with TFT display"
help

View File

@ -2,4 +2,14 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
USEMODULE += saul_gpio
endif
ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += mtd_sdcard_default
endif
# default to using fatfs on SD card
ifneq (,$(filter vfs_default,$(USEMODULE)))
USEMODULE += fatfs_vfs
USEMODULE += mtd
endif
include $(RIOTBOARD)/common/gd32v/Makefile.dep

View File

@ -7,5 +7,6 @@ FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
FEATURES_PROVIDED += sdcard_spi
include $(RIOTBOARD)/common/gd32v/Makefile.features

View File

@ -17,13 +17,8 @@ config BOARD_WASPMOTE_PRO
select HAS_PERIPH_SPI
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
select HAS_SDCARD_SPI
select HAVE_MTD_SDCARD
select HAVE_SDCARD_SPI
select HAVE_MTD_SDCARD_DEFAULT
select MODULE_FATFS_VFS if MODULE_VFS_DEFAULT
select MODULE_MTD if MODULE_VFS_DEFAULT
select MODULE_SDCARD_SPI if MODULE_MTD
source "$(RIOTKCONFIG)/Kconfig.ztimer_only"

View File

@ -3,7 +3,7 @@
#endif
ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += mtd_sdcard
USEMODULE += mtd_sdcard_default
endif
# default to using fatfs on SD card

View File

@ -25,35 +25,6 @@
#include "board.h"
#include "cpu.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 */
void board_init(void)
{
/* initialize UART_1 on AUX1 */

View File

@ -22,11 +22,8 @@ config BOARD_WAVESHARE_NRF52840_EVAL_KIT
select HAS_TINYUSB_DEVICE
select HAVE_SAUL_GPIO
select HAVE_SDCARD_SPI
select HAVE_MTD_SDCARD
select HAVE_MTD_SDCARD_DEFAULT
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/nrf52/Kconfig"

View File

@ -3,7 +3,7 @@ ifneq (,$(filter saul_default,$(USEMODULE)))
endif
ifneq (,$(filter mtd,$(USEMODULE)))
USEMODULE += mtd_sdcard
USEMODULE += mtd_sdcard_default
endif
# default to using fatfs on SD card

View File

@ -13,3 +13,4 @@ FEATURES_PROVIDED += periph_usbdev
FEATURES_PROVIDED += arduino
FEATURES_PROVIDED += arduino_pwm
FEATURES_PROVIDED += tinyusb_device
FEATURES_PROVIDED += sdcard_spi

View File

@ -1,60 +0,0 @@
/*
* Copyright (C) 2022 Gunar Schorcht
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @ingroup boards_waveshare_nrf52840_eval_kit
* @{
*
* @file
* @brief Board specific definitions for Waveshare nRF52840 Eval Kit
*
* @author Gunar Schorcht <gunar@schorcht.net>
*/
#if defined(MODULE_MTD_SDCARD)
#include "board.h"
#include "kernel_defines.h"
#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 */
#ifdef __cplusplus
extern "C" {
#endif
#ifdef __cplusplus
} /* end extern "C" */
#endif
/** @} */

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -0,0 +1 @@
PSEUDOMODULES += mtd_sdcard_default

View File

@ -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

View File

@ -21,7 +21,13 @@
#define VFS_DEFAULT_H
#include "board.h"
#include "modules.h"
#if IS_USED(MODULE_VFS) || DOXYGEN
#include "vfs.h"
#else
/* don't try to create auto-mounts if there is no VFS module */
#define VFS_AUTO_MOUNT(type, mtd, path, idx)
#endif
#if IS_USED(MODULE_FATFS_VFS)
#include "fs/fatfs.h"

View File

@ -26,6 +26,7 @@ LOW_MEMORY_BOARDS := \
nucleo-f302r8 \
saml10-xpro \
saml11-xpro \
sipeed-longan-nano \
spark-core \
stm32f7508-dk \
stm32mp157c-dk2 \