Skip to content

cpu/esp32: fix periph/sdmmc for ESP32-S3 - #23010

Merged
gschorcht merged 3 commits into
RIOT-OS:masterfrom
gschorcht:cpu/esp32/fix_sdmmc_s3
Oct 29, 2026
Merged

gschorcht merged 3 commits into
RIOT-OS:masterfrom
gschorcht:cpu/esp32/fix_sdmmc_s3

Conversation

@gschorcht

@gschorcht gschorcht commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Contribution description

This PR fixes a small issue in periph/sdmmc for ESP32-S3 SoCs.

The PR includes the following fixes:

  • On ESP32-S3, the phase of the SDMMC input clock was always set to 270 degrees, which is required for MMCs. With SD Memory Cards, this phase leads to response errors for nearly each command, which were ignored as a workaround, and to sporadic failures of the card initialization or the first accesses, e.g. when mounting a file system. SD Memory Cards are now used with the default phase of 0 degrees as in ESP-IDF, and 270 degrees is only used for MMCs. Both phases can be overridden with CONFIG_SDMMC_INPUT_DELAY_PHASE_SD and CONFIG_SDMMC_INPUT_DELAY_PHASE_MMC.

  • Since ESP-IDF v6.x (also applies for ESP-IDF 5.4), the clock configuration of an SDMMC slot is applied with the next transaction, which also resets the phase of the input clock. The phase of the input clock required on ESP32-S3 for MMCs was therefore overwritten. It is now configured with sdmmc_host_set_input_delay instead of writing it directly into the CLOCK register.

The issue was identified during the migration to ESP-IDF v6.1 in PR #22946. This PR is a split-off from of PR #22946 and simplifies PR #22946.

Testing procedure

Compile an flash the tests/sys/vfs_default to any ESP32-S3 board with SDMMC interface, e.g.:

USEMODULE=stdio_uart CFLAGS='-DCONFIG_USE_HARDWARE_MTD=1'  \
BOARD=esp32s3-usb-otg make -j8 -C tests/sys/vfs_default flash term

Issues/PRs references

Split-off from PR #22946

Declaration of AI-Tools / LLMs usage:

AI-Tools / LLMs that were used are:

  • Claude Code Opus 5.5 was used to identify the issue
  • Claude Code Opus 5.5 was used for code generation, with user review

Since ESP-IDF v6.x, the clock configuration of an SDMMC slot is applied
with the next transaction, which also resets the phase of the input
clock. The phase of the input clock required on ESP32-S3 for MMCs was
therefore overwritten. It is now configured with
sdmmc_host_set_input_delay instead of writing it directly into the
CLOCK register. SDMMC_DELAY_PHASE_3 corresponds to the value 6 used
before.

Assisted-by: Claude Code Opus 5.5
On ESP32-S3, the phase of the SDMMC input clock was always set to 270
degrees, which is required for MMCs. With SD Memory Cards, this phase
leads to response errors for nearly each command, which were ignored as
a workaround, and to sporadic failures of the card initialization or the
first accesses, e.g. when mounting a file system. SD Memory Cards are now
used with the default phase of 0 degrees as in ESP-IDF, and 270 degrees
is only used for MMCs. Both phases can be overridden with
CONFIG_SDMMC_INPUT_DELAY_PHASE_SD and CONFIG_SDMMC_INPUT_DELAY_PHASE_MMC.

Assisted-by: Claude Code Opus 5.5
ESP-IDF v6.x checks in sd_host_check_buffer_alignment whether the buffer of a data transfer can be used for DMA, including its length given by sdmmc_command_t::buflen. Since buflen was not set, the check failed with "buffer can not be used for DMA" for each data transfer, e.g. for reading the SCR with ACMD51 during card initialization.

Assisted-by: Claude Code Opus 5.5
@github-actions github-actions Bot added Platform: ESP Platform: This PR/issue effects ESP-based platforms Area: cpu Area: CPU/MCU ports labels Oct 28, 2026
@gschorcht gschorcht added AI: Co-Authored PR/Issue relies on AI. Documentation / Code was partly generated by AI. Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Oct 28, 2026
@riot-ci

riot-ci commented Oct 28, 2026

Copy link
Copy Markdown

Murdock results

✔️ PASSED

c51c716 cpu/esp32: set buffer length for SDMMC data transfers

Success Failures Total Runtime
14013 0 14013 09m:50s

Artifacts

@gschorcht
gschorcht added this pull request to the merge queue Oct 28, 2026
Merged via the queue into RIOT-OS:master with commit 2e35a34 Oct 29, 2026
34 checks passed
@gschorcht

Copy link
Copy Markdown
Contributor Author

@benpicco Thanks for the review.

@gschorcht
gschorcht deleted the cpu/esp32/fix_sdmmc_s3 branch October 29, 2026 06:37
@gschorcht gschorcht mentioned this pull request Oct 30, 2026
7 of 17 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI: Co-Authored PR/Issue relies on AI. Documentation / Code was partly generated by AI. Area: cpu Area: CPU/MCU ports Area: drivers Area: Device drivers CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Platform: ESP Platform: This PR/issue effects ESP-based platforms Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants