Skip to content

STM32 SDMMC Driver Compilation Error: Undefined SDMMC Constants on F4 series #94896

@bricle

Description

@bricle

Describe the bug

The STM32 SDMMC driver fails to compile due to undefined constants in F4 platform

.Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING,
#ifdef SDMMC_CLOCK_BYPASS_DISABLE
.Init.ClockBypass = DT_INST_PROP(0, clk_bypass)
? SDMMC_CLOCK_BYPASS_ENABLE
: SDMMC_CLOCK_BYPASS_DISABLE,
#endif
.Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE,
.Init.BusWide = SDMMC_BUS_WIDTH,
.Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE,

The compiler cannot find SDMMC_* constants and suggests using SDIO_* equivalents instead.

Device Tree Configuration:

&sdmmc1 {
	clocks = <&rcc STM32_CLOCK(APB2, 11)>,
		 <&rcc STM32_SRC_PLL_Q CLK48M_SEL(0)>;
	status = "okay";
	pinctrl-0 = <&sdio_d0_pc8
		     &sdio_d1_pc9
		     &sdio_d2_pc10
		     &sdio_d3_pc11
		     &sdio_ck_pc12
		     &sdio_cmd_pd2>;
	pinctrl-names = "default";
	cd-gpios = <&gpiog 2 GPIO_ACTIVE_LOW>;
	disk-name = "SD";
};

Root Cause
The driver is using SDMMC_* constants that are not defined in the STM32 HAL headers for STM32F4 series. The compiler suggests using SDIO_* constants instead, which indicates a mismatch between the driver implementation and the available HAL definitions for this MCU family.

Expected Behavior
The SDMMC driver should compile successfully and work with STM32F4 series MCUs that have SD cadd.

Proposed Solution
The driver should either:

Use conditional compilation to select appropriate constants based on the MCU family
Define proper mappings between SDMMC and SDIO constants
Update the driver to use the correct constants for STM32F4 series

Additional Context
This issue occurs when testing the disk access functionality on STM32F4, which has SDIO peripheral instead of the newer SDMMC peripheral found in STM32F7/H7 series.

Regression

  • This is a regression.

Steps to reproduce

  1. cd ~/zephyr/tests/drivers/disk/disk_access
  2. west build -b stm32f469i_disco/stm32f469xx -d build -p always

Relevant log output

~/zwksp/zephyr/tests/drivers/disk/disk_access (main) [130]
❯ west build -b stm32f469i_disco/stm32f469xx -d build -p always  && west flash
-- west build: making build dir /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build pristine
-- west build: generating a build system
Loading Zephyr default modules (Zephyr base).
-- Application: /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access
-- CMake version: 4.0.3
-- Found Python3: /home/bricl/zephyrproject/.venv/bin/python3 (found suitable version "3.12.3", minimum required is "3.10") found components: Interpreter
-- Cache files will be written to: /home/bricl/.cache/zephyr
-- Zephyr version: 4.2.99 (/home/bricl/zwksp/zephyr)
-- Found west (found suitable version "1.4.0", minimum required is "0.14.0")
-- Board: stm32f469i_disco, qualifiers: stm32f469xx
-- ZEPHYR_TOOLCHAIN_VARIANT not set, trying to locate Zephyr SDK
-- Found host-tools: zephyr 0.17.1 (/home/bricl/zephyr-sdk-0.17.1)
-- Found toolchain: zephyr 0.17.1 (/home/bricl/zephyr-sdk-0.17.1)
-- Found Dtc: /home/bricl/zephyr-sdk-0.17.1/sysroots/x86_64-pokysdk-linux/usr/bin/dtc (found suitable version "1.7.0", minimum required is "1.4.6")
-- Found BOARD.dts: /home/bricl/zwksp/zephyr/boards/st/stm32f469i_disco/stm32f469i_disco.dts
-- Generated zephyr.dts: /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build/zephyr/zephyr.dts
-- Generated pickled edt: /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build/zephyr/edt.pickle
-- Generated devicetree_generated.h: /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build/zephyr/include/generated/zephyr/devicetree_generated.h
Parsing /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/Kconfig
Loaded configuration '/home/bricl/zwksp/zephyr/boards/st/stm32f469i_disco/stm32f469i_disco_defconfig'
Merged configuration '/home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/prj.conf'
Configuration saved to '/home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build/zephyr/.config'
Kconfig header saved to '/home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build/zephyr/include/generated/zephyr/autoconf.h'
-- Found GnuLd: /home/bricl/zephyr-sdk-0.17.1/arm-zephyr-eabi/arm-zephyr-eabi/bin/ld.bfd (found version "2.38")
-- The C compiler identification is GNU 12.2.0
-- The CXX compiler identification is GNU 12.2.0
-- The ASM compiler identification is GNU
-- Found assembler: /home/bricl/zephyr-sdk-0.17.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc
-- Using ccache: /usr/bin/ccache
-- Found gen_kobject_list: /home/bricl/zwksp/zephyr/scripts/build/gen_kobject_list.py
-- Configuring done (8.9s)
-- Generating done (0.2s)
-- Build files have been written to: /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build
-- west build: building application
[1/157] Preparing syscall dependency handling

[2/157] Generating include/generated/zephyr/version.h
-- Zephyr version: 4.2.99 (/home/bricl/zwksp/zephyr), build: v4.2.0-2287-g5945a3fcd1eb
[107/157] Building C object zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/sdmmc_stm32.c.obj
FAILED: zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/sdmmc_stm32.c.obj 
ccache /home/bricl/zephyr-sdk-0.17.1/arm-zephyr-eabi/bin/arm-zephyr-eabi-gcc -DCORE_CM4 -DHSE_VALUE=8000000 -DKERNEL -DK_HEAP_MEM_POOL_SIZE=0 -DPICOLIBC_LONG_LONG_PRINTF_SCANF -DSTM32F469xx -DUSE_FULL_LL_DRIVER -DUSE_HAL_DRIVER -D__LINUX_ERRNO_EXTENSIONS__ -D__PROGRAM_START -D__ZEPHYR_SUPERVISOR__ -D__ZEPHYR__=1 -I/home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build/zephyr/include/generated/zephyr -I/home/bricl/zwksp/zephyr/include -I/home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build/zephyr/include/generated -I/home/bricl/zwksp/zephyr/soc/st/stm32 -I/home/bricl/zwksp/zephyr/soc/st/stm32/common/. -I/home/bricl/zwksp/zephyr/drivers -I/home/bricl/zwksp/zephyr/soc/st/stm32/stm32f4x/. -I/home/bricl/zwksp/zephyr/subsys/testsuite/include -I/home/bricl/zwksp/zephyr/subsys/testsuite/coverage -I/home/bricl/zwksp/zephyr/subsys/testsuite/ztest/include -I/home/bricl/zwksp/zephyr_application/include -I/home/bricl/zwksp/modules/hal/cmsis_6/CMSIS/Core/Include -I/home/bricl/zwksp/zephyr/modules/cmsis_6/. -I/home/bricl/zwksp/modules/hal/stm32/stm32cube/stm32f4xx/soc -I/home/bricl/zwksp/modules/hal/stm32/stm32cube/stm32f4xx/drivers/include -I/home/bricl/zwksp/modules/hal/stm32/stm32cube/common_ll/include -isystem /home/bricl/zwksp/zephyr/lib/libc/common/include -Wshadow -fno-strict-aliasing -Os -imacros /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build/zephyr/include/generated/zephyr/autoconf.h -fno-printf-return-value -fno-common -g -gdwarf-4 -fdiagnostics-color=always -mcpu=cortex-m4 -mthumb -mabi=aapcs -mfp16-format=ieee -mtp=soft --sysroot=/home/bricl/zephyr-sdk-0.17.1/arm-zephyr-eabi/arm-zephyr-eabi -imacros /home/bricl/zwksp/zephyr/include/zephyr/toolchain/zephyr_stdint.h -Wall -Wformat -Wformat-security -Wno-format-zero-length -Wdouble-promotion -Wno-pointer-sign -Wpointer-arith -Wexpansion-to-defined -Wno-unused-but-set-variable -Werror=implicit-int -fno-pic -fno-pie -fno-asynchronous-unwind-tables -ftls-model=local-exec -fno-reorder-functions --param=min-pagesize=0 -fno-defer-pop -fmacro-prefix-map=/home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access=CMAKE_SOURCE_DIR -fmacro-prefix-map=/home/bricl/zwksp/zephyr=ZEPHYR_BASE -fmacro-prefix-map=/home/bricl/zwksp=WEST_TOPDIR -ffunction-sections -fdata-sections -specs=picolibc.specs -std=c99 -MD -MT zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/sdmmc_stm32.c.obj -MF zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/sdmmc_stm32.c.obj.d -o zephyr/drivers/disk/CMakeFiles/drivers__disk.dir/sdmmc_stm32.c.obj -c /home/bricl/zwksp/zephyr/drivers/disk/sdmmc_stm32.c
/home/bricl/zwksp/zephyr/drivers/disk/sdmmc_stm32.c:883:35: error: 'SDMMC_CLOCK_EDGE_RISING' undeclared here (not in a function); did you mean 'SDIO_CLOCK_EDGE_RISING'?
  883 |                 .Init.ClockEdge = SDMMC_CLOCK_EDGE_RISING,
      |                                   ^~~~~~~~~~~~~~~~~~~~~~~
      |                                   SDIO_CLOCK_EDGE_RISING
/home/bricl/zwksp/zephyr/drivers/disk/sdmmc_stm32.c:889:40: error: 'SDMMC_CLOCK_POWER_SAVE_DISABLE' undeclared here (not in a function); did you mean 'SDIO_CLOCK_POWER_SAVE_DISABLE'?
  889 |                 .Init.ClockPowerSave = SDMMC_CLOCK_POWER_SAVE_DISABLE,
      |                                        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                        SDIO_CLOCK_POWER_SAVE_DISABLE
/home/bricl/zwksp/zephyr/drivers/disk/sdmmc_stm32.c:891:45: error: 'SDMMC_HARDWARE_FLOW_CONTROL_DISABLE' undeclared here (not in a function); did you mean 'SDIO_HARDWARE_FLOW_CONTROL_DISABLE'?
  891 |                 .Init.HardwareFlowControl = SDMMC_HARDWARE_FLOW_CONTROL_DISABLE,
      |                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      |                                             SDIO_HARDWARE_FLOW_CONTROL_DISABLE
[120/157] Building C object zephyr/kernel/CMakeFiles/kernel.dir/errno.c.obj
ninja: build stopped: subcommand failed.
FATAL ERROR: command exited with status 1: /usr/bin/cmake --build /home/bricl/zwksp/zephyr/tests/drivers/disk/disk_access/build

Impact

Major – Severely degrades functionality; workaround is difficult or unavailable.

Environment

Environment wsl2 with ubuntu 24.04
zephyr Version: main at 5945a3f
Board: stm32f469i_disco/stm32f469xx
MCU: stm32f469xx
Build System: CMake/Ninja
Test Path: tests/drivers/disk/disk_access

Additional Context

This issue is probably caused by e8799bb.
I've only noticed this issue on F4 platform, tested on H5 and H7 platform and works fine.
This issue reveals that SDMMC Driver on STM32F4 platforms are not being tested in CI, it would be valuable if someone could include STM32F4 testing on this driver.

Metadata

Metadata

Assignees

Labels

bugThe issue is a bug, or the PR is fixing a bugplatform: STM32ST Micro STM32priority: lowLow impact/importance bug

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions