Skip to content

Commit 8cdf463

Browse files
committed
drivers: sdmmc_stm32: Fix bus width initialization sequence
Fix SDMMC initialization by starting with 1-bit bus mode and properly configuring wide bus operation after HAL initialization. The SDMMC protocol requires initialization to start in 1-bit mode before switching to wider bus widths. Previously, the driver attempted to initialize directly with the target bus width, which could cause later read/write failures. Changes: - Initialize with SDMMC_BUS_WIDE_1B instead of target bus width - Add HAL_SD_ConfigWideBusOperation() call after successful init - Add error logging for wide bus configuration failures Fixes potential SDMMC read/write failures issues on STM32 platforms. Signed-off-by: Shan Pen <[email protected]>
1 parent 5945a3f commit 8cdf463

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

drivers/disk/sdmmc_stm32.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,9 @@ static int stm32_sdmmc_access_init(struct disk_info *disk)
365365
LOG_ERR("failed to init stm32_sdmmc (ErrorCode 0x%X)", priv->hsd.ErrorCode);
366366
return -EIO;
367367
}
368-
368+
if (HAL_SD_ConfigWideBusOperation(&priv->hsd, priv->hsd.Init.BusWide) != HAL_OK) {
369+
LOG_ERR("failed to configure wide bus operation");
370+
}
369371
#ifdef CONFIG_SDMMC_STM32_HWFC
370372
stm32_sdmmc_fc_enable(priv);
371373
#endif
@@ -887,7 +889,7 @@ static struct stm32_sdmmc_priv stm32_sdmmc_priv_1 = {
887889
: SDMMC_CLOCK_BYPASS_DISABLE,
888890
#endif
889891
.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE,
890-
.Init.BusWide = SDMMC_BUS_WIDTH,
892+
.Init.BusWide = SDMMC_BUS_WIDE_1B,
891893
.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE,
892894
.Init.ClockDiv = DT_INST_PROP_OR(0, clk_div, 0),
893895
},

0 commit comments

Comments
 (0)