SD Card default / high speed
Posted: Thu Nov 30, 2017 1:56 pm
Hi,
I am currently using the SD card interface on the ESP-WROOM-32 and the read/write speeds are not as expected. I am using a SanDisk 16GB HC Class 2, SanDisk Ultra 32GB HC I Class 10 and a Lexar 1000x HCII Class 10 U3.
At first I was surprised to see that is was using the default speed and not the high speed interface (sdmmc_card_print_info()). Digging in the code I found that max_freq_khz in SDMMC_HOST_DEFAULT() macro was set to use SDMMC_FREQ_DEFAULT and not SDMMC_FREQ_HIGHSPEED. In sdmmc_card_init() a test is done to check if config->max_freq_khz is >= SDMMC_FREQ_HIGHSPEED before sdmmc_enable_hs_mode() is called to test the SD card.
I changed max_freq_khz in SDMMC_HOST_DEFAULT() to SDMMC_FREQ_HIGHSPEED and the SD cards now report that they support high speed mode.
Unfortunately there was not a massive transfer improvement as expected.
Test done transferring 8MB in 2848 byte blocks:
SanDisk 16GB HC C2: 638kB/s to 754kB/s on first block and then 692kB/s, 638kB/s and then subsequent blocks are only 202kB/s.
SanDisk Ultra 32GB HC I C10: 638kB/s to 692kB/s.
Lexar 1000x HCII Class 10 U3: 1384kB/s to 1660kB/s.
1. Can anybody explain why there was not a massive speed improvement using the high speed clock?
2. Why does the transfer on the 16GB card get slower and slower and drop to 202kB/s?
Pseudo code sample:
if (sd_card_init() == ESP_OK)
{
TickType_t startTick;
TickType_t endTick;
pfile = fopen(fname, "rb");
dataRead = 0;
for(int i=0; i<10; i++)
startTick = xTaskGetTickCount();
for(int i=0; i<2916; i++)
dataRead += fread(ucpData, sizeof(uint8_t), 2848, pfile);
endTick = xTaskGetTickCount();
ESP_LOGW(TAG, "Bytes per sec %dkB/s", dataRead / ((endTick - startTick) / 1000) / 1000);
}
fclose(pfile);
}
Regards,
Charles
I am currently using the SD card interface on the ESP-WROOM-32 and the read/write speeds are not as expected. I am using a SanDisk 16GB HC Class 2, SanDisk Ultra 32GB HC I Class 10 and a Lexar 1000x HCII Class 10 U3.
At first I was surprised to see that is was using the default speed and not the high speed interface (sdmmc_card_print_info()). Digging in the code I found that max_freq_khz in SDMMC_HOST_DEFAULT() macro was set to use SDMMC_FREQ_DEFAULT and not SDMMC_FREQ_HIGHSPEED. In sdmmc_card_init() a test is done to check if config->max_freq_khz is >= SDMMC_FREQ_HIGHSPEED before sdmmc_enable_hs_mode() is called to test the SD card.
I changed max_freq_khz in SDMMC_HOST_DEFAULT() to SDMMC_FREQ_HIGHSPEED and the SD cards now report that they support high speed mode.
Unfortunately there was not a massive transfer improvement as expected.
Test done transferring 8MB in 2848 byte blocks:
SanDisk 16GB HC C2: 638kB/s to 754kB/s on first block and then 692kB/s, 638kB/s and then subsequent blocks are only 202kB/s.
SanDisk Ultra 32GB HC I C10: 638kB/s to 692kB/s.
Lexar 1000x HCII Class 10 U3: 1384kB/s to 1660kB/s.
1. Can anybody explain why there was not a massive speed improvement using the high speed clock?
2. Why does the transfer on the 16GB card get slower and slower and drop to 202kB/s?
Pseudo code sample:
if (sd_card_init() == ESP_OK)
{
TickType_t startTick;
TickType_t endTick;
pfile = fopen(fname, "rb");
dataRead = 0;
for(int i=0; i<10; i++)
startTick = xTaskGetTickCount();
for(int i=0; i<2916; i++)
dataRead += fread(ucpData, sizeof(uint8_t), 2848, pfile);
endTick = xTaskGetTickCount();
ESP_LOGW(TAG, "Bytes per sec %dkB/s", dataRead / ((endTick - startTick) / 1000) / 1000);
}
fclose(pfile);
}
Regards,
Charles