From a89abd5eac32e9c81cf150d1cdb9529d03fd411c Mon Sep 17 00:00:00 2001 From: Armando Date: Wed, 6 Nov 2024 12:10:58 +0800 Subject: [PATCH] example(sdmmc): support hs and uhs1 sdr50/ddr50 --- .../storage/sd_card/sdmmc/main/Kconfig.projbuild | 16 ++++++++++++++++ .../sd_card/sdmmc/main/sd_card_example_main.c | 14 ++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/examples/storage/sd_card/sdmmc/main/Kconfig.projbuild b/examples/storage/sd_card/sdmmc/main/Kconfig.projbuild index 70449a8e39..d85180bbbc 100644 --- a/examples/storage/sd_card/sdmmc/main/Kconfig.projbuild +++ b/examples/storage/sd_card/sdmmc/main/Kconfig.projbuild @@ -28,6 +28,22 @@ menu "SD/MMC Example Configuration" bool "1 line (D0)" endchoice + choice EXAMPLE_SDMMC_SPEED_MODE + prompt "SD/MMC speed mode" + default EXAMPLE_SDMMC_SPEED_DS + + config EXAMPLE_SDMMC_SPEED_DS + bool "Default Speed" + config EXAMPLE_SDMMC_SPEED_HS + bool "High Speed" + config EXAMPLE_SDMMC_SPEED_UHS_I_SDR50 + bool "UHS-I SDR50 (100 MHz, 50 MB/s)" + depends on SOC_SDMMC_UHS_I_SUPPORTED + config EXAMPLE_SDMMC_SPEED_UHS_I_DDR50 + bool "UHS-I DDR50 (50 MHz, 50 MB/s)" + depends on SOC_SDMMC_UHS_I_SUPPORTED + endchoice + if SOC_SDMMC_USE_GPIO_MATRIX config EXAMPLE_PIN_CMD diff --git a/examples/storage/sd_card/sdmmc/main/sd_card_example_main.c b/examples/storage/sd_card/sdmmc/main/sd_card_example_main.c index 6821d05fb2..9946e6d947 100644 --- a/examples/storage/sd_card/sdmmc/main/sd_card_example_main.c +++ b/examples/storage/sd_card/sdmmc/main/sd_card_example_main.c @@ -24,6 +24,7 @@ static const char *TAG = "example"; #define MOUNT_POINT "/sdcard" +#define EXAMPLE_IS_UHS1 (CONFIG_EXAMPLE_SDMMC_SPEED_UHS_I_SDR50 || CONFIG_EXAMPLE_SDMMC_SPEED_UHS_I_DDR50) #ifdef CONFIG_EXAMPLE_DEBUG_PIN_CONNECTIONS const char* names[] = {"CLK", "CMD", "D0", "D1", "D2", "D3"}; @@ -128,6 +129,16 @@ void app_main(void) // For setting a specific frequency, use host.max_freq_khz (range 400kHz - 40MHz for SDMMC) // Example: for fixed frequency of 10MHz, use host.max_freq_khz = 10000; sdmmc_host_t host = SDMMC_HOST_DEFAULT(); +#if CONFIG_EXAMPLE_SDMMC_SPEED_HS + host.max_freq_khz = SDMMC_FREQ_HIGHSPEED; +#elif CONFIG_EXAMPLE_SDMMC_SPEED_UHS_I_SDR50 + host.slot = SDMMC_HOST_SLOT_0; + host.max_freq_khz = SDMMC_FREQ_SDR50; + host.flags &= ~SDMMC_HOST_FLAG_DDR; +#elif CONFIG_EXAMPLE_SDMMC_SPEED_UHS_I_DDR50 + host.slot = SDMMC_HOST_SLOT_0; + host.max_freq_khz = SDMMC_FREQ_DDR50; +#endif // For SoCs where the SD power can be supplied both via an internal or external (e.g. on-board LDO) power supply. // When using specific IO pins (which can be used for ultra high-speed SDMMC) to connect to the SD card @@ -149,6 +160,9 @@ void app_main(void) // This initializes the slot without card detect (CD) and write protect (WP) signals. // Modify slot_config.gpio_cd and slot_config.gpio_wp if your board has these signals. sdmmc_slot_config_t slot_config = SDMMC_SLOT_CONFIG_DEFAULT(); +#if EXAMPLE_IS_UHS1 + slot_config.flags |= SDMMC_SLOT_FLAG_UHS1; +#endif // Set bus width to use: #ifdef CONFIG_EXAMPLE_SDMMC_BUS_WIDTH_4