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.

75 líneas
1.9KB

  1. // This stress test will create and write files until the SD is full.
  2. #include <SdFat.h>
  3. // SD chip select pin.
  4. const uint8_t SD_CS_PIN = SS;
  5. // Set write buffer size.
  6. #ifdef __arm__
  7. #ifndef CORE_TEENSY
  8. // Due
  9. const size_t BUF_SIZE = 32768;
  10. #else // CORE_TEENSY
  11. // Teensy 3.0
  12. const size_t BUF_SIZE = 8192;
  13. #endif // CORE_TEENSY
  14. #elif defined(RAMEND) && RAMEND > 5000
  15. // AVR with more than 4 KB RAM
  16. const size_t BUF_SIZE = 4096;
  17. #else // __arm__
  18. // other
  19. const size_t BUF_SIZE = 512;
  20. #endif // __arm__
  21. const size_t FILE_SIZE_KB = 10240;
  22. const uint16_t BUFS_PER_FILE = (1024L*FILE_SIZE_KB/BUF_SIZE);
  23. SdFat sd;
  24. SdFile file;
  25. uint8_t buf[BUF_SIZE];
  26. char name[13];
  27. //------------------------------------------------------------------------------
  28. void setup() {
  29. Serial.begin(9600);
  30. Serial.print("BUF_SIZE ");
  31. Serial.println(BUF_SIZE);
  32. Serial.println("Type any character to start");
  33. while (Serial.read() < 0) {}
  34. if (!sd.begin(SD_CS_PIN))sd.errorHalt("sd.begin");
  35. // Fill buf with known value.
  36. for (size_t i = 0; i < BUF_SIZE; i++) buf[i] = i;
  37. // Wait to begin.
  38. do {delay(10);} while (Serial.read() >= 0);
  39. Serial.println("Type any character to stop after next file");
  40. }
  41. //------------------------------------------------------------------------------
  42. void loop() {
  43. // Free KB on SD.
  44. uint32_t freeKB = sd.vol()->freeClusterCount()*sd.vol()->blocksPerCluster()/2;
  45. Serial.print("Free KB: ");
  46. Serial.println(freeKB);
  47. if (freeKB < 2*FILE_SIZE_KB) {
  48. Serial.println(" Done!");
  49. while(1);
  50. }
  51. sprintf(name, "%lu.DAT", freeKB);
  52. if (!file.open(name, O_WRITE | O_CREAT | O_TRUNC)) {
  53. sd.errorHalt("Open error!");
  54. }
  55. for (uint16_t i = 0; i < BUFS_PER_FILE; i++) {
  56. if (file.write(buf, BUF_SIZE) != BUF_SIZE) {
  57. sd.errorHalt("Write error!");
  58. }
  59. }
  60. file.close();
  61. if (Serial.available()) {
  62. Serial.println("Stopped!");
  63. while(1);
  64. }
  65. }