← index #11000Issue #4848
Related · high · value 0.533
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 · ISSUE

ESP32 SPI SD Card - Invalid DMA Channel

closedby McSpideropened 2019-06-15updated 2020-07-13
port-esp32

I'm having problems getting a SD card to work over SPI with the new MicroPython SD card support introduced in 8e3af7d & 6077d17 by @dpgeorge and @nickovs

The SD card and hardware work fine when using Arduino.

  • Micropython version: esp32-20190615-v1.11-45-g14cf91f70
  • Hardware:
    Wemos clone of a MH-ET LIVE MiniKit and a D1 Mini SD Card Shield
  • SD Card connected as follows:
    SCK: 18 MISO: 19 MOSI 23 CS: 5

The documentation gives this as an example:
uos.mount(storage.SDCard(), "/sd")
Which obviously doesn't work since SDCard is part of machine, fixing that results in:

>>> uos.mount(machine.SDCard(), "/sd")
E (23331) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 16

So it defaults to MMC, which is fine, but the example should note that and perhaps provide a SPI example as well.

So then I tried:

>>> import machine
>>> uos.mount(machine.SDCard(slot=2), "/sd")
E (15969) spi_master: spi_bus_initialize(235): invalid dma channel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 258

>>> uos.mount(machine.SDCard(slot=2, sck=machine.Pin(18),miso=machine.Pin(19),mosi=machine.Pin(23),cs=machine.Pin(5)), "/sd")
E (27309) spi_master: spi_bus_initialize(235): invalid dma channel
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 258

So apparently the dma channel is wrong, but I can't change that anywhere in my code. And I don't know enough about the micropython code to start poking around in it. Not that I didn't try but that lead me to the espressif source code which made me even more clueless because IMO it should be working.


Some other things I tried:

# This obviously won't work according to the docs, but I tried anyways
>>> uos.mount(machine.SDCard(slot=1, sck=machine.Pin(18),miso=machine.Pin(19),mosi=machine.Pin(23),cs=machine.Pin(5)), "/sd")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 259

No idea what OSError 259 is, and I couldn't find any documentation on it, same for 258, but at least that tells me invalid dma channel above it.

>>> uos.mount(machine.SDCard(sck=machine.Pin(18),miso=machine.Pin(19),mosi=machine.Pin(23),cs=machine.Pin(5)), "/sd")
E (32129) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OSError: 16

Doesn't work, we actually want to use SPI mode not MMC. Not sure if it's worth making the code detect this case?

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