synestetic
Member
Hi, I ran into a problem while building an audio looper.
When I call file.erase() it actually blocks the code for a while, but when I call SerialFlash.exists() after, it still returns "true". If you remove the file with remove() after erase(), the exists() returns false. However, in both cases the file is not actually erased, and the chip eventually runs out of memory. I've put together a code that shows this issue. After running "eraseTest()" a number of timer (in my case with 8Mb chip - 11 tries) it's no longer able to create a new file, not until you run full chip erase.
Board: Teensy 3.6
Audio adapter with Winbond 25Q64FVSIG soldered onto the Audio board.
Arduino IDE 1.8.13
Teensyduino version 1.53
Windows 10
It seems that a friend of mine reproduced it with Teensy 4.0 and a breakout with SPI flash.
Here's the code that reproduces the problem:
Could anybody try running this? Any help would be much appreciated.
When I call file.erase() it actually blocks the code for a while, but when I call SerialFlash.exists() after, it still returns "true". If you remove the file with remove() after erase(), the exists() returns false. However, in both cases the file is not actually erased, and the chip eventually runs out of memory. I've put together a code that shows this issue. After running "eraseTest()" a number of timer (in my case with 8Mb chip - 11 tries) it's no longer able to create a new file, not until you run full chip erase.
Board: Teensy 3.6
Audio adapter with Winbond 25Q64FVSIG soldered onto the Audio board.
Arduino IDE 1.8.13
Teensyduino version 1.53
Windows 10
It seems that a friend of mine reproduced it with Teensy 4.0 and a breakout with SPI flash.
Here's the code that reproduces the problem:
Code:
#include <SPI.h>
#include <SerialFlash.h>
#define FLASH_CHIP_SELECT 6
// The file where data is recorded
SerialFlashFile file0;
SerialFlashFile file1;
SerialFlashFile file2;
//define file size
float filesize = 65536 * 10;
void setup() {
//uncomment these if using Teensy audio shield
SPI.setSCK(14); // Audio shield has SCK on pin 14
SPI.setMOSI(7); // Audio shield has MOSI on pin 7
Serial.begin(115200);
// Start SerialFlash
if (!SerialFlash.begin(FLASH_CHIP_SELECT)) {
while (1) {
Serial.println ("Cannot access SPI Flash chip");
delay (1000);
}
}
Serial.println("READY TO GO");
}
void eraseTest() {
const char *filename = "test.csv";
byte buffer[512];
static int n = 0;
for (int i = 0; i < 512; i++) {
buffer[i] = i % 10 + n;
}
Serial.print("Creating file...");
Serial.println(filename);
if (!SerialFlash.exists(filename)) {
SerialFlash.createErasable(filename, filesize);
}
else Serial.println(" file already exists");
file0 = SerialFlash.open(filename);
if (file0) {
file0.write(buffer, 512);
}
else {
Serial.println("unable to create file");
return;
}
file0.close();
delay(10);
Serial.println("Read test:");
byte buf[256];
file1 = SerialFlash.open(filename);
file1.read(buf,256);
for (int i = 42; i < 58; i++) {
Serial.print(buf[i]); Serial.print(",");
}
Serial.println();
delay(10);
Serial.println("Erasing file...");
unsigned long t = millis();
file2 = SerialFlash.open(filename);
file2.erase();
Serial.print("done in ");
Serial.print(millis()-t);
Serial.println(" ms");
delay(10);
Serial.print("Checking if file exists:");
Serial.println(SerialFlash.exists(filename));
Serial.println("removing with remove() ");
SerialFlash.remove(filename);
Serial.print("Checking if file exists again:");
Serial.println(SerialFlash.exists(filename));
Serial.print("counter:"); Serial.println(n++);
}
void loop() {
eraseTest();
delay(1000);
}
Could anybody try running this? Any help would be much appreciated.