← index #11000PR #10490
Related · high · value 2.086
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

ports/esp32/machine_sdcard.c: Fix ESP_ERR_INVALID_ARG on SDCard init on ESP32-S3 (Change DMA channel)

mergedby maripoopened 2023-01-13updated 2023-01-19
port-esp32

This pull request solves the problem that initialization of SDCard objects with SPI fails on ESP32-S3.

Problem

Creating SDCard object with SPI (slot=2 or 3) causes ESP_ERR_INVALID_ARG error.

[0;31mE (34340) spi: spi_bus_initialize(762): invalid dma channel, chip only support spi dma channel auto-alloc[0m
[0;31mE (34340) sdspi_host: spi_bus_initialize failed with rc=0x102[0m

The code below can reproduce this.

import os
from machine import Pin, SDCard

card = SDCard(slot=2, sck=Pin(17), miso=Pin(18), mosi=Pin(16), cs=Pin(15)) # <- ESP_ERR_INVALID_ARG

Reason

In ports/esp32/machine_sdcard.c, SPI slot configurations are defined. However, the DMA channel specified in the configuration for ESP32-S3 is inappropriate. In ESP-IDF, the only available channel for ESP32S3 is SPI_DMA_CH_AUTO=3.

esp-idf/components/driver/spi_common.c

Solution

Specifying DMA channel 3 instead of 2 fixes the problem. I have confirmed the problem and the solution on ESP32-S3-DevKitC-1 board.

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