summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Wilson <chris@wilson.house>2019-08-01 19:54:32 -0700
committerDamien George <damien.p.george@gmail.com>2019-08-08 12:53:05 +1000
commit3d02ebb4e8262b67433eadc80100155387c6f186 (patch)
tree3d15c94395644dacfa349ab5c2359491539dccaa
parentefdcd6baa710af11bdc2f4930e42e439cc1b2ff8 (diff)
stm32/sdcard: Support configuring the SD/MMC bus width to 1 or 4 bits.
Some SD/MMC breakout boards don't support 4-bit bus mode. This adds a new macro MICROPY_HW_SDMMC_BUS_WIDTH that allows each board to define the width of the SD/MMC bus interface used on that board, defaulting to 4 bits.
-rw-r--r--ports/stm32/mpconfigboard_common.h5
-rw-r--r--ports/stm32/sdcard.c16
2 files changed, 17 insertions, 4 deletions
diff --git a/ports/stm32/mpconfigboard_common.h b/ports/stm32/mpconfigboard_common.h
index 121b64d03..603215af4 100644
--- a/ports/stm32/mpconfigboard_common.h
+++ b/ports/stm32/mpconfigboard_common.h
@@ -102,6 +102,11 @@
#define MICROPY_HW_ENABLE_MMCARD (0)
#endif
+// SD/MMC interface bus width (defaults to 4 bits)
+#ifndef MICROPY_HW_SDMMC_BUS_WIDTH
+#define MICROPY_HW_SDMMC_BUS_WIDTH (4)
+#endif
+
// Whether to automatically mount (and boot from) the SD card if it's present
#ifndef MICROPY_HW_SDCARD_MOUNT_AT_BOOT
#define MICROPY_HW_SDCARD_MOUNT_AT_BOOT (MICROPY_HW_ENABLE_SDCARD)
diff --git a/ports/stm32/sdcard.c b/ports/stm32/sdcard.c
index 0cb09b818..f54d67ea4 100644
--- a/ports/stm32/sdcard.c
+++ b/ports/stm32/sdcard.c
@@ -156,17 +156,21 @@ void sdcard_init(void) {
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC2_CK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC2_CK);
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC2_CMD, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC2_CMD);
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC2_D0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC2_D0);
+ #if MICROPY_HW_SDMMC_BUS_WIDTH == 4
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC2_D1, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC2_D1);
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC2_D2, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC2_D2);
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC2_D3, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC2_D3);
+ #endif
#else
// Default SDIO/SDMMC1 config
+ mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC_CK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC_CK);
+ mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC_CMD, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC_CMD);
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC_D0, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC_D0);
+ #if MICROPY_HW_SDMMC_BUS_WIDTH == 4
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC_D1, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC_D1);
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC_D2, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC_D2);
mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC_D3, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC_D3);
- mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC_CK, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC_CK);
- mp_hal_pin_config_alt_static(MICROPY_HW_SDMMC_CMD, MP_HAL_PIN_MODE_ALT, MP_HAL_PIN_PULL_UP, STATIC_AF_SDMMC_CMD);
+ #endif
#endif
// configure the SD card detect pin
@@ -252,12 +256,14 @@ STATIC HAL_StatusTypeDef sdmmc_init_sd(void) {
mp_hal_delay_ms(50);
}
- // configure the SD bus width for wide operation
+ #if MICROPY_HW_SDMMC_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 (status != HAL_OK) {
HAL_SD_DeInit(&sdmmc_handle.sd);
return status;
}
+ #endif
return HAL_OK;
}
@@ -285,7 +291,8 @@ 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;
- // Configure the SDIO bus width for wide operation
+ #if MICROPY_HW_SDMMC_BUS_WIDTH == 4
+ // Configure the SDIO bus width for 4-bit wide operation
#ifdef STM32F7
sdmmc_handle.mmc.Init.ClockBypass = SDIO_CLOCK_BYPASS_ENABLE;
#endif
@@ -294,6 +301,7 @@ STATIC HAL_StatusTypeDef sdmmc_init_mmc(void) {
HAL_MMC_DeInit(&sdmmc_handle.mmc);
return status;
}
+ #endif
return HAL_OK;
}