Skip to content

Commit

Permalink
cpu/stm32/periph: add SDMMC support for F2/F4/F7/L4
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Jun 24, 2023
1 parent 9ea2270 commit 458f5bc
Show file tree
Hide file tree
Showing 14 changed files with 981 additions and 20 deletions.
6 changes: 6 additions & 0 deletions cpu/stm32/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,10 @@ ifneq (,$(filter periph_vbat,$(USEMODULE)))
FEATURES_REQUIRED += periph_adc
endif

ifneq (,$(filter periph_sdmmc,$(FEATURES_USED)))
FEATURES_REQUIRED += periph_gpio_irq
FEATURES_REQUIRED += periph_sdmmc_clk
FEATURES_OPTIONAL += periph_dma
endif

include $(RIOTCPU)/cortexm_common/Makefile.dep
5 changes: 5 additions & 0 deletions cpu/stm32/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ ifneq (,$(filter $(CPU_FAM),f2 f4 f7 g4 l0 l4 l5 u5 wb))
endif
endif

ifneq (,$(filter $(CPU_FAM),f2 f4 f7 l4))
FEATURES_PROVIDED += periph_sdmmc_clk
FEATURES_PROVIDED += periph_sdmmc_auto_clk
endif

ifneq (,$(filter $(CPU_FAM),f2 f4 f7 g4 l1 l4 mp1))
FEATURES_PROVIDED += cortexm_mpu
endif
Expand Down
5 changes: 3 additions & 2 deletions cpu/stm32/include/clk/f2f4f7/cfg_clock_default_100.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ extern "C" {
#endif
#endif
#ifndef CONFIG_CLOCK_PLL_N
#if IS_USED(MODULE_PERIPH_USBDEV_CLK) && defined(CPU_LINE_STM32F411xE)
#if (IS_USED(MODULE_PERIPH_USBDEV_CLK) || IS_USED(MODULE_PERIPH_SDMMC_CLK)) && \
defined(CPU_LINE_STM32F411xE)
#if IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE == MHZ(8))
#define CONFIG_CLOCK_PLL_N (96)
#elif IS_ACTIVE(CONFIG_BOARD_HAS_HSE) && (CONFIG_CLOCK_HSE == MHZ(25))
Expand All @@ -60,7 +61,7 @@ extern "C" {
#else
#define CONFIG_CLOCK_PLL_N (50)
#endif
#endif /* MODULE_PERIPH_USBDEV_CLK */
#endif /* MODULE_PERIPH_USBDEV_CLK || MODULE_PERIPH_SDMMC_CLK */
#endif
#ifndef CONFIG_CLOCK_PLL_P
#define CONFIG_CLOCK_PLL_P (2)
Expand Down
6 changes: 3 additions & 3 deletions cpu/stm32/include/clk/f2f4f7/cfg_clock_default_180.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ extern "C" {
#endif
#endif
#ifndef CONFIG_CLOCK_PLL_N
#if IS_USED(MODULE_PERIPH_USBDEV_CLK) && \
#if (IS_USED(MODULE_PERIPH_USBDEV_CLK) || IS_USED(MODULE_PERIPH_SDMMC_CLK)) && \
(defined(CPU_LINE_STM32F405xx) || defined(CPU_LINE_STM32F407xx) || \
defined(CPU_LINE_STM32F415xx) || defined(CPU_LINE_STM32F417xx) || \
defined(CPU_LINE_STM32F427xx) || defined(CPU_LINE_STM32F429xx) || \
Expand All @@ -68,13 +68,13 @@ extern "C" {
#else
#define CONFIG_CLOCK_PLL_N (90)
#endif
#endif /* MODULE_PERIPH_USBDEV_CLK */
#endif /* MODULE_PERIPH_USBDEV_CLK || MODULE_PERIPH_SDMMC_CLK */
#endif
#ifndef CONFIG_CLOCK_PLL_P
#define CONFIG_CLOCK_PLL_P (2)
#endif
#ifndef CONFIG_CLOCK_PLL_Q
#if IS_USED(MODULE_PERIPH_USBDEV_CLK) && \
#if (IS_USED(MODULE_PERIPH_USBDEV_CLK) || IS_USED(MODULE_PERIPH_SDMMC_CLK)) && \
(defined(CPU_LINE_STM32F405xx) || defined(CPU_LINE_STM32F407xx) || \
defined(CPU_LINE_STM32F415xx) || defined(CPU_LINE_STM32F417xx) || \
defined(CPU_LINE_STM32F427xx) || defined(CPU_LINE_STM32F429xx) || \
Expand Down
95 changes: 95 additions & 0 deletions cpu/stm32/include/periph/cpu_sdmmc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* Copyright (C) 2023 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 cpu_stm32
* @{
*
* @file
* @brief CPU specific definitions for SDIO/SDMMC for the STM32 family
*
* @author Gunar Schorcht <gunar@schorcht.net>
*/

#ifndef PERIPH_CPU_SDMMC_H
#define PERIPH_CPU_SDMMC_H

#include <stdint.h>

#include "periph/cpu_dma.h"
#include "periph/cpu_gpio.h"

#ifdef __cplusplus
extern "C" {
#endif

/* For F1, F2, F4 and L1 the SDMMC interface is called SDIO, define used
* symbols for source code compatibility */
#if !defined(SDMMC1) && !DOXYGEN
#define SDMMC_TypeDef SDIO_TypeDef
#endif

/**
* @brief SDIO/SDMMC buffers alignment because of STM32 DMA/FIFO restrictions
*/
#define SDMMC_CPU_DMA_ALIGNMENT 4

/**
* @brief SDUI/SDMMC buffer instantiation requirement for STM32
*/
#define SDMMC_CPU_DMA_REQUIREMENTS __attribute__((aligned(SDMMC_CPU_DMA_ALIGNMENT)))

/**
* @brief SDIO/SDMMC pin structure for STM32
*/
typedef struct {
gpio_t pin; /**< GPIO pin */
#ifndef CPU_FAM_STM32F1
gpio_af_t af; /**< GPIO alternate function */
#endif
} sdmmc_pin_t;

/**
* @brief SDIO/SDMCC peripheral configuration for STM32
*
* To use 1-bit bus width, define `dat1` to `dat3` as `GPIO_UNDEF`. 8-bit bus
* width with `dat4` to `dat7` is only available if the board provides
* feature `periph_sdmmc_8bit`.
*/
typedef struct {
SDMMC_TypeDef *dev; /**< SDIO/SDMMC device */
uint8_t bus; /**< APB/AHB bus used for SDIO/SDMMC peripheral */
uint32_t rcc_mask; /**< Bit mask in clock enable register */
gpio_t cd; /**< Card Detect pin (GPIO_UNDEF if not used) */
int cd_active; /**< Card Detect pin active level */
gpio_mode_t cd_mode; /**< Card Detect pin mode */
sdmmc_pin_t clk; /**< Clock pin */
sdmmc_pin_t cmd; /**< Command/Response pin */
sdmmc_pin_t dat0; /**< Data Line Bit 0 pin */
sdmmc_pin_t dat1; /**< Data Line Bit 1 pin */
sdmmc_pin_t dat2; /**< Data Line Bit 2 pin */
sdmmc_pin_t dat3; /**< Data Line Bit 3 pin */
#if IS_USED(MODULE_PERIPH_SDMMC_8BIT)
sdmmc_pin_t dat4; /**< Data Line Bit 4 pin */
sdmmc_pin_t dat5; /**< Data Line Bit 5 pin */
sdmmc_pin_t dat6; /**< Data Line Bit 6 pin */
sdmmc_pin_t dat7; /**< Data Line Bit 7 pin */
#endif
#if IS_USED(MODULE_PERIPH_DMA)
dma_t dma; /**< Logical DMA stream used for SDIO/SDMMC */
uint8_t dma_chan; /**< DMA channel used for SDIO/SDMMC */
#endif
uint8_t irqn; /**< SDIO/SDMMC interrupt number */
} sdmmc_conf_t;

#ifdef __cplusplus
}
#endif

#endif /* PERIPH_CPU_SDMMC_H */
/** @} */
1 change: 1 addition & 0 deletions cpu/stm32/include/periph_cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
#include "periph/cpu_pm.h"
#include "periph/cpu_pwm.h"
#include "periph/cpu_qdec.h"
#include "periph/cpu_sdmmc.h"
#include "periph/cpu_spi.h"
#include "periph/cpu_timer.h"
#include "periph/cpu_uart.h"
Expand Down
2 changes: 2 additions & 0 deletions cpu/stm32/kconfigs/f2/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ config CPU_FAM_F2
select HAS_PERIPH_GPIO_LL_IRQ_LEVEL_TRIGGERED_LOW
select HAS_PERIPH_HWRNG
select HAS_PERIPH_RTC_MEM
select HAS_PERIPH_SDMMC_AUTO_CLK
select HAS_PERIPH_SDMMC_CLK
select HAS_PERIPH_VBAT
select HAS_PERIPH_WDT
select HAS_BOOTLOADER_STM32
Expand Down
2 changes: 2 additions & 0 deletions cpu/stm32/kconfigs/f4/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ config CPU_FAM_F4
select HAS_PERIPH_GPIO_LL_IRQ_LEVEL_TRIGGERED_HIGH
select HAS_PERIPH_GPIO_LL_IRQ_LEVEL_TRIGGERED_LOW
select HAS_PERIPH_RTC_MEM
select HAS_PERIPH_SDMMC_AUTO_CLK
select HAS_PERIPH_SDMMC_CLK
select HAS_PERIPH_VBAT
select HAS_PERIPH_WDT
select HAS_BOOTLOADER_STM32
Expand Down
2 changes: 2 additions & 0 deletions cpu/stm32/kconfigs/f7/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ config CPU_FAM_F7
select HAS_PERIPH_GPIO_LL_IRQ_LEVEL_TRIGGERED_LOW
select HAS_PERIPH_HWRNG
select HAS_PERIPH_RTC_MEM
select HAS_PERIPH_SDMMC_AUTO_CLK
select HAS_PERIPH_SDMMC_CLK
select HAS_PERIPH_VBAT
select HAS_PERIPH_WDT
select HAS_BOOTLOADER_STM32
Expand Down
2 changes: 2 additions & 0 deletions cpu/stm32/kconfigs/l4/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ config CPU_FAM_L4
select HAS_PERIPH_GPIO_LL_IRQ_LEVEL_TRIGGERED_LOW
select HAS_PERIPH_HWRNG
select HAS_PERIPH_RTC_MEM
select HAS_PERIPH_SDMMC_AUTO_CLK
select HAS_PERIPH_SDMMC_CLK
select HAS_PERIPH_VBAT
select HAS_PERIPH_WDT
select HAS_BOOTLOADER_STM32
Expand Down
13 changes: 13 additions & 0 deletions cpu/stm32/periph/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ config MODULE_PERIPH
select MODULE_USBDEV_SYNOPSYS_DWC2 if MODULE_PERIPH_USBDEV && CPU_LINE_STM32L4S5XX
select MODULE_USBDEV_SYNOPSYS_DWC2 if MODULE_PERIPH_USBDEV && CPU_LINE_STM32L4S7XX
select MODULE_USBDEV_SYNOPSYS_DWC2 if MODULE_PERIPH_USBDEV && CPU_LINE_STM32L4S9XX
# Special SDMMC dependencies
select MODULE_PERIPH_GPIO_IRQ if MODULE_PERIPH_SDMMC
select MODULE_PERIPH_DMA if MODULE_PERIPH_SDMMC && HAS_PERIPH_DMA
help
stm32 common peripheral code.

Expand Down Expand Up @@ -64,3 +67,13 @@ config MODULE_PERIPH_LTDC
depends on HAS_PERIPH_LTDC
help
STM32 LCD-TFT Display controller

config MODULE_PERIPH_SDMMC_CLK
bool
depends on HAS_PERIPH_SDMMC_CLK
default y if MODULE_PERIPH_SDMMC

config MODULE_PERIPH_INIT_SDMMC_CLK
bool
depends on MODULE_PERIPH_SDMMC_CLK
default y if MODULE_PERIPH_INIT
Loading

0 comments on commit 458f5bc

Please sign in to comment.