SDFat can't write to files once LVGL timer handler starts


I can read and write to my SD card during setup, but once I’m in the main loop and lv_timer_handler() is called, any interaction with the SD card results in failed reads or writes. My read/write code passes units tests, but fails when integrated into LVGL.

What MCU/Processor/Board and compiler are you using?

Arduino Nano RP2040 Connect, Arduino IDE 2.2.1, latest Arduino board definition.

What LVGL version are you using?

8.3.6 (I’m generating my interfaces from SquareLine Studio, and this is the latest LVGL it supports.

What do you want to achieve?

I’d like to be able to read and write the SD card

What have you tried so far?

  1. writing in ‘loop’ rather than in my code (called from LVGL events) in case it’s a weird timing issue - fails
  2. localising all SD interactions in my code and executing sd.begin() to create a new instance to the SD card in case (somehow) LVGL is stopping the SD card. fails.
  3. changing SPI frequencies. Nothing words once lv_timer_handler() is being called.
  4. Moving from SD to littleFS (to access the flash on the RP2040 instead). Same issue - once running in the main loop, we can’t read or write to the storage.

Plea for Help

This is driving me mad, and as you can imagine our product is going to struggle if we can’t data-log.

Code to reproduce

bool persistentTuple::persist() {
  if (fsPtr == nullptr) {
    Serial.println("Filesystem not initialized.");
    return false;
  File file = fsPtr->open(path.c_str(), O_WRITE | O_CREAT);
  Serial.print("Write error code: ");
  if (file) {
    return true;
  } else {
    return false;