Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

CardBusyTest.ino 2.1KB

5 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "SdFat.h"
  2. #ifdef __AVR__
  3. const uint32_t FILE_SIZE_MiB = 10UL;
  4. #else // __AVR__
  5. const uint32_t FILE_SIZE_MiB = 100UL;
  6. #endif
  7. bool waitBusy = true;
  8. #define SD_CONFIG SdSpiConfig(SS, DEDICATED_SPI)
  9. // Config for Teensy 3.5/3.6 buit-in SD.
  10. //#define SD_CONFIG SdSpiConfig(SDCARD_SS_PIN, DEDICATED_SPI)
  11. //#define SD_CONFIG SdioConfig(FIFO_SDIO)
  12. //------------------------------------------------------------------------------
  13. const uint64_t FILE_SIZE = (uint64_t)FILE_SIZE_MiB << 20;
  14. SdExFat sd;
  15. ExFile file;
  16. uint8_t buf[512];
  17. #define error(s) sd.errorHalt(&Serial, F(s))
  18. //------------------------------------------------------------------------------
  19. void setup() {
  20. Serial.begin(9600);
  21. // Wait for USB Serial
  22. while (!Serial) {
  23. SysCall::yield();
  24. }
  25. delay(1000);
  26. Serial.println(F("Type any character to start\n"));
  27. while (!Serial.available()) {
  28. SysCall::yield();
  29. }
  30. // Initialize the SD card.
  31. if (!sd.begin(SD_CONFIG)) {
  32. sd.initErrorHalt();
  33. }
  34. if (!file.open("SdBusyTest.bin", O_RDWR | O_CREAT |O_TRUNC)) {
  35. error("file open failed");
  36. }
  37. if (!file.preAllocate(FILE_SIZE)) {
  38. error("preallocate failed");
  39. }
  40. Serial.print(F("Starting write of "));
  41. Serial.print(FILE_SIZE_MiB);
  42. Serial.println(F(" MiB."));
  43. uint32_t maxMicros = 0;
  44. uint32_t minMicros = 99999999;
  45. uint32_t ms = millis();
  46. // Write a dummy sector to start a multi-sector write.
  47. if(file.write(buf, sizeof(buf)) != sizeof(buf)) {
  48. error("write failed for first sector");
  49. }
  50. while (file.position() < FILE_SIZE) {
  51. if (waitBusy) {
  52. while (sd.card()->isBusy()) {}
  53. }
  54. uint32_t m = micros();
  55. if (file.write(buf, sizeof(buf)) != sizeof(buf)) {
  56. error("write failed");
  57. }
  58. m = micros() - m;
  59. if (m < minMicros) {
  60. minMicros = m;
  61. }
  62. if (m > maxMicros) {
  63. maxMicros = m;
  64. }
  65. }
  66. ms = millis() - ms;
  67. Serial.print(F("minMicros: "));
  68. Serial.println(minMicros);
  69. Serial.print(F("maxMicros: "));
  70. Serial.println(maxMicros);
  71. Serial.print(1e-3*ms);
  72. Serial.println(F(" Seconds"));
  73. Serial.print(1.0*FILE_SIZE/ms);
  74. Serial.println(F(" KB/sec"));
  75. }
  76. void loop() {}