Skip to content

drivers: disk: sdmmc_stm32: Fix bus width initialization sequence #94895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bricle
Copy link
Contributor

@bricle bricle commented Aug 23, 2025

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.

before this change tested on stm32H743:

with zephyr/tests/drivers/disk/disk_access
dts:

&sdmmc1 {
	pinctrl-0 = <&sdmmc1_d0_pc8 &sdmmc1_d1_pc9
		     &sdmmc1_d2_pc10 &sdmmc1_d3_pc11
		     &sdmmc1_ck_pc12 &sdmmc1_cmd_pd2>;
	pinctrl-names = "default";
	clk-div = <6>;
	bus-width = <1>;
	cd-gpios = <&gpiod 4 (GPIO_ACTIVE_HIGH | GPIO_PULL_UP)>;
	disk-name = "SD";
	status = "okay";
};

with 1 line bus width ( bus-width = <1>)

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [disk_driver]: pass = 2, fail = 0, skip = 0, total = 2 duration = 0.122 seconds
 - PASS - [disk_driver.test_read] duration = 0.041 seconds
 - PASS - [disk_driver.test_write] duration = 0.081 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

with 4 line bus width ( bus-width = <4>)

------ TESTSUITE SUMMARY START ------

SUITE FAIL -   0.00% [disk_driver]: pass = 0, fail = 2, skip = 0, total = 2 duration = 0.131 seconds
 - FAIL - [disk_driver.test_read] duration = 0.104 seconds
 - FAIL - [disk_driver.test_write] duration = 0.027 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION FAILED

after this change tested on stm32H743:

with 4 line bus width ( bus-width = <4>)

------ TESTSUITE SUMMARY START ------

SUITE PASS - 100.00% [disk_driver]: pass = 2, fail = 0, skip = 0, total = 2 duration = 0.122 seconds
 - PASS - [disk_driver.test_read] duration = 0.041 seconds
 - PASS - [disk_driver.test_write] duration = 0.081 seconds

------ TESTSUITE SUMMARY END ------

===================================================================
PROJECT EXECUTION SUCCESSFUL

Copy link
Contributor

@JarmouniA JarmouniA left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change does not correspond to what's in the PR's description.
What's needed is to set

.Init.BusWide = SDMMC_BUS_WIDTH,

to SDMMC_BUS_WIDE_1B by default, then, after HAL_SD_Init(), if SDMMC_BUS_WIDTH!=SDMMC_BUS_WIDE_1B, change it to SDMMC_BUS_WIDTH and call HAL_SD_ConfigWideBusOperation().

@bricle bricle force-pushed the fix_sdmmc_stm32_bus_wide branch from 15165b7 to 2d22df5 Compare August 24, 2025 01:30
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 if needed 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]>
@bricle bricle force-pushed the fix_sdmmc_stm32_bus_wide branch from 2d22df5 to 76de1af Compare August 24, 2025 01:38
Copy link

@bricle
Copy link
Contributor Author

bricle commented Aug 24, 2025

The change does not correspond to what's in the PR's description. What's needed is to set

.Init.BusWide = SDMMC_BUS_WIDTH,

to SDMMC_BUS_WIDE_1B by default, then, after HAL_SD_Init(), if SDMMC_BUS_WIDTH!=SDMMC_BUS_WIDE_1B, change it to SDMMC_BUS_WIDTH and call HAL_SD_ConfigWideBusOperation().

Sorry for the misleading, changed as suggested. Now it is explicitly initialized with SDMMC_BUS_WIDE_1B using HAL_SD_Init()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants