From c6ba2c13c799dcb18b53aaf63978925473cab7ce Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Tue, 24 Dec 2019 10:52:09 -0600 Subject: [PATCH] [BACKPORT] STM32F7 and STM32H7 SDMMC internal pull up usage fixed Code was flawed in that the Pins are defined with the pullups in the definition. Since there are no alterntes pins there is no way to remove them. So not enabling the CONFIG pull up did nothing as did enabling them. Code also ignored the use of D0 for ready detection causing 3X+ the chatter. This is now a compile time feature as there was no reason for it to be a run time. It wasted both flash and ram. --- arch/arm/src/stm32f7/stm32_sdmmc.c | 54 +++++++++++++++--------------- arch/arm/src/stm32h7/stm32_sdmmc.c | 50 +++++++++++++++------------ 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/arch/arm/src/stm32f7/stm32_sdmmc.c b/arch/arm/src/stm32f7/stm32_sdmmc.c index d5b02ddc593..8ef2768293a 100644 --- a/arch/arm/src/stm32f7/stm32_sdmmc.c +++ b/arch/arm/src/stm32f7/stm32_sdmmc.c @@ -171,6 +171,18 @@ # undef CONFIG_CONFIG_STM32F7_SDMMC_XFRDEBUG #endif +#ifdef CONFIG_SDMMC1_SDIO_PULLUP +# define SDMMC1_SDIO_PULL(g) (((g) & ~GPIO_PUPD_MASK) | GPIO_PULLUP) +#else +# define SDMMC1_SDIO_PULL(g) (((g) & ~GPIO_PUPD_MASK) | GPIO_FLOAT) +#endif + +#ifdef CONFIG_SDMMC2_SDIO_PULLUP +# define SDMMC2_SDIO_PULL(g) (((g) & ~GPIO_PUPD_MASK) | GPIO_PULLUP) +#else +# define SDMMC2_SDIO_PULL(g) (((g) & ~GPIO_PUPD_MASK) | GPIO_FLOAT) +#endif + /* Friendly CLKCR bit re-definitions ****************************************/ #define STM32_CLKCR_RISINGEDGE (0) @@ -423,7 +435,6 @@ struct stm32_dev_s /* Misc */ - uint32_t pullup; /* GPIO pull-up option */ uint32_t blocksize; /* Current block size */ }; @@ -640,7 +651,7 @@ struct stm32_dev_s g_sdmmcdev1 = .base = STM32_SDMMC1_BASE, .nirq = STM32_IRQ_SDMMC1, #ifdef CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE - .d0_gpio = GPIO_SDMMC1_D0, + .d0_gpio = SDMMC1_SDIO_PULL(GPIO_SDMMC1_D0), #endif #ifdef CONFIG_STM32F7_SDMMC1_DMAPRIO .dmapri = CONFIG_STM32F7_SDMMC1_DMAPRIO, @@ -654,12 +665,6 @@ struct stm32_dev_s g_sdmmcdev1 = #endif .do_sdio_card = NULL, #endif - -#ifdef CONFIG_SDMMC1_SDIO_PULLUP - .pullup = GPIO_PULLUP, -#else - .pullup = 0, -#endif }; #endif @@ -708,7 +713,7 @@ struct stm32_dev_s g_sdmmcdev2 = .base = STM32_SDMMC2_BASE, .nirq = STM32_IRQ_SDMMC2, #ifdef CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE - .d0_gpio = GPIO_SDMMC2_D0, + .d0_gpio = SDMMC2_SDIO_PULL(GPIO_SDMMC2_D0), #endif #ifdef CONFIG_STM32F7_SDMMC2_DMAPRIO .dmapri = CONFIG_STM32F7_SDMMC2_DMAPRIO, @@ -722,12 +727,6 @@ struct stm32_dev_s g_sdmmcdev2 = #endif .do_sdio_card = NULL, #endif - -#ifdef CONFIG_SDMMC2_SDIO_PULLUP - .pullup = GPIO_PULLUP, -#else - .pullup = 0, -#endif }; #endif /* Register logging support */ @@ -898,8 +897,9 @@ static void stm32_configwaitints(struct stm32_dev_s *priv, uint32_t waitmask, waitmask &= ~SDIOWAIT_WRCOMPLETE; - pinset = priv->d0_gpio & (GPIO_PORT_MASK | GPIO_PIN_MASK); - pinset |= (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI); + pinset = priv->d0_gpio & (GPIO_PORT_MASK | GPIO_PIN_MASK | \ + GPIO_PUPD_MASK); + pinset |= (GPIO_INPUT | GPIO_EXTI); /* Arm the SDMMC_D Ready and install Isr */ @@ -3424,14 +3424,14 @@ FAR struct sdio_dev_s *sdio_initialize(int slotno) */ # ifndef CONFIG_SDIO_MUXBUS - stm32_configgpio(GPIO_SDMMC1_D0 | priv->pullup); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_D0)); # ifndef CONFIG_SDMMC1_WIDTH_D1_ONLY - stm32_configgpio(GPIO_SDMMC1_D1 | priv->pullup); - stm32_configgpio(GPIO_SDMMC1_D2 | priv->pullup); - stm32_configgpio(GPIO_SDMMC1_D3 | priv->pullup); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_D1)); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_D2)); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_D3)); # endif stm32_configgpio(GPIO_SDMMC1_CK); - stm32_configgpio(GPIO_SDMMC1_CMD | priv->pullup); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_CMD)); # endif } else @@ -3461,14 +3461,14 @@ FAR struct sdio_dev_s *sdio_initialize(int slotno) */ # ifndef CONFIG_SDIO_MUXBUS - stm32_configgpio(GPIO_SDMMC2_D0 | priv->pullup); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_D0)); # ifndef CONFIG_SDMMC2_WIDTH_D1_ONLY - stm32_configgpio(GPIO_SDMMC2_D1 | priv->pullup); - stm32_configgpio(GPIO_SDMMC2_D2 | priv->pullup); - stm32_configgpio(GPIO_SDMMC2_D3 | priv->pullup); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_D1)); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_D2)); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_D3)); # endif stm32_configgpio(GPIO_SDMMC2_CK); - stm32_configgpio(GPIO_SDMMC2_CMD | priv->pullup); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_CMD)); # endif } else diff --git a/arch/arm/src/stm32h7/stm32_sdmmc.c b/arch/arm/src/stm32h7/stm32_sdmmc.c index 708a0fdc12b..77b30c804cc 100644 --- a/arch/arm/src/stm32h7/stm32_sdmmc.c +++ b/arch/arm/src/stm32h7/stm32_sdmmc.c @@ -156,6 +156,18 @@ # undef CONFIG_CONFIG_STM32H7_SDMMC_XFRDEBUG #endif +#ifdef CONFIG_SDMMC1_SDIO_PULLUP +# define SDMMC1_SDIO_PULL(g) (((g) & ~GPIO_PUPD_MASK) | GPIO_PULLUP) +#else +# define SDMMC1_SDIO_PULL(g) (((g) & ~GPIO_PUPD_MASK) | GPIO_FLOAT) +#endif + +#ifdef CONFIG_SDMMC2_SDIO_PULLUP +# define SDMMC2_SDIO_PULL(g) (((g) & ~GPIO_PUPD_MASK) | GPIO_PULLUP) +#else +# define SDMMC2_SDIO_PULL(g) (((g) & ~GPIO_PUPD_MASK) | GPIO_FLOAT) +#endif + /* Define the Hardware FIFO size */ #define FIFO_SIZE_IN_BYTES 64 @@ -341,7 +353,6 @@ struct stm32_dev_s /* Misc */ - uint32_t pullup; /* GPIO pull-up option */ uint32_t blocksize; /* Current block size */ uint32_t receivecnt; /* Real count to receive */ #if !defined(CONFIG_STM32H7_SDMMC_IDMA) @@ -551,14 +562,11 @@ struct stm32_dev_s g_sdmmcdev1 = .base = STM32_SDMMC1_BASE, .nirq = STM32_IRQ_SDMMC1, #if defined(CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE) - .d0_gpio = GPIO_SDMMC1_D0, + .d0_gpio = SDMMC1_SDIO_PULL(GPIO_SDMMC1_D0), #endif #if defined(HAVE_SDMMC_SDIO_MODE) && defined(CONFIG_SDMMC1_SDIO_MODE) .sdiomode = true, #endif -#if defined(CONFIG_SDMMC1_SDIO_PULLUP) - .pullup = GPIO_PULLUP, -#endif }; #endif #if defined(CONFIG_STM32H7_SDMMC2) @@ -606,14 +614,11 @@ struct stm32_dev_s g_sdmmcdev2 = .base = STM32_SDMMC2_BASE, .nirq = STM32_IRQ_SDMMC2, #if defined(CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE) - .d0_gpio = GPIO_SDMMC2_D0, + .d0_gpio = SDMMC2_SDIO_PULL(GPIO_SDMMC2_D0), #endif #if defined(HAVE_SDMMC_SDIO_MODE) && defined(CONFIG_SDMMC2_SDIO_MODE) .sdiomode = true, #endif -#if defined(CONFIG_SDMMC2_SDIO_PULLUP) - .pullup = GPIO_PULLUP, -#endif }; #endif /* Register logging support */ @@ -774,6 +779,7 @@ static void stm32_configwaitints(struct stm32_dev_s *priv, uint32_t waitmask, /* Save all of the data and set the new interrupt mask in one, atomic * operation. */ + flags = enter_critical_section(); #if defined(CONFIG_MMCSD_SDIOWAIT_WRCOMPLETE) @@ -783,8 +789,9 @@ static void stm32_configwaitints(struct stm32_dev_s *priv, uint32_t waitmask, waitmask &= ~SDIOWAIT_WRCOMPLETE; - pinset = priv->d0_gpio & (GPIO_PORT_MASK | GPIO_PIN_MASK); - pinset |= (GPIO_INPUT | GPIO_FLOAT | GPIO_EXTI); + pinset = priv->d0_gpio & (GPIO_PORT_MASK | GPIO_PIN_MASK | \ + GPIO_PUPD_MASK); + pinset |= (GPIO_INPUT | GPIO_EXTI); /* Arm the SDMMC_D Ready and install Isr */ @@ -1423,6 +1430,7 @@ static void stm32_endtransfer(struct stm32_dev_s *priv, * None * ****************************************************************************/ + #if !defined(CONFIG_STM32H7_SDMMC_IDMA) static void stm32_sdmmc_fifo_monitor(FAR void *arg) { @@ -3294,14 +3302,14 @@ FAR struct sdio_dev_s *sdio_initialize(int slotno) */ # ifndef CONFIG_SDIO_MUXBUS - stm32_configgpio(GPIO_SDMMC1_D0 | priv->pullup); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_D0)); # ifndef CONFIG_SDMMC1_WIDTH_D1_ONLY - stm32_configgpio(GPIO_SDMMC1_D1 | priv->pullup); - stm32_configgpio(GPIO_SDMMC1_D2 | priv->pullup); - stm32_configgpio(GPIO_SDMMC1_D3 | priv->pullup); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_D1)); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_D2)); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_D3)); # endif stm32_configgpio(GPIO_SDMMC1_CK); - stm32_configgpio(GPIO_SDMMC1_CMD | priv->pullup); + stm32_configgpio(SDMMC1_SDIO_PULL(GPIO_SDMMC1_CMD)); # endif } else @@ -3327,14 +3335,14 @@ FAR struct sdio_dev_s *sdio_initialize(int slotno) */ # ifndef CONFIG_SDIO_MUXBUS - stm32_configgpio(GPIO_SDMMC2_D0 | priv->pullup); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_D0)); # ifndef CONFIG_SDMMC2_WIDTH_D1_ONLY - stm32_configgpio(GPIO_SDMMC2_D1 | priv->pullup); - stm32_configgpio(GPIO_SDMMC2_D2 | priv->pullup); - stm32_configgpio(GPIO_SDMMC2_D3 | priv->pullup); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_D1)); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_D2)); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_D3)); # endif stm32_configgpio(GPIO_SDMMC2_CK); - stm32_configgpio(GPIO_SDMMC2_CMD | priv->pullup); + stm32_configgpio(SDMMC2_SDIO_PULL(GPIO_SDMMC2_CMD)); # endif } else