Page 1 of 2

store data in Flash (not Spiff)

Posted: Tue Jan 15, 2019 9:27 pm
by schuppeste
Hi,

At the moment I compile a 1.3MB array in my code, I want to put this byte array now in Flash to save compile time. Whats the best way to do this?

Spiff is too slow. My first try was write directly to flash partition.. but it did not work.

Could be the fastest way to work on mapping?Or store data at end of program Flash?

Re: store data in Flash (not Spiff)

Posted: Wed Jan 16, 2019 8:54 am
by ESP_Sprite
How did it not work? Storing data in a raw partition and mmapping it is a tried & true method.

Re: store data in Flash (not Spiff)

Posted: Wed Jan 16, 2019 9:56 am
by schuppeste
It is possible to mmap to Mybin.bin in Spiff if i know the startbyte?

Here is my try and Error(actest is my array):

Code: Select all



#include "FS.h"
#include <TFT_eSPI.h>
#include <SPI.h>
#include "test.h"

TFT_eSPI tft = TFT_eSPI();
#define TRUE 1
#define FALSE 0

#define SPI2_NSS_PIN 28
static const int spiClk = 40000000; // 1 MHz
SPIClass * vspi = NULL;
//#include <Arduino.h>
#include "esp_spi_flash.h"
#include "esp_partition.H"
#include <stdint.h>
int statuss = 0;
static esp_partition_t *epp;

void setup()
{
  unsigned long i, s;
  uint8_t *buf = (uint8_t *)malloc(4096);
  pinMode (LED_BUILTIN, OUTPUT);
  Serial.begin(921600);

  Serial.println("FLASH FILE SYSTEM TEST");
  epp = (esp_partition_t *)esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL);
  if (!epp) {
    Serial.println("Can't find spiffs partition");
    while (1);
  }
  Serial.printf("DATA Subtype=%d add=%x size=%x lbl=%s enc=%d\n", epp->subtype, epp->address, epp->size, epp->label, epp->encrypted);
  int y = 0;
  i = 0;
  Serial.setTimeout(5000);
  Serial.println("Write one sector");

  while (Serial.readBytes(buf, 4096) != 0 && i < 1187840)
  {
    esp_partition_erase_range(epp, i, sizeof(_actest));

    if (esp_partition_write(epp, i, _actest, sizeof(_actest))) {
      Serial.println("Write Error");
    }
    else {
      Serial.println("Write OK");
    }
    i = i + 4096;
  }
}

void loop()
{

}

Re: store data in Flash (not Spiff)

Posted: Thu Jan 17, 2019 1:20 am
by ESP_Sprite
No, you cannot mmap files on fat or spiffs. Mmapping needs the files to be aligned to the pages of the MMU, and none of the filesystems in esp-idf do that.

Re: store data in Flash (not Spiff)

Posted: Thu Jan 17, 2019 5:47 am
by schuppeste
Ok, i have start a new try..

i created a new partition in arduino Default.csv and uploaded my Pictures.bin with Downloader tool to the startaddress of the Partition.

Now I try to read the image data:

Code: Select all

const esp_partition_t* partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA,ESP_PARTITION_SUBTYPE_ANY, "storage");
and replace my SPIFF Read with:

Code: Select all

esp_partition_read( partition, pictureoffset, data, width*3 );
The Picture data/Bytes is not 100% the same,I have to keep looking. From Picture to Picture i can see Partial Results.

Re: store data in Flash (not Spiff)

Posted: Thu Jan 17, 2019 5:55 pm
by schuppeste
Done!

I create my own Custom Partition and Uploaded my Pictures.bin to this Partition. After Mapping the Partition i can join the data on Data Pointer Very Fast.

Code: Select all

const esp_partition_t* part;
spi_flash_mmap_handle_t handle;
void* data;
esp_err_t err;

void setup(){
part=  esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_ANY, "storage");
err = esp_partition_mmap(part, 0, part->size, SPI_FLASH_MMAP_DATA, (const void**)&data, &handle);
vspi->writeBytes((uint8_t*)data+offsetBackground, width *high* 3);
}

Re: store data in Flash (not Spiff)

Posted: Fri Jan 18, 2019 10:55 am
by Bodmer
One option is to buy an ESP32 board with PSRAM fitted and copy the SPIFFS image to PSRAM at boot up. You will then get much faster random access to the data set just using pointers. If PSRAM is available, the TFT_eSPI library uses that memory area and technique for Sprites, so examining the Sprite.cpp file in the library may help you figure it out.

Re: store data in Flash (not Spiff)

Posted: Fri Jan 18, 2019 4:59 pm
by schuppeste
Fast enough for my Project..

As Final Step i Change the App Partition to 3.5MB and add my binary Data as constant array. Maybe ist the same Speed.. the Display Limit is 40mhz.

@Bodmer
i use TFT_espi.. its a good Library ;)

But for ILI9488 i made many optimizations, Transparency Functions, Speedup etc.

Code: Select all

//Max SPI Speed
 tft.setWindow(x, y, x + width - 1, y + height - 1);
  vspi->beginTransaction(SPISettings(spiClk, MSBFIRST, SPI_MODE0));
  digitalWrite(5, LOW); 
    vspi->writeBytes((uint8_t*)data + offset, width * 3);
  }
  digitalWrite(5, HIGH); 

Re: store data in Flash (not Spiff)

Posted: Sat Nov 09, 2019 7:23 am
by chief23c
I am working on similar project as you mention above, I am wondering could you share the final completed code for my reference. If you do that will be wonderful.Thanks. I am having a hard time match the mapping data .

Re: store data in Flash (not Spiff)

Posted: Tue Nov 12, 2019 11:47 am
by schuppeste
I have posted an example on Hackaday:

https://hackaday.io/project/166021-esp3 ... on-mapping