So if I do an operation on 500KB, that involves processing the data multiple times in multiple ways in PSRAM, it is instant from the user point of view. But loading two 500KB files takes over 4 seconds, about the same speed as writing, which also sometimes produces interrupt watchdog timeouts like OTA updates do with large partitions when the CAN driver is active since the CAN driver's interrupt functions do not seem to be in IRAM. It is actually faster to get stuff from a websocket over Wifi than it is to get it from the SPI flash using VFS/FATFS. It is really quick if a file is embedded but I need encrypted flash and the flexibility to write occasionally.
I'm using 4096 byte sectors and performance mode. I'm starting to think I need to read and write partitions separately, but that is a real shame to fragment a system that otherwise gives a lot of flexibility. I'm having to start threading file opens whilst other things happen as they are so obviously slow. For saving, I'm saving to a RAM disk to speed things up (like saving half a second when writing a few bytes). It is manageable, just, but it is the one area I'm really fighting, performance is otherwise stellar and once stuff is in PSRAM, the thing flies along.
Is this performance expected? Code snippet for reading a file into a RAM buffer included. It is pretty standard stuff unless I'm doing something wrong with fread parameter that is 1, but that was my understanding of how to use it. It is the fread that takes all the time, CPU speed is 240MHz, flash is 16MB WROVER at 80MHz QIO. CPU usage from other tasks is a few percent total.
Code: Select all
//open file
FILE* f = NULL;
f = fopen(filepath, "rb");
if (!f) {
my_print_web("*Unable to open file %s for reading!", filepath);
return false;
}
//get filesize
fseek(f, 0, SEEK_END);
int filesize = ftell(f);
fseek(f, 0, SEEK_SET);
*pstart = (uint8_t*)malloc(filesize);
if (!*pstart){
my_print_web("*Unable to malloc file %s size %d!", filepath, filesize);
retval = false;
}
//read file
else{
if (fread(*pstart, filesize, 1, f) != 1){
my_print_web("*Error reading file %s size %d!", filepath, filesize);
free(*pstart);
*pstart = NULL;
retval = false;
}else{
*pend = *pstart + filesize;
}
}
fclose(f);