Psram speed issue using an SD Card

_0b00t_
Posts: 12
Joined: Mon Dec 30, 2019 6:56 pm

Psram speed issue using an SD Card

Postby _0b00t_ » Tue Jan 07, 2020 1:32 pm

I encounter a problem with Psram (included in a Wrover B module) speed using an SD card in 4-bit mode.
To fill a buffer of 100KB stored in internal RAM it takes only 6 ms which is really fast using sdmmc_read_sectors()
But with the same buffer size stored in PSRAM it takes 136 ms ? Why so slow ? I'm using QSPI at 80 MHz for the flash and PSRAM.

Code: Select all

uint16_t *buf;
uint16_t *buf2;
buf = malloc(50000*sizeof(uint16_t));
buf2 = heap_caps_malloc(50000*sizeof(uint16_t), MALLOC_CAP_SPIRAM);
sdmmc_read_sectors(card, buf, offset, SECTOR_NB)
sdmmc_read_sectors(card, buf2, offset, SECTOR_NB)
However if I copy the same buffer size from the internal RAM to the PSRAM it takes only 6 ms using

Code: Select all

memcpy(buf2, buf,50000*sizeof(uint16_t));
Is it related to the fact that there is no DMA for PSRAM ?

ESP_Sprite
Posts: 9770
Joined: Thu Nov 26, 2015 4:08 am

Re: Psram speed issue using an SD Card

Postby ESP_Sprite » Wed Jan 08, 2020 2:52 am

Probably. As you have noticed, psram on the ESP32 is not accessible using DMA, so when you ask the driver to read into a buffer in PSRAM, it will allocate a temporary buffer of one block. It will then do single-block transactions into that temp buffer and copy that into the PSRAM buffer until it has filled the PSRAM buffer. Because lots of single-block transfers have way more overhead than one large transfer, this is going to be a lot slower, as you experienced. (Logic for this is here if you want to look at it yourself.)

_0b00t_
Posts: 12
Joined: Mon Dec 30, 2019 6:56 pm

Re: Psram speed issue using an SD Card

Postby _0b00t_ » Wed Jan 08, 2020 5:22 pm

After looking the source code of sdmmc_read_sectors() fonction, everything is clear about speed issue.
So you can't use PSRAM to store data from a SD card with high speed.
Is it possible to not use DMA for the sd card host and use CPU instead ?
I also don't understand why there is no DMA for PSRAM because it uses SPI, and there is DMA for VSPI, and HSPI ?
Will there be in the next versions of esp32 chip DMA for PSRAM ?

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

Re: Psram speed issue using an SD Card

Postby ESP_igrr » Wed Jan 08, 2020 10:02 pm

_0b00t_ wrote:
Wed Jan 08, 2020 5:22 pm
Is it possible to not use DMA for the sd card host and use CPU instead ?
No, the current version of SDMMC driver doesn't support FIFO based transfers.
_0b00t_ wrote:
Wed Jan 08, 2020 5:22 pm
I also don't understand why there is no DMA for PSRAM because it uses SPI, and there is DMA for VSPI, and HSPI ?
Will there be in the next versions of esp32 chip DMA for PSRAM ?
The SPI DMA allows for copying data from RAM to SPI transactions. What is needed here is different: to allow copying data from one peripheral (SDMMC) to the external RAM. Since the external RAM is accessed via cache, it is a matter of supporting DMA transfers in the cache controller.

The upcoming ESP32-S2 does have external memory DMA support for some peripherals. However it doesn't have an SD host.

_0b00t_
Posts: 12
Joined: Mon Dec 30, 2019 6:56 pm

Re: Psram speed issue using an SD Card

Postby _0b00t_ » Thu Jan 09, 2020 7:26 am

Thank you for the informations.

Who is online

Users browsing this forum: LiliumJSN and 78 guests