Skip to content

Commit a345eeb

Browse files
committed
test sd speed
1 parent 63ee3f1 commit a345eeb

File tree

12 files changed

+454
-93
lines changed

12 files changed

+454
-93
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#include "SPI.h"
2+
#include "SD.h"
3+
#include "SD_MMC.h"
4+
5+
#define PIN_AUDIO_KIT_SD_CARD_CS 13
6+
#define PIN_AUDIO_KIT_SD_CARD_MISO 2
7+
#define PIN_AUDIO_KIT_SD_CARD_MOSI 15
8+
#define PIN_AUDIO_KIT_SD_CARD_CLK 14
9+
10+
uint8_t data[1024 * 100];
11+
int len[] = { 1, 5, 10, 25, 100, 256, 512, 1024, 1024 * 10, 1024 * 100 };
12+
size_t totalSize = 1024 * 1024 * 1;
13+
const char* test_file = "/test.txt";
14+
15+
void testWrite(Stream& file, int writeSize, int totalSize) {
16+
memset(data, 0, sizeof(data));
17+
int32_t start = millis();
18+
while (totalSize > 0) {
19+
int written = file.write(data, min(writeSize, totalSize));
20+
//Serial.println(written);
21+
//assert(written > 0);
22+
totalSize -= written;
23+
}
24+
}
25+
26+
void testRead(Stream& file, int readSize, int totalSize) {
27+
memset(data, 0, sizeof(data));
28+
while (totalSize > 0) {
29+
int read = file.readBytes(data, min(readSize, totalSize));
30+
//assert(read>0);
31+
totalSize -= read;
32+
}
33+
}
34+
35+
void logTime(uint32_t start, int i, const char* name, const char* op) {
36+
int32_t time = millis() - start;
37+
float thru = (float)totalSize / (float)time / 1000.0;
38+
Serial.printf("%s, %s, %d, %d, %f\n", op, name, i, time, thru);
39+
}
40+
41+
template<typename SD, typename Open>
42+
void testFS(const char* name, SD& sd, Open write, Open read) {
43+
44+
for (int i : len) {
45+
int32_t start = millis();
46+
auto file = sd.open(test_file, write);
47+
file.seek(0);
48+
assert(file);
49+
testWrite(file, i, totalSize);
50+
file.close();
51+
logTime(start, i, name, "Write");
52+
}
53+
for (int i : len) {
54+
int32_t start = millis();
55+
auto file = sd.open(test_file, read);
56+
assert(file);
57+
testRead(file, i, totalSize);
58+
file.close();
59+
logTime(start, i, name, "Read");
60+
}
61+
sd.end();
62+
}
63+
64+
65+
void setup() {
66+
67+
Serial.begin(115200);
68+
69+
while (!SD_MMC.begin()) {
70+
Serial.println("SDMMC error");
71+
delay(1000);
72+
}
73+
testFS<fs::SDMMCFS, const char*>("SD_MMC", SD_MMC, FILE_WRITE, FILE_READ);
74+
75+
// SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
76+
// while (!SD.begin(PIN_AUDIO_KIT_SD_CARD_CS)) {
77+
// Serial.println("SD error");
78+
// delay(1000);
79+
// }
80+
// testFS<fs::SDFS, const char*>("SD", SD, FILE_WRITE, FILE_READ);
81+
}
82+
83+
void loop() {}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
Write, SD, 1, 12813, 0.081837
2+
Write, SD, 5, 4578, 0.229047
3+
Write, SD, 10, 3550, 0.295374
4+
Write, SD, 25, 2927, 0.358243
5+
Write, SD, 100, 2623, 0.399762
6+
Write, SD, 256, 2607, 0.402216
7+
Write, SD, 512, 2571, 0.407848
8+
Write, SD, 1024, 2601, 0.403143
9+
Write, SD, 10240, 2531, 0.414293
10+
Write, SD, 102400, 2451, 0.427816
11+
Read, SD, 1, 13009, 0.080604
12+
Read, SD, 5, 4538, 0.231066
13+
Read, SD, 10, 3478, 0.301488
14+
Read, SD, 25, 2845, 0.368568
15+
Read, SD, 100, 2527, 0.414949
16+
Read, SD, 256, 2463, 0.425731
17+
Read, SD, 512, 2443, 0.429217
18+
Read, SD, 1024, 2432, 0.431158
19+
Read, SD, 10240, 2423, 0.432759
20+
Read, SD, 102400, 2421, 0.433117
21+
Write, SD_MMC, 1, 10605, 0.098876
22+
Write, SD_MMC, 5, 2384, 0.439839
23+
Write, SD_MMC, 10, 1313, 0.798611
24+
Write, SD_MMC, 25, 728, 1.440352
25+
Write, SD_MMC, 100, 391, 2.681780
26+
Write, SD_MMC, 256, 351, 2.987396
27+
Write, SD_MMC, 512, 313, 3.350083
28+
Write, SD_MMC, 1024, 315, 3.328813
29+
Write, SD_MMC, 10240, 215, 4.877098
30+
Write, SD_MMC, 102400, 109, 9.619963
31+
Read, SD_MMC, 1, 10703, 0.097970
32+
Read, SD_MMC, 5, 2230, 0.470213
33+
Read, SD_MMC, 10, 1171, 0.895453
34+
Read, SD_MMC, 25, 537, 1.952656
35+
Read, SD_MMC, 100, 219, 4.788018
36+
Read, SD_MMC, 256, 155, 6.765007
37+
Read, SD_MMC, 512, 135, 7.767230
38+
Read, SD_MMC, 1024, 124, 8.456258
39+
Read, SD_MMC, 10240, 115, 9.118052
40+
Read, SD_MMC, 102400, 115, 9.118052
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
#include "SPI.h"
2+
#include "SdFat.h"
3+
4+
#define PIN_AUDIO_KIT_SD_CARD_CS 13
5+
#define PIN_AUDIO_KIT_SD_CARD_MISO 2
6+
#define PIN_AUDIO_KIT_SD_CARD_MOSI 15
7+
#define PIN_AUDIO_KIT_SD_CARD_CLK 14
8+
#define SPI_CLOCK SD_SCK_MHZ(10)
9+
10+
uint8_t* data = nullptr;
11+
int len[] = { 1, 5, 10, 25, 100, 256, 512, 1024, 1024 * 10, 1024 * 100 };
12+
size_t totalSize = 1024 * 1024 * 1;
13+
const char* test_file = "/test.txt";
14+
15+
void testWrite(Stream& file, int writeSize, int totalSize) {
16+
memset(data, 0xff, sizeof(data));
17+
int32_t start = millis();
18+
while (totalSize > 0) {
19+
int written = file.write(data, min(writeSize, totalSize));
20+
//Serial.println(written);
21+
//assert(written > 0);
22+
totalSize -= written;
23+
}
24+
}
25+
26+
void testRead(Stream& file, int readSize, int totalSize) {
27+
memset(data, 0, sizeof(data));
28+
while (totalSize > 0) {
29+
int read = file.readBytes(data, min(readSize, totalSize));
30+
//assert(read>0);
31+
totalSize -= read;
32+
}
33+
}
34+
35+
void logTime(uint32_t start, int i, const char* name, const char* op) {
36+
int32_t time = millis() - start;
37+
float thru = (float)totalSize / (float)time / 1000.0;
38+
Serial.printf("%s, %s, %d, %d, %f\n", op, name, i, time, thru);
39+
}
40+
41+
42+
template<typename SD, typename Open>
43+
void testFS(const char* name, SD& sd, Open write, Open read) {
44+
SdSpiConfig cfg(PIN_AUDIO_KIT_SD_CARD_CS, DEDICATED_SPI, SPI_CLOCK, &SPI);
45+
while (!sd.begin(PIN_AUDIO_KIT_SD_CARD_CS, SPI, SPI_CLOCK)) {
46+
Serial.print(name);
47+
Serial.println(" error");
48+
delay(1000);
49+
}
50+
51+
for (int i : len) {
52+
int32_t start = millis();
53+
auto file = sd.open(test_file, write);
54+
assert(file);
55+
file.seek(0);
56+
testWrite(file, len[i], totalSize);
57+
file.close();
58+
logTime(start, i, name, "Write");
59+
}
60+
for (int i : len) {
61+
int32_t start = millis();
62+
auto file = sd.open(test_file, read);
63+
assert(file);
64+
testRead(file, len[i], totalSize);
65+
file.close();
66+
logTime(start, i, name, "Read");
67+
}
68+
sd.end();
69+
}
70+
71+
void setup() {
72+
Serial.begin(115200);
73+
// allocate read/write buffer
74+
data = new uint8_t[1024 * 100];
75+
assert(data != nullptr);
76+
77+
// setup SPI pins
78+
SPI.begin(PIN_AUDIO_KIT_SD_CARD_CLK, PIN_AUDIO_KIT_SD_CARD_MISO, PIN_AUDIO_KIT_SD_CARD_MOSI, PIN_AUDIO_KIT_SD_CARD_CS);
79+
delay(1000);
80+
81+
// test SD
82+
SdFat sdfat;
83+
testFS<SdFat, int>("SDFAT", sdfat, FILE_WRITE, FILE_READ);
84+
}
85+
86+
void loop() {}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
There seems to be a bug in the library, since this is dumping!
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#define AUDIOBOARD_SD
2+
#include "AudioTools.h"
3+
#include "AudioTools/Disk/VFS_SDSPI.h"
4+
#include "AudioTools/Disk/VFS_SDMMC.h"
5+
#include "AudioTools/Disk/VFSFile.h"
6+
7+
#define PIN_AUDIO_KIT_SD_CARD_CS 13
8+
#define PIN_AUDIO_KIT_SD_CARD_MISO 2
9+
#define PIN_AUDIO_KIT_SD_CARD_MOSI 15
10+
#define PIN_AUDIO_KIT_SD_CARD_CLK 14
11+
12+
const size_t max_len = 1024 * 100;
13+
uint8_t *data = nullptr;
14+
int len[] = { 1, 5, 10, 25, 100, 256, 512, 1024, 1024 * 10, 1024 * 100 };
15+
size_t totalSize = 1024 * 1024 * 1;
16+
const char* test_file = "/test.txt";
17+
18+
void testWrite(Stream& file, int writeSize, int totalSize) {
19+
memset(data, 0, max_len);
20+
int32_t start = millis();
21+
while (totalSize > 0) {
22+
int written = file.write(data, min(writeSize, totalSize));
23+
//Serial.println(written);
24+
//assert(written > 0);
25+
totalSize -= written;
26+
}
27+
}
28+
29+
void testRead(Stream& file, int readSize, int totalSize) {
30+
memset(data, 0, max_len);
31+
while (totalSize > 0) {
32+
int read = file.readBytes(data, min(readSize, totalSize));
33+
//assert(read>0);
34+
totalSize -= read;
35+
}
36+
}
37+
38+
void logTime(uint32_t start, int i, const char* name, const char* op) {
39+
int32_t time = millis() - start;
40+
float thru = (float)totalSize / (float)time / 1000.0;
41+
Serial.printf("%s, %s, %d, %d, %f\n", op, name, i, time, thru);
42+
}
43+
44+
template<typename SD, typename Open>
45+
void testFS(const char* name, SD& sd, Open write, Open read) {
46+
while (!sd.begin()) {
47+
Serial.print(name);
48+
Serial.println(" error");
49+
delay(1000);
50+
}
51+
52+
for (int i : len) {
53+
int32_t start = millis();
54+
auto file = sd.open(test_file, write);
55+
file.seek(0);
56+
assert(file);
57+
testWrite(file, i, totalSize);
58+
file.close();
59+
logTime(start, i, name, "Write");
60+
}
61+
for (int i : len) {
62+
int32_t start = millis();
63+
auto file = sd.open(test_file, read);
64+
assert(file);
65+
testRead(file, i, totalSize);
66+
file.close();
67+
logTime(start, i, name, "Read");
68+
}
69+
sd.end();
70+
}
71+
72+
void setup() {
73+
Serial.begin(115200);
74+
75+
VFS_SDSPI sd;
76+
VFS_SDMMC sdmmc;
77+
78+
data = new uint8_t[max_len];
79+
assert(data!=nullptr);
80+
81+
// testFS<VFS_SDSPI, FileMode>("VFS_SDSPI", sd, VFS_FILE_WRITE, VFS_FILE_READ);
82+
testFS<VFS_SDMMC, FileMode>("VFS_SDMMC", sdmmc, VFS_FILE_WRITE, VFS_FILE_READ);
83+
}
84+
85+
void loop() {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
Write, VFS_SDSPI, 512, 2869, 0.365485
2+
Write, VFS_SDSPI, 1024, 2881, 0.363963
3+
Write, VFS_SDSPI, 10240, 2882, 0.363836
4+
Write, VFS_SDSPI, 102400, 2869, 0.365485
5+
Read, VFS_SDSPI, 1, 2481, 0.422642
6+
Read, VFS_SDSPI, 5, 1501, 0.698585
7+
Read, VFS_SDSPI, 10, 1378, 0.760940
8+
Read, VFS_SDSPI, 25, 1303, 0.804740
9+
Read, VFS_SDSPI, 100, 1267, 0.827605
10+
Read, VFS_SDSPI, 256, 1143, 0.917389
11+
Read, VFS_SDSPI, 512, 1109, 0.945515
12+
Read, VFS_SDSPI, 1024, 928, 1.129931
13+
Read, VFS_SDSPI, 10240, 651, 1.610716
14+
Read, VFS_SDSPI, 102400, 625, 1.677722
15+
Write, VFS_SDMMC, 5, 2366, 0.443185
16+
Write, VFS_SDMMC, 10, 2346, 0.446963
17+
Write, VFS_SDMMC, 25, 2346, 0.446963
18+
Write, VFS_SDMMC, 100, 2332, 0.449647
19+
Write, VFS_SDMMC, 256, 2337, 0.448685
20+
Write, VFS_SDMMC, 512, 2324, 0.451194
21+
Write, VFS_SDMMC, 1024, 2384, 0.439839
22+
Write, VFS_SDMMC, 10240, 2337, 0.448685
23+
Write, VFS_SDMMC, 102400, 2341, 0.447918
24+
Read, VFS_SDMMC, 1, 1809, 0.579644
25+
Read, VFS_SDMMC, 5, 828, 1.266396
26+
Read, VFS_SDMMC, 10, 705, 1.487342
27+
Read, VFS_SDMMC, 25, 631, 1.661769
28+
Read, VFS_SDMMC, 100, 594, 1.765279
29+
Read, VFS_SDMMC, 256, 509, 2.060071
30+
Read, VFS_SDMMC, 512, 467, 2.245345
31+
Read, VFS_SDMMC, 1024, 277, 3.785473
32+
Read, VFS_SDMMC, 10240, 88, 11.915637
33+
Read, VFS_SDMMC, 102400, 70, 14.979657

0 commit comments

Comments
 (0)