Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

EraseEverything.ino 2.0KB

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