No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

EraseEverything.ino 2.1KB

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