From 6ab9277234aa65f5d3ae864c5851c79fc0f08b22 Mon Sep 17 00:00:00 2001 From: Gunar Schorcht Date: Thu, 14 Sep 2023 13:00:54 +0200 Subject: [PATCH] cpu/sam0_common: add SDMMC support --- cpu/sam0_common/Kconfig | 4 ++++ cpu/sam0_common/Makefile.dep | 4 ++++ cpu/sam0_common/Makefile.features | 4 ++++ cpu/sam0_common/include/periph_cpu_common.h | 19 +++++++++++++++++++ cpu/sam0_common/include/sdhc.h | 3 +++ 5 files changed, 34 insertions(+) diff --git a/cpu/sam0_common/Kconfig b/cpu/sam0_common/Kconfig index 909dee87330f..2f9b333e95f7 100644 --- a/cpu/sam0_common/Kconfig +++ b/cpu/sam0_common/Kconfig @@ -17,6 +17,10 @@ config CPU_COMMON_SAM0 select HAS_PERIPH_I2C_RECONFIGURE select HAS_PERIPH_RTT_SET_COUNTER select HAS_PERIPH_RTT_OVERFLOW + select HAS_PERIPH_SDMMC_AUTO_CMD12 + select HAS_PERIPH_SDMMC_HS + select HAS_PERIPH_SDMMC_MMC + select HAS_PERIPH_SDMMC_SDHC select HAS_PERIPH_SPI_RECONFIGURE select HAS_PERIPH_SPI_GPIO_MODE select HAS_PERIPH_TIMER_PERIODIC diff --git a/cpu/sam0_common/Makefile.dep b/cpu/sam0_common/Makefile.dep index b02d4fdab8d4..e284a37a485b 100644 --- a/cpu/sam0_common/Makefile.dep +++ b/cpu/sam0_common/Makefile.dep @@ -10,6 +10,10 @@ ifneq (,$(filter periph_spi,$(USEMODULE))) USEMODULE += periph_spi_gpio_mode endif +ifneq (,$(filter periph_sdmmc,$(USEMODULE))) + USEMODULE += sdmmc_sdhc +endif + # include sam0 common periph drivers USEMODULE += sam0_common_periph diff --git a/cpu/sam0_common/Makefile.features b/cpu/sam0_common/Makefile.features index aad3211a3854..2d2035c20d0d 100644 --- a/cpu/sam0_common/Makefile.features +++ b/cpu/sam0_common/Makefile.features @@ -15,6 +15,10 @@ FEATURES_PROVIDED += periph_gpio periph_gpio_irq FEATURES_PROVIDED += periph_i2c_reconfigure FEATURES_PROVIDED += periph_rtt_set_counter FEATURES_PROVIDED += periph_rtt_overflow +FEATURES_PROVIDED += periph_sdmmc_auto_cmd12 +FEATURES_PROVIDED += periph_sdmmc_hs +FEATURES_PROVIDED += periph_sdmmc_mmc +FEATURES_PROVIDED += periph_sdmmc_sdhc FEATURES_PROVIDED += periph_spi_reconfigure FEATURES_PROVIDED += periph_spi_gpio_mode FEATURES_PROVIDED += periph_timer_periodic # implements timer_set_periodic() diff --git a/cpu/sam0_common/include/periph_cpu_common.h b/cpu/sam0_common/include/periph_cpu_common.h index ee425d144c2e..8f5e9cb47f89 100644 --- a/cpu/sam0_common/include/periph_cpu_common.h +++ b/cpu/sam0_common/include/periph_cpu_common.h @@ -907,6 +907,25 @@ typedef struct { } sam0_common_usb_config_t; #endif /* USB_INST_NUM */ +/** + * @brief SDIO/SDMMC buffer alignment for SDHC because of DMA/FIFO buffer restrictions + */ +#define SDMMC_CPU_DMA_ALIGNMENT 4 + +/** + * @brief SDIO/SDMMC buffer instantiation requirement for SDHC + */ +#define SDMMC_CPU_DMA_REQUIREMENTS __attribute__((aligned(SDMMC_CPU_DMA_ALIGNMENT))) + +/** + * @brief SDHC peripheral configuration + */ +typedef struct { + void *sdhc; /**< SDHC peripheral */ + gpio_t cd; /**< Card Detect pin (must be GPIO_UNDEF if not connected) */ + gpio_t wp; /**< Write Protect pin (must be GPIO_UNDEF if not connected) */ +} sdhc_conf_t; + /** * @name WDT upper and lower bound times in ms * @{ diff --git a/cpu/sam0_common/include/sdhc.h b/cpu/sam0_common/include/sdhc.h index 3691eb0e4082..effb633821a0 100644 --- a/cpu/sam0_common/include/sdhc.h +++ b/cpu/sam0_common/include/sdhc.h @@ -11,6 +11,9 @@ * @ingroup cpu_sam0_common * @brief SD card interface functions for sam0 class devices * + * @warning This driver is deprecated. Use the `sdmmc` driver module + * instead. You can refer to the `same54-xpro´ board as an example + * on how to use it. * @{ * * @file