Browse Source

stm32/sdcard: Support 8-bit wide SDIO bus.

Signed-off-by: Damien George <damien@micropython.org>
pull/8082/head
Damien George 3 years ago
parent
commit
b26704aac5
  1. 39
      ports/stm32/sdcard.c

39
ports/stm32/sdcard.c

@ -60,6 +60,10 @@
#define STATIC_AF_SDCARD_D1 STATIC_AF_SDMMC2_D1
#define STATIC_AF_SDCARD_D2 STATIC_AF_SDMMC2_D2
#define STATIC_AF_SDCARD_D3 STATIC_AF_SDMMC2_D3
#define STATIC_AF_SDCARD_D4 STATIC_AF_SDMMC2_D4
#define STATIC_AF_SDCARD_D5 STATIC_AF_SDMMC2_D5
#define STATIC_AF_SDCARD_D6 STATIC_AF_SDMMC2_D6
#define STATIC_AF_SDCARD_D7 STATIC_AF_SDMMC2_D7
#else
#define SDIO SDMMC1
#define SDMMC_IRQHandler SDMMC1_IRQHandler
@ -75,6 +79,10 @@
#define STATIC_AF_SDCARD_D1 STATIC_AF_SDMMC1_D1
#define STATIC_AF_SDCARD_D2 STATIC_AF_SDMMC1_D2
#define STATIC_AF_SDCARD_D3 STATIC_AF_SDMMC1_D3
#define STATIC_AF_SDCARD_D4 STATIC_AF_SDMMC1_D4
#define STATIC_AF_SDCARD_D5 STATIC_AF_SDMMC1_D5
#define STATIC_AF_SDCARD_D6 STATIC_AF_SDMMC1_D6
#define STATIC_AF_SDCARD_D7 STATIC_AF_SDMMC1_D7
#endif
// The F7 & L4 series calls the peripheral SDMMC rather than SDIO, so provide some
@ -120,6 +128,10 @@
#define STATIC_AF_SDCARD_D1 STATIC_AF_SDIO_D1
#define STATIC_AF_SDCARD_D2 STATIC_AF_SDIO_D2
#define STATIC_AF_SDCARD_D3 STATIC_AF_SDIO_D3
#define STATIC_AF_SDCARD_D4 STATIC_AF_SDIO_D4
#define STATIC_AF_SDCARD_D5 STATIC_AF_SDIO_D5
#define STATIC_AF_SDCARD_D6 STATIC_AF_SDIO_D6
#define STATIC_AF_SDCARD_D7 STATIC_AF_SDIO_D7
#endif
@ -133,6 +145,13 @@
#define MICROPY_HW_SDCARD_CMD (pin_D2)
#endif
// Define a constant to select the bus width.
#if MICROPY_HW_SDCARD_BUS_WIDTH == 4
#define SDIO_BUS_WIDE_VALUE SDIO_BUS_WIDE_4B
#elif MICROPY_HW_SDCARD_BUS_WIDTH == 8
#define SDIO_BUS_WIDE_VALUE SDIO_BUS_WIDE_8B
#endif
#define PYB_SDMMC_FLAG_SD (0x01)
#define PYB_SDMMC_FLAG_MMC (0x02)
#define PYB_SDMMC_FLAG_ACTIVE (0x04)
@ -162,10 +181,16 @@ void sdcard_init(void) {
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_CK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_CK);
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_CMD, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_CMD);
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_D0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_D0);
#if MICROPY_HW_SDCARD_BUS_WIDTH == 4
#if MICROPY_HW_SDCARD_BUS_WIDTH >= 4
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_D1, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_D1);
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_D2, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_D2);
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_D3, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_D3);
#if MICROPY_HW_SDCARD_BUS_WIDTH == 8
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_D4, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_D4);
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_D5, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_D5);
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_D6, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_D6);
mp_hal_pin_config_alt_static(MICROPY_HW_SDCARD_D7, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDCARD_D7);
#endif
#endif
// configure the SD card detect pin
@ -252,9 +277,9 @@ STATIC HAL_StatusTypeDef sdmmc_init_sd(void) {
mp_hal_delay_ms(50);
}
#if MICROPY_HW_SDCARD_BUS_WIDTH == 4
// configure the SD bus width for 4-bit wide operation
status = HAL_SD_ConfigWideBusOperation(&sdmmc_handle.sd, SDIO_BUS_WIDE_4B);
#if MICROPY_HW_SDCARD_BUS_WIDTH >= 4
// configure the SD bus width for 4/8-bit wide operation
status = HAL_SD_ConfigWideBusOperation(&sdmmc_handle.sd, SDIO_BUS_WIDE_VALUE);
if (status != HAL_OK) {
HAL_SD_DeInit(&sdmmc_handle.sd);
return status;
@ -287,12 +312,12 @@ STATIC HAL_StatusTypeDef sdmmc_init_mmc(void) {
// As this is an eMMC card, overwrite LogBlockNbr with actual value
sdmmc_handle.mmc.MmcCard.LogBlockNbr = 7469056 + 2048;
#if MICROPY_HW_SDCARD_BUS_WIDTH == 4
// Configure the SDIO bus width for 4-bit wide operation
#if MICROPY_HW_SDCARD_BUS_WIDTH >= 4
// Configure the SDIO bus width for 4/8-bit wide operation
#ifdef STM32F7
sdmmc_handle.mmc.Init.ClockBypass = SDIO_CLOCK_BYPASS_ENABLE;
#endif
status = HAL_MMC_ConfigWideBusOperation(&sdmmc_handle.mmc, SDIO_BUS_WIDE_4B);
status = HAL_MMC_ConfigWideBusOperation(&sdmmc_handle.mmc, SDIO_BUS_WIDE_VALUE);
if (status != HAL_OK) {
HAL_MMC_DeInit(&sdmmc_handle.mmc);
return status;

Loading…
Cancel
Save