Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cpu/sam0_common/periph: add low-level SDMMC peripheral driver for SDHC #19760

Merged
merged 7 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions boards/same54-xpro/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ config BOARD_SAME54_XPRO
select HAS_PERIPH_RTC
select HAS_PERIPH_RTT
select HAS_PERIPH_PWM
select HAS_PERIPH_SDMMC
select HAS_PERIPH_SPI
select HAS_PERIPH_TIMER
select HAS_PERIPH_UART
Expand All @@ -31,6 +32,7 @@ config BOARD_SAME54_XPRO
select HAVE_SAM0_ETH
select HAVE_SAM0_SDHC
select HAVE_MTD_AT24CXXX
select HAVE_MTD_SDMMC_DEFAULT

# This specific board requires SPI_ON_QSPI for the MTD_SPI_NOR
select MODULE_PERIPH_SPI_ON_QSPI if MODULE_MTD_SPI_NOR
6 changes: 5 additions & 1 deletion boards/same54-xpro/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ ifneq (,$(filter mtd,$(USEMODULE)))
FEATURES_REQUIRED += periph_spi_on_qspi
USEMODULE += mtd_spi_nor
USEMODULE += mtd_at24cxxx at24mac
USEMODULE += sam0_sdhc
ifeq (,$(filter sam0_sdhc,$(USEMODULE)))
benpicco marked this conversation as resolved.
Show resolved Hide resolved
# during a transition period it is possible to use the `sam0_sdhc` MTD
# driver instead of the SD/MMC MTD driver
USEMODULE += mtd_sdmmc_default
endif
endif

# enables sam0_eth as default network device
Expand Down
1 change: 1 addition & 0 deletions boards/same54-xpro/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ FEATURES_PROVIDED += periph_i2c
FEATURES_PROVIDED += periph_rtc
FEATURES_PROVIDED += periph_rtt
FEATURES_PROVIDED += periph_pwm
FEATURES_PROVIDED += periph_sdmmc
FEATURES_PROVIDED += periph_spi
FEATURES_PROVIDED += periph_timer
FEATURES_PROVIDED += periph_uart
Expand Down
2 changes: 2 additions & 0 deletions boards/same54-xpro/include/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ extern mtd_dev_t *mtd0, *mtd1, *mtd2;
#define MTD_1 mtd1
#define MTD_2 mtd2
#define MTD_NUMOF 3

#define CONFIG_SDMMC_GENERIC_MTD_OFFSET 2 /**< mtd2 is used for SD Card */
/** @} */

/**
Expand Down
12 changes: 12 additions & 0 deletions boards/same54-xpro/include/periph_conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,18 @@ static const adc_conf_chan_t adc_channels[] = {
*/
#define SDHC_DEV SDHC1 /**< The SDHC instance to use */
#define SDHC_DEV_ISR isr_sdhc1 /**< Interrupt service routing for SDHC1 */

/** SDHC devices */
static const sdhc_conf_t sdhc_config[] = {
{
.sdhc = SDHC1,
.cd = GPIO_PIN(PD, 20),
.wp = GPIO_UNDEF,
},
};

/** Number of configured SDHC devices */
#define SDHC_CONFIG_NUMOF 1
/** @} */

/**
Expand Down
4 changes: 4 additions & 0 deletions cpu/sam0_common/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cpu/sam0_common/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions cpu/sam0_common/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
19 changes: 19 additions & 0 deletions cpu/sam0_common/include/periph_cpu_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
* @{
Expand Down
3 changes: 3 additions & 0 deletions cpu/sam0_common/include/sdhc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions cpu/samd5x/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,16 @@ extern "C" {
* @{
*/
#define PM_NUM_MODES (4) /**< Backup, Hibernate, Standby, Idle */

/**
* @brief Power modes
*/
enum {
SAM0_PM_BACKUP = 0,
SAM0_PM_HIBERNATE = 1,
SAM0_PM_STANDBY = 2,
SAM0_PM_IDLE = 3,
};
/** @} */

/**
Expand Down
Loading
Loading