From f52e2ea8efa096a77e95a59df423a49cfef3a141 Mon Sep 17 00:00:00 2001 From: Manuel <71137295+mverch67@users.noreply.github.com> Date: Fri, 10 Jul 2026 22:00:32 +0200 Subject: [PATCH] fix SPI1 instances (#10983) --- src/main.cpp | 8 ++++++++ src/mesh/RadioInterface.cpp | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 63cbf35ab..cc7c239a4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -196,8 +196,16 @@ void setupNicheGraphics(); #endif #if defined(HW_SPI1_DEVICE) && defined(ARCH_ESP32) +#if defined(HAS_SDCARD) && defined(SDCARD_USE_SPI1) +// Reuse FSCommon's SPI_HSPI instance to avoid double-initializing SPI2_HOST in arduino-esp32 3.x. +// Two SPIClass(HSPI) objects on the same bus cause the second spi_bus_initialize() to return +// ESP_ERR_INVALID_STATE, leaving the LoRa device handle invalid and blocking SPI transfers. +extern SPIClass SPI_HSPI; +SPIClass &SPI1 = SPI_HSPI; +#else SPIClass SPI1(HSPI); #endif +#endif using namespace concurrency; diff --git a/src/mesh/RadioInterface.cpp b/src/mesh/RadioInterface.cpp index fac3aff59..5a3215fee 100644 --- a/src/mesh/RadioInterface.cpp +++ b/src/mesh/RadioInterface.cpp @@ -337,8 +337,12 @@ LoRaRadioType radioType = NO_RADIO; extern RadioLibHal *RadioLibHAL; #if defined(HW_SPI1_DEVICE) && defined(ARCH_ESP32) +#if defined(HAS_SDCARD) && defined(SDCARD_USE_SPI1) +extern SPIClass &SPI1; // alias for SPI_HSPI; both on SPI2_HOST +#else extern SPIClass SPI1; #endif +#endif std::unique_ptr initLoRa() {