您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

70 行
1.9KB

  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. // wait up to 10 seconds for Arduino Serial Monitor
  10. unsigned long startMillis = millis();
  11. while (!Serial && (millis() - startMillis < 10000)) ;
  12. delay(100);
  13. SerialFlash.begin();
  14. unsigned char id[3];
  15. SerialFlash.readID(id);
  16. unsigned long size = SerialFlash.capacity(id);
  17. if (size > 0) {
  18. Serial.print("Flash Memory has ");
  19. Serial.print(size);
  20. Serial.println(" bytes.");
  21. Serial.println("Erasing ALL Flash Memory:");
  22. // Estimate the (lengthy) wait time.
  23. Serial.print(" estimated wait: ");
  24. int seconds = (float)size / eraseBytesPerSecond(id) + 0.5;
  25. Serial.print(seconds);
  26. Serial.println(" seconds.");
  27. Serial.println(" Yes, full chip erase is SLOW!");
  28. SerialFlash.eraseAll();
  29. unsigned long dotMillis = millis();
  30. unsigned char dotcount = 0;
  31. while (SerialFlash.ready() == false) {
  32. if (millis() - dotMillis > 1000) {
  33. dotMillis = dotMillis + 1000;
  34. Serial.print(".");
  35. dotcount = dotcount + 1;
  36. if (dotcount >= 60) {
  37. Serial.println();
  38. dotcount = 0;
  39. }
  40. }
  41. }
  42. if (dotcount > 0) Serial.println();
  43. Serial.println("Erase completed");
  44. unsigned long elapsed = millis() - startMillis;
  45. Serial.print(" actual wait: ");
  46. Serial.print(elapsed / 1000ul);
  47. Serial.println(" seconds.");
  48. }
  49. }
  50. float eraseBytesPerSecond(const unsigned char *id) {
  51. if (id[0] == 0x20) return 152000.0; // Micron
  52. if (id[0] == 0x01) return 500000.0; // Spansion
  53. if (id[0] == 0xEF) return 419430.0; // Winbond
  54. if (id[0] == 0xC2) return 279620.0; // Macronix
  55. return 320000.0; // guess?
  56. }
  57. void loop() {
  58. }