Hi everyone,
I'm in the process of developing a project that has to log some sensor data to Flash.
Since I'm not capable of understanding every bit of the code in the LittleFS library, I run some tests to see if writing to a W25Q128JVSIM soldered to the teensy 4.1 bottom pads would block the execution of my code and for how long.
I've written this short sketch that I used to characterize the behaviour changing the size of buf[] via DIMEN definition:
I run tests with the following sizes :
DIMEN 32 Just calcs: 901 Calcs and write: 1198
DIMEN 64 Just calcs: 1796 Calcs and write: 2119
DIMEN 65 Just calcs: 1758 Calcs and write: ~29000000
DIMEN 128 Just calcs: 3396 Calcs and write: ~27000000
To me it seems that if I try to write more bytes that fit in a Flash page (64*4=256 bytes) it hangs the execution of the rest of the program for a while (about 48 ms).
Then I updated the Arduino IDE and Teensyduino from 1.55 to 1.56 and rerun some tests:
DIMEN 32 Just calcs: 935 Calcs and write: 1195
DIMEN 64 Just calcs: 1733 Calcs and write: 2061
DIMEN 65 Just calcs: 1759 Calcs and write: ~147000000 (actually varies from 132M to 147M)
DIMEN 128 Just calcs: 3396 Calcs and write: ~135000000(126M to 142M)
DIMEN 129 Just calcs: 3422 Calcs and write: ~135000000(pretty much the same as DIMEN 128)
Sadly I didn't test with higher DIMEN that 128 with the old version of teensyduino.
My questions are:
Why this much difference between the two versions of teensyduino?
Is there a way to make these larger writes non blocking? Would it be safe to execute large(ish) interrupts routine to keep my code running while it writes to flash?
Thanks, Leonardo
P.S. more informations about my project that I don't if are relevant:
I have a number of sensors connected via SPI that I read at around 1kHz (possibly more in the future). When I get a data ready signal via an interrupt pin I set a flag that tells me to retrieve data from the sensor in the next loop execution (or I could do that directly in the ISR, but I haven't decided yet).
I have to filter this data and check for some conditions to make certain actions. I the future I want to add some Serial communications to a GPS and a Lora module and also some active control that moves RC servos accordingly to the situation it senses.
I'm in the process of developing a project that has to log some sensor data to Flash.
Since I'm not capable of understanding every bit of the code in the LittleFS library, I run some tests to see if writing to a W25Q128JVSIM soldered to the teensy 4.1 bottom pads would block the execution of my code and for how long.
I've written this short sketch that I used to characterize the behaviour changing the size of buf[] via DIMEN definition:
Code:
#include <LittleFS.h>
#include <Entropy.h>
#define DIMEN 65
LittleFS_QSPIFlash myfs;
//LittleFS_QPINAND myfs;
uint32_t prevSysCount = 0;
uint32_t ticksTacken = 0;
void setup() {
Entropy.Initialize();
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
Serial.println("LittleFS Blocking Test");
if (!myfs.begin()) {
Serial.printf("Error starting %s\n", "QSPI FLASH");
while (1) ; // stop here
}
}
void loop() {
unsigned long buf[DIMEN];
File myfile = myfs.open("WriteSpeedTest.bin", FILE_WRITE_BEGIN);
if (myfile) {
prevSysCount = ARM_DWT_CYCCNT;
randomSeed(Entropy.random());
for (int i=0; i<DIMEN; i++) buf[i] = random();
ticksTacken = ARM_DWT_CYCCNT - prevSysCount;
Serial.print("Just calcs: ");
Serial.print(ticksTacken);
Serial.print(" ");
prevSysCount = ARM_DWT_CYCCNT;
randomSeed(Entropy.random());
for (int i=0; i<DIMEN; i++) buf[i] = random();
myfile.write(buf, DIMEN*4);
ticksTacken = ARM_DWT_CYCCNT - prevSysCount;
Serial.print("Calcs and write: ");
Serial.print(ticksTacken);
Serial.println();
myfile.close();
myfs.remove("WriteSpeedTest.bin");
}
delay(1000);
}
I run tests with the following sizes :
DIMEN 32 Just calcs: 901 Calcs and write: 1198
DIMEN 64 Just calcs: 1796 Calcs and write: 2119
DIMEN 65 Just calcs: 1758 Calcs and write: ~29000000
DIMEN 128 Just calcs: 3396 Calcs and write: ~27000000
To me it seems that if I try to write more bytes that fit in a Flash page (64*4=256 bytes) it hangs the execution of the rest of the program for a while (about 48 ms).
Then I updated the Arduino IDE and Teensyduino from 1.55 to 1.56 and rerun some tests:
DIMEN 32 Just calcs: 935 Calcs and write: 1195
DIMEN 64 Just calcs: 1733 Calcs and write: 2061
DIMEN 65 Just calcs: 1759 Calcs and write: ~147000000 (actually varies from 132M to 147M)
DIMEN 128 Just calcs: 3396 Calcs and write: ~135000000(126M to 142M)
DIMEN 129 Just calcs: 3422 Calcs and write: ~135000000(pretty much the same as DIMEN 128)
Sadly I didn't test with higher DIMEN that 128 with the old version of teensyduino.
My questions are:
Why this much difference between the two versions of teensyduino?
Is there a way to make these larger writes non blocking? Would it be safe to execute large(ish) interrupts routine to keep my code running while it writes to flash?
Thanks, Leonardo
P.S. more informations about my project that I don't if are relevant:
I have a number of sensors connected via SPI that I read at around 1kHz (possibly more in the future). When I get a data ready signal via an interrupt pin I set a flag that tells me to retrieve data from the sensor in the next loop execution (or I could do that directly in the ISR, but I haven't decided yet).
I have to filter this data and check for some conditions to make certain actions. I the future I want to add some Serial communications to a GPS and a Lora module and also some active control that moves RC servos accordingly to the situation it senses.