diff --git a/drivers/disk/Kconfig.sdmmc b/drivers/disk/Kconfig.sdmmc index 26faa7b67ff..840e7ea909d 100644 --- a/drivers/disk/Kconfig.sdmmc +++ b/drivers/disk/Kconfig.sdmmc @@ -51,6 +51,14 @@ config SDMMC_STM32 help File system on sdmmc accessed through stm32 sdmmc. +config SDMMC_STM32_HWFC + bool "STM32 SDMMC Hardware Flow control" + depends on SDMMC_STM32 + depends on SOC_SERIES_STM32H7X || SOC_SERIES_STM32F7X || SOC_SERIES_STM32L4X + help + Enable SDMMC Hardware Flow Control to avoid FIFO underrun (TX mode) and + overrun (RX mode) errors. + module = SDMMC module-str = sdmmc source "subsys/logging/Kconfig.template.log_config" diff --git a/drivers/disk/sdmmc_stm32.c b/drivers/disk/sdmmc_stm32.c index df059551998..ca2e3f966a2 100644 --- a/drivers/disk/sdmmc_stm32.c +++ b/drivers/disk/sdmmc_stm32.c @@ -287,6 +287,15 @@ static struct disk_info stm32_sdmmc_info = { .ops = &stm32_sdmmc_ops, }; +#ifdef CONFIG_SDMMC_STM32_HWFC +static void stm32_sdmmc_fc_enable(struct stm32_sdmmc_priv *priv) +{ + MMC_TypeDef *sdmmcx = priv->hsd.Instance; + + sdmmcx->CLKCR |= SDMMC_CLKCR_HWFC_EN; +} +#endif + /* * Check if the card is present or not. If no card detect gpio is set, assume * the card is present. If reading the gpio fails for some reason, assume the @@ -444,6 +453,10 @@ static int disk_stm32_sdmmc_init(const struct device *dev) k_sem_init(&priv->thread_lock, 1, 1); k_sem_init(&priv->sync, 0, 1); +#ifdef CONFIG_SDMMC_STM32_HWFC + stm32_sdmmc_fc_enable(priv); +#endif + err = stm32_sdmmc_card_detect_init(priv); if (err) { return err;