← index #11000PR #16702
Likely Duplicate · medium · value 5.672
QUERY · ISSUE

docs: machine.SDCard: clarify, which SPI device is used

openby sebert007opened 2023-03-10updated 2025-11-06
docs

I am using this code here:

    sd = machine.SDCard(slot=SD_SLOT,
                        width=SD_WIDTH,
                        sck=SD_SCK_PIN,
                        mosi=SD_MOSI_PIN,
                        miso=SD_MISO_PIN,
                        cs=SD_CS,
                        freq=SD_FREQ)

However it's not clear, which hardware SPI device is used.

I am using the ESP32-S3 (quad SPIRAM). It seems that SPI id=2 is used.

Is it possible to clarify this on the documentation? Or even let the user specify a parameter?

CANDIDATE · PULL REQUEST

esp32: Improve machine.SDCard support on newer chips

mergedby projectgusopened 2025-02-05updated 2025-03-13
port-esp32

Summary

Updating the esp32 port machine.SDCard support for other chips:

  • Added support for configuring pins in SD/MMC mode on ESP32-S3. Closes #8514. Closes #16526.
  • Added support for SDCard in SPI mode on ESP32-S2, C3 and C6. This is a little restrictive on C3 and C6 as they only have one available SPI bus, so can't use this and machine.SPI together. Have enabled on all boards by default (the code size impact is about 4KB).
  • Explicitly disable slot 0 on original ESP32 (and document this). There are effectively zero ESP32 boards in the world that can use slot 0 for SDMMC.

This work was funded through GitHub sponsors

TODO

  • Final docs pass
  • [ ] ESP32-S3 SDCard object should print the additonal pin config EDIT: Actually SDCard has no print support on esp32, so leaving this off.

Testing

Manual testing with SD card breakout module:

  • ESP32-S3 in SDMMC mode with custom pins.
  • ESP32-S3 in SPI mode on both hosts.
  • ESP32-C3 in SPI mode.
  • ESP32-C6 in SPI mode.
  • ESP32-S2 in SPI mode on both hosts.
  • ESP32 in SDMMC and SPI modes.

Note that testing is easier if cherry-picking #16700 fix into the branch.

Trade-offs and Alternatives

  • Could drop the commit that enables SDCard on SPI-only chips if preferable, and update docs to suit. Although on balance I think it's still potentially useful.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied