circuitpython: SPI SD Cards don't mount both when on the same SPI bus

CircuitPython version

Adafruit CircuitPython 7.2.0 on 2022-17-4; Raspberry Pi Pico with rp2040

Code/REPL

import time
import board, busio, digitalio
import os, storage
from sdcardio import SDCard

spi = busio.SPI(clock=board.GP18, MOSI=board.GP19, MISO=board.GP16)
sdcs1_pin = board.GP6
sdcs2_pin = board.GP7

print("Starting")
sd1 = SDCard(spi, sdcs1_pin)
vfs1 = storage.VfsFat(sd1)
storage.mount(vfs1, "/sd1")
print("SD 1 Mounted")
print(os.listdir("/sd1"))
storage.umount(vfs1)

sd2 = SDCard(spi, sdcs2_pin)
vfs2 = storage.VfsFat(sd2)
storage.mount(vfs2, "/sd2")
print("SD 2 Mounted")
print(os.listdir("/sd2"))

while True:
    print("loop")
    time.sleep(1)

Behavior

Below is the error from the code. When run, only one of the SPI SD Card modules is recognized. You can change which one is mounted by unplugging the power and swapping in the code the CS pins. A few times, it successfully mounted both SD cards, but I cant reproduce that event anymore.

>>> %Run -c $EDITOR_CONTENT
Starting
SD 1 Mounted
[]
Traceback (most recent call last):
  File "<stdin>", line 18, in <module>
OSError: no SD card

Description

-Error with mounting two SPI SD Card modules -MCU is Raspberry Pi Pico

  • I have tried following with no change in behavior: -Slowing the baudrate down to 9600 -Changing to 5V power -Adding time.sleep() calls -Flipping CS Pins -Deiniting CS pins -Tested with a regular SD Card and the SPI SD Card flash module and the two mounted correctly.

Additional information

No response

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 21 (3 by maintainers)

Most upvoted comments

@KurtE Been playing around with different processor and SD Cards. And it seems some SD cards will work and some not. I have been using 3 different SD Cards for testing

  1. Samsung 64GB Ultra
  2. Samsung 32GB EVO
  3. Transcend 8GB premium.
  4. Adafruit SPI Flash SD Card (yep picked one up)

The 64GB worked without an issue, for the 32GB card had to increase the timeout in the SD lib to 400 from 200 and then it worked. The 8GB had a problem with-didn’t want to work. The Flash SD Card only worked with certain processors. Here I what I found so far:

Adafruit QT PY RP2040
SPI Flash first card on D0 and SD Card on D1 chained both worked together

T41
SD Card and SPI Flash SD Card worked together.

TMM
2 SD cards are read but NAND SD Card does not work by itself
getting no sd card found

Sparkfun SAMD51 Micromod
Only Card reader on ML Carrier worked with a 64GB Samsung Ultra
Either No SD card found or timeout V2

ESP32S3
only the flash SD Card breakout works.  Getting No SD Card found for the SD cards.

Adafruit STM32F405 express
Only flash SD Card breakout works, Either No SD card found or timeout V2

There is only one set of connections going to the processor board. So don’t think its a wiring problem. Whether its a timing or other issue with the SD Library don’t know yet.

This was discussed and tested at length on Discord. I think it needs someone with two of the Adafruit flash-chip SD Card breakouts to try to replicate. Confirmed that one regular SD Card breakout + one flash-chip SD Card breakout work fine on RP2040 port, but I don’t have two flash-chip breakouts to test.