Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

EraseEverything.ino 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #include <SerialFlash.h>
  2. #include <SPI.h>
  3. const int FlashChipSelect = 6; // digital pin for flash chip CS pin
  4. //const int FlashChipSelect = 21; // Arduino 101 built-in SPI Flash
  5. SerialFlashFile file;
  6. const unsigned long testIncrement = 4096;
  7. void setup() {
  8. //uncomment these if using Teensy audio shield
  9. //SPI.setSCK(14); // Audio shield has SCK on pin 14
  10. //SPI.setMOSI(7); // Audio shield has MOSI on pin 7
  11. //uncomment these if you have other SPI chips connected
  12. //to keep them disabled while using only SerialFlash
  13. //pinMode(4, INPUT_PULLUP);
  14. //pinMode(10, INPUT_PULLUP);
  15. Serial.begin(9600);
  16. // wait up to 10 seconds for Arduino Serial Monitor
  17. unsigned long startMillis = millis();
  18. while (!Serial && (millis() - startMillis < 10000)) ;
  19. delay(100);
  20. SerialFlash.begin(FlashChipSelect);
  21. unsigned char id[5];
  22. SerialFlash.readID(id);
  23. unsigned long size = SerialFlash.capacity(id);
  24. if (size > 0) {
  25. Serial.print("Flash Memory has ");
  26. Serial.print(size);
  27. Serial.println(" bytes.");
  28. Serial.println("Erasing ALL Flash Memory:");
  29. // Estimate the (lengthy) wait time.
  30. Serial.print(" estimated wait: ");
  31. int seconds = (float)size / eraseBytesPerSecond(id) + 0.5;
  32. Serial.print(seconds);
  33. Serial.println(" seconds.");
  34. Serial.println(" Yes, full chip erase is SLOW!");
  35. SerialFlash.eraseAll();
  36. unsigned long dotMillis = millis();
  37. unsigned char dotcount = 0;
  38. while (SerialFlash.ready() == false) {
  39. if (millis() - dotMillis > 1000) {
  40. dotMillis = dotMillis + 1000;
  41. Serial.print(".");
  42. dotcount = dotcount + 1;
  43. if (dotcount >= 60) {
  44. Serial.println();
  45. dotcount = 0;
  46. }
  47. }
  48. }
  49. if (dotcount > 0) Serial.println();
  50. Serial.println("Erase completed");
  51. unsigned long elapsed = millis() - startMillis;
  52. Serial.print(" actual wait: ");
  53. Serial.print(elapsed / 1000ul);
  54. Serial.println(" seconds.");
  55. }
  56. }
  57. float eraseBytesPerSecond(const unsigned char *id) {
  58. if (id[0] == 0x20) return 152000.0; // Micron
  59. if (id[0] == 0x01) return 500000.0; // Spansion
  60. if (id[0] == 0xEF) return 419430.0; // Winbond
  61. if (id[0] == 0xC2) return 279620.0; // Macronix
  62. return 320000.0; // guess?
  63. }
  64. void loop() {
  65. }