-->
Page 1 of 2

Save 5 large arrays to FLASH

PostPosted: Fri Apr 13, 2018 10:42 am
by atticus
Hi

I am trying to save 5 large arrays to flash as i do not have enough SRAM. The arrays are char array[30000]. The array gets filled with sensor data really fast so i need to fill it up, dump to flash, fill it up, dump to flash about 5 times. The data dumped to the flash will be retrieved afterwards for displaying on a graph format via a web page.

I have tested SPIFFS to write the a char array[2048] to flash. If i am correct, i understand that the flash has 4096 byte sectors that must be written to. This means i will need to write +- 75 sectors to save my 5 large arrays.

The way i think i should do this is as follows:

Code: Select all// open file for writing
  File f = SPIFFS.open("/f.txt", "w");
  if (!f) {
      Serial.println("file open failed");
  }
  Serial.println("====== Writing to SPIFFS file =========");
  // write 10 strings to file
  for (int i=1; i<=2048; i++){
    f.println(sensor_byte);
  }



My Question/Confusion

How do i write the large array to the file? Do I need to manage writing the data at 4096 byte chunks? Should I loop 75 times and append the file? I fail to write 4096 bytes as the esp wdt forces a reset. I am not sure if this is because of the serial display.

Re: Save 5 large arrays to FLASH

PostPosted: Sun Apr 15, 2018 2:57 am
by schufti
I can't say anything to the rest of your post but the wdt should be solved by this mod

Code: Select all  for (int i=1; i<=2048; i++){
    f.println(sensor_byte);
    yield();
  }

Re: Save 5 large arrays to FLASH

PostPosted: Sun Apr 15, 2018 12:10 pm
by atticus
What does yeild(); do?

Re: Save 5 large arrays to FLASH

PostPosted: Sun Apr 15, 2018 12:51 pm
by martinayotte
It lets other SDK tasks having chance to run, such as the WiFi task.
delay() is also doing that, but, of course, it is also inserting a delay ...