Skip to content

Implement sdioio for raspberrypi port#11090

Open
FoamyGuy wants to merge 5 commits into
adafruit:mainfrom
FoamyGuy:rpi_sdioio
Open

Implement sdioio for raspberrypi port#11090
FoamyGuy wants to merge 5 commits into
adafruit:mainfrom
FoamyGuy:rpi_sdioio

Conversation

@FoamyGuy

@FoamyGuy FoamyGuy commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

The core functionality of the implementation comes from https://github.com/adafruit/SdFat/. A few files needed altering to work embedded within CircuitPython and hooked up to the bindings.

Basic testing has been completed successfully on a Metro RP2350. Also enabled for Fruit Jam, but not tested yet, should work the same. board.SDIO_DATA is added to those two devices as a tuple of the 4 sdio data pins to match the existing sdioio documented example.

Currently the sdcard automount still uses SPI, and the SPI sdcard interface has some conflicting pins with the sdioio interface. When automount is enabled it holds a lock on those pins preventing them from being used for sdioio. The settings.toml config CIRCUITPY_SDCARD_USB already disabled the automount, but was still holding the pins even when set to false. This PR changes the behavior to not hold the pins when the config is False. I did not look into changing the automount over to use sdio, maybe that would be a good option in the long term? For right now you must have CIRCUITPY_SDCARD_USB = false in settings.toml to use this.

@mikeysklar You recently did a bunch of sd card testing. If you're interested in trying this out it would be appreciated.

@FoamyGuy

FoamyGuy commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator Author

pre-commit run -a was passing for me with all green. I had to manually run python3 tools/codeformat.py -v -c [file] against the files in the actions log to get it to actually format those files for me locally.

@mikeysklar

mikeysklar commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Nice work, Foamy. This is the fastest setup I've seen. You cracked the 10 MB/s write speed. This is now competitive with Arduino code.

SDIO on RP2350 ~4x faster for bulk read / write than SPI mode.
SDIO on RP2350 ~10% slower for log/lines (small writes) than SPI mode.

Benchmarking using SD Card Performance Guide example code / configuration.

+-------------+-------+-------+-------+
|             | Bulk  | Bulk  | Log   |
|             | read  | write | lines |
| Bus         | MB/s  | MB/s  | /sec  |
+-------------+-------+-------+-------+
| RP2350 SPI  |  2.3  |  2.3  | 2581  |
|  @25MHz     |       |       |       |
+-------------+-------+-------+-------+
| ESP32-S3    |  7.1  |  4.5  | 1489  |
|  SDIO       |       |       |       |
|  @40MHz     |       |       |       |
+-------------+-------+-------+-------+
| RP2350 SDIO |  8.7  | 10.4  | 2278  |
|  @25MHz     |       |       |       |
|  (this PR)  |       |       |       |
+-------------+-------+-------+-------+
| SDIO vs SPI | 3.8x  | 4.5x  | 0.88x |
|  (RP2350)   | up    | up    | down  |
+-------------+-------+-------+-------+

Note: I did need to do one single hard power cycle - unplug - the board after updating to the new build to transition from SPI -> SDIO mode.

@mikeysklar

mikeysklar commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Feather RP2040 Adalogger 5x improvement with SDIO over SPI for bulk rd/wr. Small bump up in log lines.

+----------------------------+------+-----+------+
| Board / Bus                | Wr   | Rd  | Log  |
+----------------------------+------+-----+------+
| Feather RP2040 Adalogger   |  1.9 | 1.8 | 1065 |
|  SPI (built-in)            |      |     |      |
+----------------------------+------+-----+------+
| ESP32-S3                   |  4.5 | 7.1 | 1489 |
|  4-bit SDIO @40MHz         |      |     |      |
+----------------------------+------+-----+------+
| Metro RP2350               | 10.4 | 8.7 | 2278 |
|  4-bit SDIO @25MHz         |      |     |      |
+----------------------------+------+-----+------+
| Feather RP2040 Adalogger   |  9.6 | 8.1 | 1160 |
|  SDIO @25MHz               |      |     |      |
+----------------------------+------+-----+------+
Wr/Rd = MB/s, Log = lines/sec

Turn on the PIO SDIO driver for the Feather RP2040 Adalogger's built-in
microSD slot, which is already wired for 4-bit SDIO on consecutive GPIOs
(CLK=GPIO18, CMD=GPIO19, DAT0..3=GPIO20..23).

Set CIRCUITPY_SDIOIO = 1 and add the standard SDIO_CLOCK / SDIO_COMMAND /
SDIO_DATA0..3 pin aliases plus the SDIO_DATA four-pin tuple, matching the
Metro RP2350 board's pattern so board.SDIO_DATA works out of the box.

Tested on hardware: mounts at 25 MHz 4-bit and benchmarks ~9.6 MB/s write,
~8.1 MB/s read (bulk 4096x16) vs ~1.9 / 1.8 MB/s over the SPI auto-mount on
the same board and card -- roughly a 5x throughput improvement. The vendored
SdFat PIO driver builds cleanly for RP2040 (the RP2350-only gpio_base block
compiles out); firmware fits at 92% of the FLASH region.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@mikeysklar

mikeysklar commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Feather RP2350 ADA#6000 + SDIO Breakout ADA#4682

Good results nearly identical to the Metro RP2350

+---------------------------------+--------+------+------+------+
| Board (SDIO @25MHz)             | Chip   | Wr   | Rd   | Log  |
+---------------------------------+--------+------+------+------+
| Feather RP2040 Adalogger        | RP2040 |  9.6 |  8.1 | 1160 |
|  (onboard slot)                 |        |      |      |      |
+---------------------------------+--------+------+------+------+
| Metro RP2350                    | RP2350 | 10.4 |  8.7 | 2278 |
|  (onboard slot)                 |        |      |      |      |
+---------------------------------+--------+------+------+------+
| Feather RP2350 + #4682 breakout | RP2350 | 10.3 |  8.7 | 2352 |
|  (A0-A3 wiring)                 |        |      |      |      |
+---------------------------------+--------+------+------+------+
Wr/Rd = MB/s, Log = lines/sec.  All 4-bit SDIO @25MHz, best-of-3.
Breakout #4682 Feather GPIO SDIO Wire
CLK SCK 22 Clock 🟡 Yellow
CMD MOSI 23 Command 🔵 Blue
D0 A0 26 Data 0 🟢 Green
D1 A1 27 Data 1 🟠 Orange
DAT2 A2 28 Data 2 🟣 Purple
D3 A3 29 Data 3 🟤 Brown
DET MISO 20 Card-detect ⚪ White
3V 3V Power 🔴 Red
GND GND Ground ⚫ Black

Compiled with :

CIRCUITPY_SDIOIO = 1

in:

ports/raspberrypi/boards/adafruit_feather_rp2350/mpconfigboard.mk

It costs 10 KB of flash / 2 KB of SRAM to enable SDIO by default for the Feather RP2350. It's not a lot, but also a little hard to justify as most people would not be using SDIO on the Feather RP2350.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants