|
- #include <SerialFlash.h>
- #include <SPI.h>
-
- const int FlashChipSelect = 6;
-
-
- SerialFlashFile file;
-
- const unsigned long testIncrement = 4096;
-
- void setup() {
-
-
-
-
-
-
-
-
-
- Serial.begin(9600);
-
-
- unsigned long startMillis = millis();
- while (!Serial && (millis() - startMillis < 10000)) ;
- delay(100);
-
- SerialFlash.begin(FlashChipSelect);
- unsigned char id[5];
- SerialFlash.readID(id);
- unsigned long size = SerialFlash.capacity(id);
-
- if (size > 0) {
- Serial.print("Flash Memory has ");
- Serial.print(size);
- Serial.println(" bytes.");
- Serial.println("Erasing ALL Flash Memory:");
-
- Serial.print(" estimated wait: ");
- int seconds = (float)size / eraseBytesPerSecond(id) + 0.5;
- Serial.print(seconds);
- Serial.println(" seconds.");
- Serial.println(" Yes, full chip erase is SLOW!");
- SerialFlash.eraseAll();
- unsigned long dotMillis = millis();
- unsigned char dotcount = 0;
- while (SerialFlash.ready() == false) {
- if (millis() - dotMillis > 1000) {
- dotMillis = dotMillis + 1000;
- Serial.print(".");
- dotcount = dotcount + 1;
- if (dotcount >= 60) {
- Serial.println();
- dotcount = 0;
- }
- }
- }
- if (dotcount > 0) Serial.println();
- Serial.println("Erase completed");
- unsigned long elapsed = millis() - startMillis;
- Serial.print(" actual wait: ");
- Serial.print(elapsed / 1000ul);
- Serial.println(" seconds.");
- }
- }
-
- float eraseBytesPerSecond(const unsigned char *id) {
- if (id[0] == 0x20) return 152000.0;
- if (id[0] == 0x01) return 500000.0;
- if (id[0] == 0xEF) return 419430.0;
- if (id[0] == 0xC2) return 279620.0;
- return 320000.0;
- }
-
-
- void loop() {
-
- }
|