SD card write speed
Posted: Tue Feb 15, 2022 3:30 pm
Hello,
I just benchmarked the write speed to an SD card and found out that it caps at about 400kB/s.
I was surprised of such a low speed and read posts where users claim writing speeds of more than 1MB/s (up to 9MB/s)
while others have speeds comparable to mine but could not figure out the difference in their configurations.
I tried to change parameters and models of SD card but cannot improve.
I think I'm missing something pretty evident. Any hint or solution would be appreciated.
Here a short code replicating what I'm doing (ESP-IDF release/v4.1 and ES-ADF v2.3, cannot change versions for the moment)
in a board alike the LyraT 4.3.
Thanks in advance for any help.
I just benchmarked the write speed to an SD card and found out that it caps at about 400kB/s.
I was surprised of such a low speed and read posts where users claim writing speeds of more than 1MB/s (up to 9MB/s)
while others have speeds comparable to mine but could not figure out the difference in their configurations.
I tried to change parameters and models of SD card but cannot improve.
I think I'm missing something pretty evident. Any hint or solution would be appreciated.
Here a short code replicating what I'm doing (ESP-IDF release/v4.1 and ES-ADF v2.3, cannot change versions for the moment)
in a board alike the LyraT 4.3.
Thanks in advance for any help.
Code: Select all
//Code tested in ESP-IDF release v4.1 with ESP-ADF v2.3
#define BASESTR1000 "..." //a 1000 characters string
esp_periph_config_t periph_cfg = DEFAULT_ESP_PERIPH_SET_CONFIG();
esp_periph_set_handle_t set = esp_periph_set_init(&periph_cfg);
periph_sdcard_cfg_t sdcard_cfg = {
.root = "/sdcard",
.card_detect_pin = get_sdcard_intr_gpio(),
.mode = SD_MODE_4_LINE,
};
esp_periph_handle_t sdcard_handle = periph_sdcard_init(&sdcard_cfg);
//In ESP-ADF components/esp_pheripherals/lib/sdcard/sdcard: host.max_freq_khz = SDMMC_FREQ_HIGHSPEED; => 40MHz
esp_err_t ret = esp_periph_start(set, sdcard_handle);
while(!periph_sdcard_is_mounted(sdcard_handle)){vTaskDelay(500 / portTICK_PERIOD_MS);}
FILE * test = fopen("/sdcard/test", "w");
TickType_t startTick = xTaskGetTickCount();
for(int i=0; i<1000; i++){fwrite((const void *)BASESTR1000, strlen(BASESTR1000), 1, test);}
TickType_t endTick = xTaskGetTickCount();
fclose(test);
ESP_LOGI(TAG, "Benchmark writing 1MB in %d milliseconds (%.2fMB/s)", endTick-startTick, 1000./(endTick-startTick));
/////////OUTPUT: Benchmark writing 1MB in 2156 milliseconds (0.46MB/s)
/////////From the logs in verbose mode, the SD card is mounted in 4-lines at 40MHz clock