Skip to content
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9dbe71c
Adjust SPI configuration for ESP32-S3 support
Will-wastelander Jun 14, 2026
11e3e9e
Make SD card pin configuration customizable
Will-wastelander Jun 15, 2026
80490a6
Update readme with SD card pin customization
Will-wastelander Jun 15, 2026
d38fd09
Improve formatting of SD card configuration code
Will-wastelander Jun 15, 2026
96f21c1
Added original comments back
Will-wastelander Jun 15, 2026
4920af2
Change SPI port from HSPI to FSPI for ESP32-S3
Will-wastelander Jun 15, 2026
c5d03af
Change pin configuration types from int8_t to uint8_t
Will-wastelander Jun 15, 2026
f6567cc
Update usermods/sd_card/sd_card.cpp
Will-wastelander Jun 15, 2026
ad21b1d
Merge branch 'main' into main
Will-wastelander Jun 16, 2026
9a9ab8b
Change SPI port from FSPI to HSPI for ESP32-S3
Will-wastelander Jun 18, 2026
4e17ff4
Change pin configuration types from uint8_t to int8_t
Will-wastelander Jun 20, 2026
9684c95
Update SPI configuration for SD card support
Will-wastelander Jun 20, 2026
951f362
Define SD card configuration pins if not defined
Will-wastelander Jun 20, 2026
9dc89db
Refactor SD card pin configuration logic
Will-wastelander Jun 20, 2026
b802162
Merge branch 'main' into main
Will-wastelander Jun 20, 2026
0a001f6
Merge branch 'main' into main
Will-wastelander Jun 20, 2026
3db59af
Fix macro definitions for SD card pin configurations
Will-wastelander Jun 20, 2026
e67f030
Add warning for SD card and Ethernet conflicts
Will-wastelander Jun 21, 2026
ee61d98
Remove preprocessor directive for SD card SPI init
Will-wastelander Jun 21, 2026
e59482c
Merge branch 'main' into main
Will-wastelander Jun 22, 2026
9ca0dcc
Merge branch 'main' into main
Will-wastelander Jun 23, 2026
6dfe8a9
Merge branch 'main' into main
Will-wastelander Jun 24, 2026
2ef83c2
Merge branch 'main' into main
Will-wastelander Jun 25, 2026
1bd9c82
Refactor SD card SPI configuration handling
Will-wastelander Jun 28, 2026
1e3efd5
Fix formatting for SD_SPI configuration in sd_card.cpp
Will-wastelander Jun 29, 2026
c63ef25
Adjust SPI class initialization for ESP32-S3
Will-wastelander Jun 29, 2026
8edc19a
Merge branch 'main' into main
Will-wastelander Jun 30, 2026
0cecf56
sdcard: fix wrong macro, add "error" fallback
softhack007 Jul 3, 2026
7804918
fix a few more errors in macros
softhack007 Jul 3, 2026
e265710
always use HSPI
softhack007 Jul 3, 2026
b32e27a
add samity check for _both_ SPI and MMC being defined
softhack007 Jul 3, 2026
035024f
make github build happy
softhack007 Jul 3, 2026
c30a7c3
Merge branch 'main' into main
softhack007 Jul 3, 2026
64b2d68
Merge branch 'main' into main
softhack007 Jul 3, 2026
ea089a8
Merge branch 'main' into main
softhack007 Jul 3, 2026
03b07f4
minor improvements
softhack007 Jul 4, 2026
2430d75
Merge branch 'main' into main
Will-wastelander Jul 4, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions usermods/sd_card/platformio_override.ini.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
; Options
; -------
;; see readme.md


;; simple examples how to configure this usermod -> add to your platformio_override.ini

[env:esp32_sdcard_spi]
extends = env:esp32dev
custom_usermods = ${env:esp32dev.custom_usermods} sd_card
build_flags = ${env:esp32dev.build_flags}
-D WLED_USE_SD_SPI

[env:esp32_sdcard_mmc]
extends = env:esp32dev
custom_usermods = ${env:esp32dev.custom_usermods} sd_card
build_flags = ${env:esp32dev.build_flags}
-D WLED_USE_SD_MMC

[env:esp32S3_sdcard_spi]
extends = env:esp32s3dev_8MB_opi
custom_usermods = ${env:esp32s3dev_8MB_opi.custom_usermods} sd_card
build_flags = ${env:esp32s3dev_8MB_opi.build_flags}
-D WLED_USE_SD_SPI

[env:esp32S3_sdcard_mmc]
extends = env:esp32s3_4M_qspi
custom_usermods = ${env:esp32s3_4M_qspi.custom_usermods} sd_card
build_flags = ${env:esp32s3_4M_qspi.build_flags}
-D WLED_USE_SD_MMC


[env:esp32C3_sdcard_SPI]

@DedeHai DedeHai Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

C3 only has one SPI so SPI led output can not coexist,
both 2-pin as well as the future parallel SPI. I would also add a warning for C3.
also I dont think C3 uses "HSPI" as an alias so it will probably not compile

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"HSPI" compiles for -C3, I can't say if it works actually.

I've extended the 2-wire conflict warning to C3.

extends = env:esp32c3dev
custom_usermods = ${env:esp32c3dev.custom_usermods} sd_card
build_flags = ${env:esp32c3dev.build_flags}
-D WLED_USE_SD_SPI

[env:esp32S2_sdcard_SPI]
extends = env:lolin_s2_mini
custom_usermods = ${env:lolin_s2_mini.custom_usermods} sd_card
build_flags = ${env:lolin_s2_mini.build_flags}
-D WLED_USE_SD_SPI
1 change: 1 addition & 0 deletions usermods/sd_card/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- choose the way your SD is connected
1. via `-D WLED_USE_SD_MMC` when connected via MMC
2. via `-D WLED_USE_SD_SPI` when connected via SPI (use usermod page to setup SPI pins)
3. Customize pins with the following `-D UM_SD_SELECT=16 -D UM_SD_CLOCK=14 -D UM_SD_POCI=36 -D UM_SD_PICO=15`

### Test
- enable `-D SD_PRINT_HOME_DIR` and `-D WLED_DEBUG`
Expand Down
55 changes: 42 additions & 13 deletions usermods/sd_card/sd_card.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,39 @@
#define USED_STORAGE_FILESYSTEMS "SD SPI, LittleFS"
#include "SD.h"
#include "SPI.h"
#else
#error "Please define either WLED_USE_SD_MMC or WLED_USE_SD_SPI"
#endif
#if defined(WLED_USE_SD_SPI) && defined(WLED_USE_SD_MMC)
#error "Both WLED_USE_SD_MMC and WLED_USE_SD_SPI are defined, please use only one."
#endif

#ifdef WLED_USE_SD_MMC
#elif defined(WLED_USE_SD_SPI)
SPIClass spiPort = SPIClass(VSPI);

#ifndef UM_SD_SELECT
#define UM_SD_SELECT 16
#endif
#ifndef UM_SD_CLOCK
#define UM_SD_CLOCK 14
#endif
#ifndef UM_SD_POCI
#if CONFIG_IDF_TARGET_ESP32S3 && (CONFIG_SPIRAM_MODE_OCT || CONFIG_ESPTOOLPY_FLASHMODE_OPI) // on -S3 with octal (opi) flash or PSRAM, Pin 22-37 are not available
#define UM_SD_POCI 44
#else
#define UM_SD_POCI 36
#endif
#endif
#ifndef UM_SD_PICO
#define UM_SD_PICO 15
#endif


#ifndef WLED_USE_SD_MMC
// SD_MMC configuration handled elsewhere
// HSPI bus should be used both on -S3 and classic esp32; try VSPI (classic esp32) or FSPI (esp32-s3) in case of conflicts
SPIClass spiPort = SPIClass(HSPI);
#if defined(WLED_USE_ETHERNET)
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
#warning "SD card may have conflicts with 2-pin LEDs."
#endif
#endif

void listDir( const char * dirname, uint8_t levels);
Expand All @@ -24,11 +52,13 @@ class UsermodSdCard : public Usermod {
private:
bool sdInitDone = false;

#ifdef WLED_USE_SD_SPI
int8_t configPinSourceSelect = 16;
int8_t configPinSourceClock = 14;
int8_t configPinPoci = 36; // confusing names? Then have a look :)
int8_t configPinPico = 15; // https://www.oshwa.org/a-resolution-to-redefine-spi-signal-names/
// confusing names? Then have a look
// https://oshwa.org/resources/a-resolution-to-redefine-spi-signal-names/
#ifdef WLED_USE_SD_SPI
int8_t configPinSourceSelect = UM_SD_SELECT;
int8_t configPinSourceClock = UM_SD_CLOCK;
int8_t configPinPoci = UM_SD_POCI;
int8_t configPinPico = UM_SD_PICO;

//acquired and initialize the SPI port
void init_SD_SPI()
Expand All @@ -51,10 +81,9 @@ class UsermodSdCard : public Usermod {

bool returnOfInitSD = false;

#if defined(WLED_USE_SD_SPI)
spiPort.begin(configPinSourceClock, configPinPoci, configPinPico, configPinSourceSelect);
returnOfInitSD = SD_ADAPTER.begin(configPinSourceSelect, spiPort);
#endif
// This whole function is only enabled when compiling with WLED_USE_SD_SPI
spiPort.begin(configPinSourceClock, configPinPoci, configPinPico, configPinSourceSelect);
returnOfInitSD = SD_ADAPTER.begin(configPinSourceSelect, spiPort);

if(!returnOfInitSD) {
DEBUG_PRINTF("[%s] SPI begin failed!\n", _name);
Expand Down Expand Up @@ -241,4 +270,4 @@ void listDir( const char * dirname, uint8_t levels){
#endif

static UsermodSdCard sd_card;
REGISTER_USERMOD(sd_card);
REGISTER_USERMOD(sd_card);
Loading