Page 1 of 1

Psram speed issue using an SD Card

Posted: Tue Jan 07, 2020 1:32 pm
by _0b00t_
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 ?

Re: Psram speed issue using an SD Card

Posted: Wed Jan 08, 2020 2:52 am
by ESP_Sprite
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.)

Re: Psram speed issue using an SD Card

Posted: Wed Jan 08, 2020 5:22 pm
by _0b00t_
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 ?

Re: Psram speed issue using an SD Card

Posted: Wed Jan 08, 2020 10:02 pm
by ESP_igrr
_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.

Re: Psram speed issue using an SD Card

Posted: Thu Jan 09, 2020 7:26 am
by _0b00t_
Thank you for the informations.