Skip to content

Commit

Permalink
stability: add SPI lock before saving via littleFS
Browse files Browse the repository at this point in the history
  • Loading branch information
mverch67 authored and caveman99 committed Oct 26, 2024
1 parent 2568d4f commit a8bd1ee
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/mesh/NodeDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#if HAS_WIFI
#include "mesh/wifi/WiFiAPClient.h"
#endif
#include "SPILock.h"
#include "modules/StoreForwardModule.h"
#include <Preferences.h>
#include <esp_efuse.h>
Expand Down Expand Up @@ -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);
Expand Down

1 comment on commit a8bd1ee

@kchiem
Copy link

@kchiem kchiem commented on a8bd1ee Oct 27, 2024

Choose a reason for hiding this comment

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

Probably should have moved the comment along with the function call ?

// Init our SPI controller (must be before screen and lora)

Please sign in to comment.