esp32/machine_sdcard: Make default SPI pins board-configurable.#19407
Open
pavelrevak wants to merge 2 commits into
Open
esp32/machine_sdcard: Make default SPI pins board-configurable.#19407pavelrevak wants to merge 2 commits into
pavelrevak wants to merge 2 commits into
Conversation
The default pins for the primary SPI-mode SD card bus (slot 2) were hard-coded per chip, and the ESP32-S3 defaults (GPIO 35/36/37) clash with the octal SPIRAM bus, so they are unusable on many S3 boards. Add a machine_sdcard.h header defining MICROPY_HW_SDCARD_SPI_SCK, _MOSI, _MISO and _CS, following the existing per-peripheral pin-define convention (machine_i2c.h, machine_hw_spi.c). A board can override these in its mpconfigboard.h so that machine.SDCard(slot=2) works without passing pins. The defaults match the previous per-chip values, so behaviour is unchanged unless a board overrides them. SDMMC-mode pins (slots 0 and 1) are not affected. Signed-off-by: Pavel Revak <pavelrevak@gmail.com>
Define MICROPY_HW_SDCARD_SPI_* so that machine.SDCard(slot=2) works without explicit pins on boards that have an onboard microSD slot wired for SPI mode, where the pins differ from the chip default: - SEEED_XIAO_ESP32S3 (verified on hardware) - LILYGO_T3_S3 - LILYGO_TTGO_LORA32 - SPARKFUN_THINGPLUS_ESP32C5 The pins are taken from each board's definition or official documentation. Signed-off-by: Pavel Revak <pavelrevak@gmail.com>
|
Code size report: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The default pins for the SPI-mode SD card bus (
machine.SDCard(slot=2)) on the esp32 port are hard-coded per chip inmachine_sdcard.c. This makesmachine.SDCard(slot=2)unusable out of the box on many boards — most notably the ESP32-S3 defaults (GPIO 35/36/37) clash with the octal SPIRAM bus, so on an S3 board with octal PSRAM the call reconfigures the PSRAM pins and crashes.This PR makes those pins board-configurable, consistent with how I2C (
machine_i2c.h) and SPI (machine_hw_spi.c) already expose their default pins.Changes
ports/esp32/machine_sdcard.hdefiningMICROPY_HW_SDCARD_SPI_SCK/_MOSI/_MISO/_CSfor the primary SPI SD bus (slot 2), guarded with#ifndefso a board can override them inmpconfigboard.h.machine_sdcard.cuses these macros for the primary bus/device defaults.SEEED_XIAO_ESP32S3,LILYGO_T3_S3,LILYGO_TTGO_LORA32,SPARKFUN_THINGPLUS_ESP32C5. Pins are taken from each board's definition or official documentation.Behaviour / compatibility
GPIO_NUM_NC).sck=/miso=/mosi=/cs=arguments still take precedence.Testing
Verified on a Seeed XIAO ESP32S3 (Sense) with a microSD card:
machine.SDCard(slot=2)works with no arguments andsd.info()returns(1977614336, 512). TheSPARKFUN_THINGPLUS_ESP32C5board (single SPI bus) exercises theNUM_SD_SPI_BUS == 1code path at build time in CI. The other boards' pins were confirmed against their schematics.Affected ports
ESP32 only (all variants).
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.