Skip to content

Commit bca5f68

Browse files
committed
Allow setting DDR, and only enable UHS for higher frequencies
1 parent b333d4c commit bca5f68

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

libraries/SD_MMC/examples/SDMMC_Test/SDMMC_Test.ino

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,25 @@ void testFileIO(fs::FS &fs, const char *path) {
211211
file.close();
212212
}
213213

214+
void testRawIO(uint32_t sectors, uint8_t sequential) {
215+
uint32_t readSect = 0;
216+
uint32_t startTime = millis();
217+
uint8_t* buf = (uint8_t*)heap_caps_malloc(SD_MMC.sectorSize(), MALLOC_CAP_DMA);
218+
for (uint32_t x=0; x<sectors; x++) {
219+
if (! SD_MMC.readRAW(buf, readSect)) {
220+
log_e("Unable to read sector %lu\n", readSect);
221+
free(buf);
222+
return;
223+
}
224+
readSect = sequential ? readSect + 1 : random(SD_MMC.numSectors()-1);
225+
}
226+
uint32_t passed = millis() - startTime;
227+
uint32_t rate = sectors * SD_MMC.sectorSize() / passed;
228+
Serial.printf("%lu %s sectors read in %lu msec (%luKB/s)\n",
229+
sectors, sequential ? "sequential" : "random", passed, rate);
230+
free(buf);
231+
}
232+
214233
void setup() {
215234
Serial.begin(115200);
216235
/*
@@ -262,6 +281,7 @@ void setup() {
262281
renameFile(SD_MMC, "/hello.txt", "/foo.txt");
263282
readFile(SD_MMC, "/foo.txt");
264283
testFileIO(SD_MMC, "/test.txt");
284+
testRawIO(2000, 1);
265285
Serial.printf("Total space: %lluMB\n", SD_MMC.totalBytes() / (1024 * 1024));
266286
Serial.printf("Used space: %lluMB\n", SD_MMC.usedBytes() / (1024 * 1024));
267287
}

libraries/SD_MMC/src/SD_MMC.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,8 +247,13 @@ bool SDMMCFS::begin(const char *mountpoint, bool mode1bit, bool format_if_mount_
247247
.flags = 0,
248248
};
249249
#ifdef SOC_SDMMC_UHS_I_SUPPORTED
250-
host.flags &= ~SDMMC_HOST_FLAG_DDR;
250+
if (sdmmc_frequency == SDMMC_FREQ_DDR50) {
251+
host.flags |= SDMMC_HOST_FLAG_DDR;
251252
slot_config.flags = SDMMC_SLOT_FLAG_UHS1;
253+
}
254+
if (sdmmc_frequency == SDMMC_FREQ_SDR50) {
255+
slot_config.flags = SDMMC_SLOT_FLAG_UHS1;
256+
}
252257
#endif
253258
#else
254259
host.slot = SDMMC_HOST_SLOT_1;

0 commit comments

Comments
 (0)