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.

82 rindas
2.3KB

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