SD card interface high speed mode

ph1l1p139
Posts: 3
Joined: Mon Jun 05, 2017 12:59 pm

SD card interface high speed mode

Postby ph1l1p139 » Mon Jun 05, 2017 1:20 pm

Hi,

I'm attempting to use the SD card interface functionality of the ESP32 module as part of a project. I'd like to be able to read at as high a speed as possible. Using 4 bit SDIO interface on SDMMC_HOST_SLOT_1 I can read raw sectors from various micro SD cards at up to about 9MB/s. However interestingly every card I've tried has been in default speed mode (25MHz max clock).

I have tried both my own code, the sd_card example and the sdmmc test app. I have made sure to uncomment the following line in the examples:

Code: Select all

// To allow capable cards to use high speed (40MHz) mode use the following flag
host.max_freq_khz = SDMMC_FREQ_HIGHSPEED;
I have tried using various micro SDHC cards (Sandisk extreme plus 32GB , Sandisk ultra 16GB, Kingston 4GB, Samsung 32GB) all of which claim to support UHS-1. (Labeling on the cards is both class 10 and UHS-1).

The hardware is using a micro SD -> SD card adaptor connected to the ESP32 dev board C on bread board. the CMD,CLK and DAT lines have 10k pull ups and 33R series resistors (having some issues with signal integrity due to the bread-boarding). There is also a 10pF cap on the clock line (to GND) for similar issues. The card is decoupled with 10uF. This setup works reliably with both RAW read/write and FAT filesystems at deafult speed.

Looking at the CSD response the TRAN_SPEED field as accessed by SD_CSD_SPEED(response); in the sdmmc_decode_csd() function called as part of sdmmc_card_init() always gives a TRAN_SPEED of 0x32 (25Mb/s).

I was under the impression that I'd be able to access a UHS-1 card in high speed mode, is this incorrect? Has anyone had any luck in accessing a (micro) SD card in high speed mode?

Thanks,
Phil

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: SD card interface high speed mode

Postby ESP_igrr » Mon Jun 05, 2017 2:23 pm

According to the spec (table 3-7 in ver 4.1) HS is mandatory for UHS50 and UHS104... So the issue is that TRAN_SPEED doesn't read 0x5a for some reason. I don't know why this is happening, but will order a few UHS cards to test.

For HS mode we will also likely need to do delay tuning, especially for a breadboard. This is not currently implemented, and may require some new ways of interaction between the SD/MMC peripheral part and the SD/MMC protocol part.

Another thing to note is that we are currently using 20MHz clock in DS mode and 40MHz in HS, due to clock divider limitation. The frequencies which can be obtained are 160MHz / (n + 1), 0 < n < 16, which means that 53,3 and 26.7 MHz clocks are possible (although slightly out of spec). So you can get 33% speed increase by changing the clock from 20 to 26.7 in DS mode.
See https://github.com/espressif/esp-idf/bl ... #L123-L125 if you want to try this.

ph1l1p139
Posts: 3
Joined: Mon Jun 05, 2017 12:59 pm

Re: SD card interface high speed mode

Postby ph1l1p139 » Mon Jun 05, 2017 3:30 pm

Hi,

Thanks very much for the info. It sounds like high speed mode hasn't been fully tested/integrated yet so I shall stick with default speed for now (although I'd be interested to hear of any developments with your investigation into high speed mode). I'll give the clocking changes a go once i get the chance.

Thanks,
Phil

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: SD card interface high speed mode

Postby ESP_igrr » Wed Jul 12, 2017 1:50 pm

We have added HS mode to the SDMMC driver. The feature needs more extensive testing, i expect that it will be part of the next major version. If you want to try it out, let me know and i will push the branch to Github.

Here are some performance numbers for comparison, obtained with a 32GB Sandisk Extreme UHS-II card.

Default speed mode:

Code: Select all

Name: SE32G
Type: SDHC/SDXC
Speed: default speed
Size: 30436MB
CSD: ver=1, sector_size=512, capacity=62333952 read_bl_len=9
SCR: sd_spec=2, bus_width=5
  sector  | count | size(kB) | wr_time(ms) | wr_speed(MB/s) | rd_time(ms) | rd_speed(MB/s)
        0 |    1  |    0.5   |     2.79    |      0.18      |    0.46     |     1.06
        0 |    4  |    2.0   |     1.04    |      1.89      |    0.48     |     4.04
        1 |   16  |    8.0   |     4.03    |      1.94      |    1.09     |     7.18
       16 |   32  |   16.0   |     2.62    |      5.97      |    1.94     |     8.07
       48 |   64  |   32.0   |     5.99    |      5.21      |    3.64     |     8.59
      128 |  128  |   64.0   |     9.67    |      6.46      |    7.02     |     8.90
 62333888 |   32  |   16.0   |     3.99    |      3.91      |    1.94     |     8.06
 62333888 |   64  |   32.0   |     4.28    |      7.30      |    3.63     |     8.60
 62333944 |    1  |    0.5   |     0.74    |      0.66      |    0.29     |     1.71
 31166976 |    1  |    0.5   |     0.74    |      0.66      |    0.29     |     1.71
 31166976 |    4  |    2.0   |     1.03    |      1.90      |    0.49     |     3.95
 31166976 |    8  |    4.0   |     2.90    |      1.35      |    0.69     |     5.69
 31166976 |   16  |    8.0   |     1.90    |      4.10      |    1.09     |     7.15
 31166976 |   32  |   16.0   |     2.81    |      5.57      |    1.93     |     8.08
 31166976 |   64  |   32.0   |     6.50    |      4.81      |    3.64     |     8.58
 31166976 |  128  |   64.0   |     9.85    |      6.35      |    7.03     |     8.89
/Users/ivan/e/esp-idf/components/sdmmc/test/./test_sd.c:121:can write and read back blocks:PASS
Test ran in 328ms

High speed mode:

Code: Select all

Name: SE32G
Type: SDHC/SDXC
Speed: high speed
Size: 30436MB
CSD: ver=1, sector_size=512, capacity=62333952 read_bl_len=9
SCR: sd_spec=2, bus_width=5
  sector  | count | size(kB) | wr_time(ms) | wr_speed(MB/s) | rd_time(ms) | rd_speed(MB/s)
        0 |    1  |    0.5   |     7.76    |      0.06      |    0.40     |     1.24
        0 |    4  |    2.0   |     0.93    |      2.11      |    0.38     |     5.18
        1 |   16  |    8.0   |     1.76    |      4.43      |    0.67     |     11.59
       16 |   32  |   16.0   |     3.57    |      4.38      |    1.10     |     14.18
       48 |   64  |   32.0   |     4.43    |      7.05      |    1.96     |     15.94
      128 |  128  |   64.0   |     6.51    |      9.59      |    3.67     |     17.03
 62333888 |   32  |   16.0   |     3.60    |      4.34      |    1.10     |     14.24
 62333888 |   64  |   32.0   |     4.20    |      7.44      |    1.96     |     15.93
 62333944 |    1  |    0.5   |     0.72    |      0.68      |    0.26     |     1.91
 31166976 |    1  |    0.5   |     0.72    |      0.68      |    0.26     |     1.91
 31166976 |    4  |    2.0   |     0.92    |      2.12      |    0.38     |     5.18
 31166976 |    8  |    4.0   |     0.71    |      5.52      |    0.44     |     8.96
 31166976 |   16  |    8.0   |     3.33    |      2.35      |    0.67     |     11.73
 31166976 |   32  |   16.0   |     1.75    |      8.91      |    1.10     |     14.24
 31166976 |   64  |   32.0   |     4.35    |      7.19      |    1.96     |     15.94
 31166976 |  128  |   64.0   |     5.99    |      10.44      |    3.67     |     17.03
/Users/ivan/e/esp-idf/components/sdmmc/test/./test_sd.c:121:can write and read back blocks:PASS
Test ran in 449ms

sintech
Posts: 27
Joined: Wed Dec 14, 2016 2:54 pm

Re: SD card interface high speed mode

Postby sintech » Wed Jul 12, 2017 2:20 pm

ESP_igrr, is there any performance improvement in 1 bit mode?

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: SD card interface high speed mode

Postby ESP_igrr » Wed Jul 12, 2017 4:59 pm

Here are the numbers for 1 bit mode:

Default speed mode:

Code: Select all

  sector  | count | size(kB) | wr_time(ms) | wr_speed(MB/s) | rd_time(ms) | rd_speed(MB/s)
        0 |    1  |    0.5   |     7.79    |      0.06      |    0.61     |     0.80
        0 |    4  |    2.0   |     1.66    |      1.18      |    1.11     |     1.76
        1 |   16  |    8.0   |     4.65    |      1.68      |    3.59     |     2.18
       16 |   32  |   16.0   |     7.70    |      2.03      |    6.88     |     2.27
       48 |   64  |   32.0   |    16.12    |      1.94      |    13.46     |     2.32
      128 |  128  |   64.0   |    29.71    |      2.10      |    26.70     |     2.34
 62333888 |   32  |   16.0   |    12.29    |      1.27      |    6.90     |     2.27
 62333888 |   64  |   32.0   |    15.59    |      2.01      |    13.47     |     2.32
 62333944 |    1  |    0.5   |     2.39    |      0.20      |    0.44     |     1.12
 31166976 |    1  |    0.5   |     0.90    |      0.55      |    0.44     |     1.11
 31166976 |    4  |    2.0   |     1.65    |      1.19      |    1.11     |     1.76
 31166976 |    8  |    4.0   |     2.15    |      1.82      |    1.93     |     2.02
 31166976 |   16  |    8.0   |     4.37    |      1.79      |    3.61     |     2.17
 31166976 |   32  |   16.0   |     7.93    |      1.97      |    6.88     |     2.27
 31166976 |   64  |   32.0   |    16.38    |      1.91      |    13.46     |     2.32
 31166976 |  128  |   64.0   |    29.53    |      2.12      |    26.68     |     2.34
High speed mode:

Code: Select all

  sector  | count | size(kB) | wr_time(ms) | wr_speed(MB/s) | rd_time(ms) | rd_speed(MB/s)
        0 |    1  |    0.5   |     2.80    |      0.17      |    0.50     |     0.98
        0 |    4  |    2.0   |     1.23    |      1.59      |    0.69     |     2.83
        1 |   16  |    8.0   |     4.65    |      1.68      |    1.94     |     4.02
       16 |   32  |   16.0   |     4.37    |      3.58      |    3.54     |     4.41
       48 |   64  |   32.0   |     9.86    |      3.17      |    6.86     |     4.56
      128 |  128  |   64.0   |    16.28    |      3.84      |    13.47     |     4.64
 62333888 |   32  |   16.0   |     5.97    |      2.62      |    3.55     |     4.40
 62333888 |   64  |   32.0   |     9.30    |      3.36      |    6.85     |     4.56
 62333944 |    1  |    0.5   |     0.82    |      0.60      |    0.34     |     1.45
 31166976 |    1  |    0.5   |     0.78    |      0.62      |    0.33     |     1.49
 31166976 |    4  |    2.0   |     1.23    |      1.59      |    0.70     |     2.81
 31166976 |    8  |    4.0   |     1.32    |      2.95      |    1.10     |     3.55
 31166976 |   16  |    8.0   |     2.54    |      3.08      |    1.93     |     4.05
 31166976 |   32  |   16.0   |     4.25    |      3.68      |    3.55     |     4.40
 31166976 |   64  |   32.0   |     9.23    |      3.39      |    6.85     |     4.56
 31166976 |  128  |   64.0   |    15.77    |      3.96      |    13.47     |     4.64

humberry
Posts: 2
Joined: Fri Nov 10, 2017 4:44 pm

Re: SD card interface high speed mode

Postby humberry » Fri Nov 10, 2017 5:02 pm

Hi,
I was playing around with the SPI connected sd card in default speed (20MHz clock), then I decided to change the clock to 26.7MHz by setting the SDMMC.clock.div_factor_h to 5 (instead of 1 => hint in the second post). I also removed the old build folder to get sure the changes are made, but I had no luck. I have still a 20MHz clock. Any ideas how I can increase the speed/clock?

@ESP_igrr: Could I get the link to the HS mode Github branch, please?

Thank you...

adamtegen
Posts: 4
Joined: Wed Aug 01, 2018 10:12 pm

Re: SD card interface high speed mode

Postby adamtegen » Wed Aug 01, 2018 10:29 pm

I am having similar results with fread(), roughly 1MBps. Would you be able to post the code you used for that test with the raw sectors? I'm curious if I get the same results.

Adam

ESP_igrr
Posts: 2072
Joined: Tue Dec 01, 2015 8:37 am

Re: SD card interface high speed mode

Postby ESP_igrr » Thu Aug 02, 2018 7:19 am

The output above was produced by unit test of sdmmc component. You can go to $IDF_PATH/tools/unit-test-app, and there "make flash monitor TEST_COMPONENTS=sdmmc".

adamtegen
Posts: 4
Joined: Wed Aug 01, 2018 10:12 pm

Re: SD card interface high speed mode

Postby adamtegen » Thu Aug 02, 2018 5:04 pm

Thanks. I was able to get good results on the raw sector reads. I believe I've narrowed down the bottleneck to whatever is calling esp_vfs_read(). Even though I have some relatively large buffers, esp_vfs_read() is being called with 128 bytes as an argument.

Would you be able to assist me in tracking that down? If I can, I believe it could close the gap between the raw sector performance (I'm seeing 17MBps) and the fread() performance of 1MBps.

Adam

Who is online

Users browsing this forum: Bing [Bot] and 137 guests