Skip to content

Commit

Permalink
[BACKPORT] STM32F7 and STM32H7 SDMMC internal pull up usage fixed
Browse files Browse the repository at this point in the history
    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.
  • Loading branch information
davids5 authored and dagar committed Dec 24, 2019
1 parent a14d2ce commit c6ba2c1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
54 changes: 27 additions & 27 deletions arch/arm/src/stm32f7/stm32_sdmmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -423,7 +435,6 @@ struct stm32_dev_s

/* Misc */

uint32_t pullup; /* GPIO pull-up option */
uint32_t blocksize; /* Current block size */
};

Expand Down Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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,
Expand All @@ -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 */
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
50 changes: 29 additions & 21 deletions arch/arm/src/stm32h7/stm32_sdmmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
Expand All @@ -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 */

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit c6ba2c1

Please sign in to comment.