eMMC write speed test

JPMJPM
Posts: 25
Joined: Fri Oct 13, 2017 4:35 pm

eMMC write speed test

Postby JPMJPM » Sun May 11, 2025 10:27 am

HI,
I have tested the write speed of a SAMSUNG eMMC with two different sketchs. The writing speed of the second
sketch is much lower.

Sketch 1)
https://github.com/espressif/arduino-es ... C_Test.ino
with SD_MMC.setPins(3, 5, 1, 13, 7, 6);
with SD_MMC.begin("/sdcard", false, false, 20000, 5); // 4-bit line mode and CLK = 20 MHz
Write speed --> 1048576 bytes written for 285 ms

Sketch 2) The following sketch (4-bit line mode and CLK = 20 MHz)
Write speed --> 1048576 bytes written for 1170 ms

Can someone tell me what I did wrong in the second sketch ?.

Code: Select all

// Sketch 2

#include <string.h>
#include <sys/unistd.h>
#include <sys/stat.h>
#include "esp_vfs_fat.h"
#include "sdmmc_cmd.h"
#include "driver/sdmmc_host.h"
#include "FS.h"

#define MOUNT_POINT "/eMMC"

void setup(){
  Serial.begin(115200);
  Serial.printf("ESP-IDF version = %s\n", esp_get_idf_version());

  esp_vfs_fat_sdmmc_mount_config_t mount_config = {
    .format_if_mount_failed = true,
    .max_files = 5,
    .allocation_unit_size = 16 * 1024
  };
  sdmmc_card_t *card = NULL;
  const char mount_point[] = MOUNT_POINT;

  sdmmc_host_t host = SDMMC_HOST_DEFAULT();
  host.max_freq_khz = 20000;
  //host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
  //host.flags &= ~SDMMC_HOST_FLAG_DDR;

  sdmmc_slot_config_t slot_config = {
        .cd = SDMMC_SLOT_NO_CD,
        .wp = SDMMC_SLOT_NO_WP,
  };
  slot_config.width = 4;
  slot_config.clk = GPIO_NUM_3;
  slot_config.cmd = GPIO_NUM_5;
  slot_config.d0 = GPIO_NUM_1;
  slot_config.d1 = GPIO_NUM_13;
  slot_config.d2 = GPIO_NUM_7;
  slot_config.d3 = GPIO_NUM_6;
  esp_err_t ret = esp_vfs_fat_sdmmc_mount(mount_point, &host, &slot_config, &mount_config, &card);
  if (ret != ESP_OK) {
    Serial.println("Failed to mount filesystem.");
    return;
  }
  Serial.println("Filesystem mounted");

  ///////////////// eMMC write speed test
  int i;
  static char buf[512];
  for (i = 0; i < 512; i++) {
    buf[i] = 'A';
  }
  const char *file_test_write_speed = MOUNT_POINT"/test_write_speed.txt";
  FILE *fi = fopen(file_test_write_speed, "w");
  uint32_t start = millis();
  uint32_t end = start;
  for (i = 0; i < 2048; i++) {
    fwrite(buf, 1, 512, fi);
  }
  end = millis() - start;
  Serial.printf("%u bytes written for %lu ms\n", 2048 * 512, end);
  fclose(fi);
  /////////////////  

  // All done, unmount partition and disable SDMMC peripheral
  esp_vfs_fat_sdcard_unmount(mount_point, card);
  Serial.println("Card unmounted");
}

void loop(){
  delay(1);
}

lbernstone
Posts: 1131
Joined: Mon Jul 22, 2019 3:20 pm

Re: eMMC write speed test

Postby lbernstone » Sun May 11, 2025 5:20 pm

You are writing single bytes. Disk writes will always be fastest if you match the write size to the sector/block size- 512 bytes in the case of an SD.

JPMJPM
Posts: 25
Joined: Fri Oct 13, 2017 4:35 pm

Re: eMMC write speed test

Postby JPMJPM » Mon May 12, 2025 6:17 am

I think fwrite(buf, 1, 512, fi) write an array of 512 bytes, Isn't that right ?.
Is there another way to do this ?.
Regards.

Who is online

Users browsing this forum: No registered users and 4 guests