Does SPIFFS resulted ESP32 repeated restarts?

Hi everyone.
this is a simple sketch that should just list the files in SPIFFS, but it repeated list and restarts ? why?
Thanks
Adam



  
#include "SPIFFS.h"
 
void listAllFiles(){
 
  File root = SPIFFS.open("/");
 
  File file = root.openNextFile();
 
  while(file){
 
      Serial.print("FILE: ");
      Serial.println(file.name());
 
      file = root.openNextFile();
  }
 
}
 
void setup() {
 
  Serial.begin(115200);
 
  if (!SPIFFS.begin(true)) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
 
  File file = SPIFFS.open("/test.txt", FILE_WRITE);
 
  if (!file) {
    Serial.println("There was an error opening the file for writing");
    return;
  }
 
  if (file.print("some content")) {
    Serial.println("File was written");
  } else {
    Serial.println("File write failed");
  }
 
  file.close();
 
  Serial.println("\n\n---BEFORE RENAMING---");
  listAllFiles();
 
  SPIFFS.rename("/test.txt", "/renamed.txt");
 
  Serial.println("\n\n---AFTER RENAMING---");
  listAllFiles();
 
}
 
void loop() {}


ERROR:

12:49:57.010 -> ELF file SHA256: 0000000000000000
12:49:57.010 -> 
12:49:57.010 -> Rebooting...
12:49:57.010 -> ets Jul 29 2019 12:21:46
12:49:57.010 -> 
12:49:57.010 -> rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
12:49:57.010 -> configsip: 0, SPIWP:0xee
12:49:57.010 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
12:49:57.010 -> mode:DIO, clock div:2
12:49:57.010 -> load:0x3fff0030,len:1344
12:49:57.010 -> load:0x40078000,len:13836
12:49:57.010 -> load:0x40080400,len:3608
12:49:57.010 -> entry 0x400805f0
12:49:57.247 -> File was written
12:49:57.247 -> 
12:49:57.247 -> 
12:49:57.247 -> ---BEFORE RENAMING---
12:49:57.315 -> FILE: hello.txt
12:49:57.349 -> FILE: renamed.txt
12:49:57.349 -> FILE: test.txt
12:49:57.383 -> 
12:49:57.383 -> 
12:49:57.383 -> ---AFTER RENAMING---
12:49:57.485 -> FILE: hello.txt
12:49:57.485 -> FILE: renamed.txt
12:49:57.485 -> FILE: test.txt

They could, depending upon your partition scheme.

Did you put the debug info into the ESP Exception Decoder and post the results here?

did you try this

#include "SPIFFS.h"
 
void listAllFiles(){
 
  File root = SPIFFS.open("/");
 
  File file = root.openNextFile();
 
  while(file){
 
      Serial.print("FILE: ");
      Serial.println(file.name());
 
      file = root.openNextFile();
  }
 
}
 
void setup() {
 
  Serial.begin(115200);
 
  if (!SPIFFS.begin(true)) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
 
  //File file = SPIFFS.open("/test.txt", FILE_WRITE);
 
  //if (!file) {
  //  Serial.println("There was an error opening the file for writing");
   // return;
 // }
 
  //if (file.print("some content")) {
   // Serial.println("File was written");
  //} else {
    //Serial.println("File write failed");
  //}
 
  //file.close();
 
//  Serial.println("\n\n---BEFORE RENAMING---");
 // listAllFiles();
 
 // SPIFFS.rename("/test.txt", "/renamed.txt");
 
//  Serial.println("\n\n---AFTER RENAMING---");
  //listAllFiles();
 
}

void loop() {}

Did it work?
then try this

#include "SPIFFS.h"
 
void listAllFiles(){
 
  File root = SPIFFS.open("/");
 
  File file = root.openNextFile();
 
  while(file){
 
      Serial.print("FILE: ");
      Serial.println(file.name());
 
      file = root.openNextFile();
  }
 
}
 
void setup() {
 
  Serial.begin(115200);
 
  if (!SPIFFS.begin(true)) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
 
  File file = SPIFFS.open("/test.txt", FILE_WRITE);
 
  //if (!file) {
  //  Serial.println("There was an error opening the file for writing");
   // return;
 // }
 
  //if (file.print("some content")) {
   // Serial.println("File was written");
  //} else {
    //Serial.println("File write failed");
  //}
 
  //file.close();
 
//  Serial.println("\n\n---BEFORE RENAMING---");
 // listAllFiles();
 
 // SPIFFS.rename("/test.txt", "/renamed.txt");
 
//  Serial.println("\n\n---AFTER RENAMING---");
  //listAllFiles();
 
}

void loop() {}

If that worked did you try this

#include "SPIFFS.h"
 
void listAllFiles(){
 
  File root = SPIFFS.open("/");
 
  File file = root.openNextFile();
 
  while(file){
 
      Serial.print("FILE: ");
      Serial.println(file.name());
 
      file = root.openNextFile();
  }
 
}
 
void setup() {
 
  Serial.begin(115200);
 
  if (!SPIFFS.begin(true)) {
    Serial.println("An Error has occurred while mounting SPIFFS");
    return;
  }
 
  File file = SPIFFS.open("/test.txt", FILE_WRITE);
 
  if (!file) {
  //  Serial.println("There was an error opening the file for writing");
   // return;
  }
 
  //if (file.print("some content")) {
   // Serial.println("File was written");
  //} else {
    //Serial.println("File write failed");
  //}
 
  //file.close();
 
//  Serial.println("\n\n---BEFORE RENAMING---");
 // listAllFiles();
 
 // SPIFFS.rename("/test.txt", "/renamed.txt");
 
//  Serial.println("\n\n---AFTER RENAMING---");
  //listAllFiles();
 
}

void loop() {}

? did it work?

You caught on to what I'm doing?

1 Like

Thank you Idahowalker.

I tested the first sketch and got that rebooting again.

the Exception Decoder debug info:

0x400833d5: panic_abort at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/esp_system/panic.c line 402

does this reboot?

#include "SPIFFS.h"
 
//void listAllFiles(){
 
//  File root = SPIFFS.open("/");
 
 // File file = root.openNextFile();
 
 // while(file){
 
    //  Serial.print("FILE: ");
//      Serial.println(file.name());
 
  //    file = root.openNextFile();
  //}
 
//}
 
void setup() {
 
  //Serial.begin(115200);
 
  //if (!SPIFFS.begin(true)) {
  //  Serial.println("An Error has occurred while mounting SPIFFS");
  //  return;
 // }
 
  //File file = SPIFFS.open("/test.txt", FILE_WRITE);
 
  //if (!file) {
  //  Serial.println("There was an error opening the file for writing");
   // return;
 // }
 
  //if (file.print("some content")) {
   // Serial.println("File was written");
  //} else {
    //Serial.println("File write failed");
  //}
 
  //file.close();
 
//  Serial.println("\n\n---BEFORE RENAMING---");
 // listAllFiles();
 
 // SPIFFS.rename("/test.txt", "/renamed.txt");
 
//  Serial.println("\n\n---AFTER RENAMING---");
  //listAllFiles();
 
}

void loop() {}
1 Like

still.

disconnect everything but power/gnd. upload a blank sketch. does it reboot? If you post an image of your project wall wired up and not working.

1 Like

Thanks.
a blank sketch still rebooting.
nothing wiring on, just USB power cable, and also tried extra 5V/GND to Vin/GND some time.

uploaded example Blink with LED redefine to 2 works well, without reboot.

Maybe try this

#include "SPIFFS.h"
void setup() {
  Serial.begin(115200);
  if (!SPIFFS.begin(true)) {
    Serial.println("ERROR");
    return;
  }
  SPIFFS.remove("/renamed.txt");
}
void loop() {
}
2 Likes

Great!
Sorry, this sketch works well itself.
made rebooting again when moved to the post#1 sketch. actually added the line: SPIFFS.remove("/renamed.txt");

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.