store data in Flash (not Spiff)

schuppeste
Posts: 6
Joined: Tue Jan 15, 2019 9:19 pm

store data in Flash (not Spiff)

Postby schuppeste » Tue Jan 15, 2019 9:27 pm

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?

ESP_Sprite
Posts: 2666
Joined: Thu Nov 26, 2015 4:08 am

Re: store data in Flash (not Spiff)

Postby ESP_Sprite » Wed Jan 16, 2019 8:54 am

How did it not work? Storing data in a raw partition and mmapping it is a tried & true method.

schuppeste
Posts: 6
Joined: Tue Jan 15, 2019 9:19 pm

Re: store data in Flash (not Spiff)

Postby schuppeste » Wed Jan 16, 2019 9:56 am

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()
{

}

ESP_Sprite
Posts: 2666
Joined: Thu Nov 26, 2015 4:08 am

Re: store data in Flash (not Spiff)

Postby ESP_Sprite » Thu Jan 17, 2019 1:20 am

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.

schuppeste
Posts: 6
Joined: Tue Jan 15, 2019 9:19 pm

Re: store data in Flash (not Spiff)

Postby schuppeste » Thu Jan 17, 2019 5:47 am

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.

schuppeste
Posts: 6
Joined: Tue Jan 15, 2019 9:19 pm

Re: store data in Flash (not Spiff)

Postby schuppeste » Thu Jan 17, 2019 5:55 pm

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);
}

Bodmer
Posts: 4
Joined: Sun Mar 25, 2018 5:44 pm

Re: store data in Flash (not Spiff)

Postby Bodmer » Fri Jan 18, 2019 10:55 am

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.

schuppeste
Posts: 6
Joined: Tue Jan 15, 2019 9:19 pm

Re: store data in Flash (not Spiff)

Postby schuppeste » Fri Jan 18, 2019 4:59 pm

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); 

Who is online

Users browsing this forum: No registered users and 9 guests