Skip to content

esp32/machine_sdcard: Move SDMMC slot/width defaults to per-board config - #19620

Open
pavelrevak wants to merge 2 commits into
micropython:masterfrom
pavelrevak:machine_sdcard
Open

esp32/machine_sdcard: Move SDMMC slot/width defaults to per-board config#19620
pavelrevak wants to merge 2 commits into
micropython:masterfrom
pavelrevak:machine_sdcard

Conversation

@pavelrevak

Copy link
Copy Markdown
Contributor

Follow-up to #19533. In that PR @dpgeorge suggested moving the
MICROPY_HW_SDMMC_DEFAULT_SLOT and MICROPY_HW_SDMMC_DEFAULT_WIDTH
defaults out of mpconfigport.h:

maybe it makes sense now to move the MICROPY_HW_SDMMC_DEFAULT_SLOT and
MICROPY_HW_SDMMC_DEFAULT_WIDTH default defines out of mpconfigport.h
and into machine_sdcard.h?

(#19533 (comment))

This does that, and goes one step further. These defines are only used by
machine_sdcard.c, so the first commit moves them next to the SD card SPI
pin defaults in machine_sdcard.h.

While moving them I checked the SoC capabilities: the ESP32-P4 exposes two
equally-capable SDMMC slots (SOC_SDMMC_NUM_SLOTS == 2, both up to 8-bit),
so the previous slot 0 / 4-bit value for P4 was not a silicon property
but a description of how the reference board is wired. The old
#if CONFIG_IDF_TARGET_ESP32P4 special-case in the shared header was
therefore misleading.

So the second commit keeps only a conservative generic default in the
header (slot 1, 1-bit) and moves the P4-specific slot 0 / 4-bit
wiring into boards/ESP32_GENERIC_P4/mpconfigboard.h, next to the existing
SDMMC LDO config. Any board can still override both defines via the
existing #ifndef guards.

No functional change: ESP32_GENERIC_P4 keeps slot 0 / 4-bit and all
other targets keep slot 1 / 1-bit; the values are just defined in more
appropriate places.

Tested on hardware:

  • ESP32_GENERIC_P4: default machine.SDCard() reads at ~6.8 MiB/s vs
    ~2.3 MiB/s when forced to width=1, confirming the 4-bit default is
    applied from the board config.
  • ESP32_GENERIC_S3 (XIAO ESP32-S3): SPI-mode machine.SDCard(slot=2)
    with the default pins still mounts and reads correctly (~1.5 MiB/s),
    confirming the refactor didn't regress the other targets.

Generative AI

I used generative AI tools when creating this PR, but a human has checked the
code and is responsible for the code and the description above.

Move MICROPY_HW_SDMMC_DEFAULT_SLOT and MICROPY_HW_SDMMC_DEFAULT_WIDTH out
of mpconfigport.h and into machine_sdcard.h, next to the SD card SPI pin
defaults.  These defines are only used by machine_sdcard.c, so they
belong with the rest of the SD card configuration.  The defaults are now
the conservative slot 1, 1-bit values, leaving per-board wiring to each
board to override.

Signed-off-by: Pavel Revak <pavelrevak@gmail.com>
The ESP32-P4 has two equally capable SDMMC slots, so which slot is used
and how many data lines are wired is a board property rather than a SoC
one.  This board connects the SD/MMC card to slot 0 with a full 4-bit
bus, so set the default slot to 0 and the default bus width to 4.

Signed-off-by: Pavel Revak <pavelrevak@gmail.com>
@pavelrevak pavelrevak changed the title Machine sdcard esp32/machine_sdcard: Move SDMMC slot/width defaults to per-board config Aug 14, 2026
@github-actions

Copy link
Copy Markdown

Code size report:

Reference:  lib/tinyusb: Update tinyusb submodule to MicroPython's fork. [791ba6e]
Comparison: esp32/boards/ESP32_GENERIC_P4: Set default SDMMC slot and bus width. [merge of 60dbe80]
  mpy-cross:    +0 +0.000% 
   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:    +0 +0.000% standard
      stm32:    +0 +0.000% PYBV10
      esp32:    +0 +0.000% ESP32_GENERIC
     mimxrt:    +0 +0.000% TEENSY40
        rp2:    +0 +0.000% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +0 +0.000% VIRT_RV32

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant