From a8bd1ee0da3a0e68bb9449314d1b0e77f1f12067 Mon Sep 17 00:00:00 2001 From: mverch67 Date: Fri, 25 Oct 2024 16:09:49 +0200 Subject: [PATCH] stability: add SPI lock before saving via littleFS --- src/main.cpp | 3 ++- src/mesh/NodeDB.cpp | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index e71d1df5f..6bf38b524 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -642,6 +642,8 @@ void setup() rp2040Setup(); #endif + initSPI(); // needed here before reading from littleFS + // We do this as early as possible because this loads preferences from flash // but we need to do this after main cpu init (esp32setup), because we need the random seed set nodeDB = new NodeDB; @@ -705,7 +707,6 @@ void setup() #endif // Init our SPI controller (must be before screen and lora) - initSPI(); #ifdef ARCH_RP2040 #ifdef HW_SPI1_DEVICE SPI1.setSCK(LORA_SCK); diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index 87a7ad091..69cd631c0 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -32,6 +32,7 @@ #if HAS_WIFI #include "mesh/wifi/WiFiAPClient.h" #endif +#include "SPILock.h" #include "modules/StoreForwardModule.h" #include #include @@ -870,6 +871,9 @@ void NodeDB::loadFromDisk() bool NodeDB::saveProto(const char *filename, size_t protoSize, const pb_msgdesc_t *fields, const void *dest_struct, bool fullAtomic) { +#ifdef ARCH_ESP32 + concurrency::LockGuard g(spiLock); +#endif bool okay = false; #ifdef FSCom auto f = SafeFile(filename, fullAtomic);