From 3892bc7a1a98662fb1736ce8a10dda59eb290128 Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Wed, 17 Dec 2025 17:49:52 +0100 Subject: [PATCH] Support SDCard on SPI bus 2 (if present) --- tasmota/include/tasmota_template.h | 2 +- tasmota/tasmota_xdrv_driver/xdrv_50_filesystem.ino | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/tasmota/include/tasmota_template.h b/tasmota/include/tasmota_template.h index d9e3161ac..e8bcde86e 100644 --- a/tasmota/include/tasmota_template.h +++ b/tasmota/include/tasmota_template.h @@ -656,7 +656,7 @@ const uint16_t kGpioNiceList[] PROGMEM = { AGPIO(GPIO_RC522_RST), // RC522 Rfid Reset #endif #ifdef USE_SDCARD - AGPIO(GPIO_SDCARD_CS), // SDCard in SPI mode + AGPIO(GPIO_SDCARD_CS) + AGMAX(MAX_SPI), // SDCard in SPI mode #endif // USE_SDCARD #if defined(USE_MCP2515) || defined(USE_CANSNIFFER) AGPIO(GPIO_MCP2515_CS), diff --git a/tasmota/tasmota_xdrv_driver/xdrv_50_filesystem.ino b/tasmota/tasmota_xdrv_driver/xdrv_50_filesystem.ino index f016ffffd..5739c835a 100644 --- a/tasmota/tasmota_xdrv_driver/xdrv_50_filesystem.ino +++ b/tasmota/tasmota_xdrv_driver/xdrv_50_filesystem.ino @@ -194,14 +194,26 @@ char *fileOnly(char *fname){ void UfsCheckSDCardInit(void) { // Try SPI mode first // SPI mode requires SDCARD_CS to be configured +/* if (TasmotaGlobal.spi_enabled && PinUsed(GPIO_SDCARD_CS)) { int8_t cs = Pin(GPIO_SDCARD_CS); +*/ + uint32_t spi_bus = 0; + int8_t cs = -1; + if (TasmotaGlobal.spi_enabled && PinUsed(GPIO_SDCARD_CS)) { + cs = Pin(GPIO_SDCARD_CS); + } + if (TasmotaGlobal.spi_enabled2 && PinUsed(GPIO_SDCARD_CS, 1)) { + spi_bus = 1; + cs = Pin(GPIO_SDCARD_CS, 1); + } + if (cs > -1) { #ifdef ESP8266 SPI.begin(); #endif // ESP8266 #ifdef ESP32 - SPI.begin(Pin(GPIO_SPI_CLK), Pin(GPIO_SPI_MISO), Pin(GPIO_SPI_MOSI), -1); + SPI.begin(Pin(GPIO_SPI_CLK, spi_bus), Pin(GPIO_SPI_MISO, spi_bus), Pin(GPIO_SPI_MOSI, spi_bus), -1); #endif // ESP32 if (SD.begin(cs)) {