store data in Flash (not Spiff)
-
- Posts: 8
- Joined: Tue Jan 15, 2019 9:19 pm
store data in Flash (not Spiff)
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?
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?
-
- Posts: 9708
- Joined: Thu Nov 26, 2015 4:08 am
Re: store data in Flash (not Spiff)
How did it not work? Storing data in a raw partition and mmapping it is a tried & true method.
-
- Posts: 8
- Joined: Tue Jan 15, 2019 9:19 pm
Re: store data in Flash (not Spiff)
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):
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()
{
}
-
- Posts: 9708
- Joined: Thu Nov 26, 2015 4:08 am
Re: store data in Flash (not Spiff)
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.
-
- Posts: 8
- Joined: Tue Jan 15, 2019 9:19 pm
Re: store data in Flash (not Spiff)
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:
and replace my SPIFF Read with:
The Picture data/Bytes is not 100% the same,I have to keep looking. From Picture to Picture i can see Partial Results.
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");
Code: Select all
esp_partition_read( partition, pictureoffset, data, width*3 );
-
- Posts: 8
- Joined: Tue Jan 15, 2019 9:19 pm
Re: store data in Flash (not Spiff)
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.
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)
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.
-
- Posts: 8
- Joined: Tue Jan 15, 2019 9:19 pm
Re: store data in Flash (not Spiff)
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.
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)
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 .
-
- Posts: 8
- Joined: Tue Jan 15, 2019 9:19 pm
Who is online
Users browsing this forum: No registered users and 30 guests