Page 1 of 1

Transfer data from SD Card (with SD/MMC host) to SPI Output in real time

Posted: Mon Jan 06, 2020 5:38 pm
by _0b00t_
Hi,
I'm wonder if there is a better way to transfer data as fast as possible continually from a SD Card to a SPI output ?
Currently the only way I have found is to have 2 large buffers in the RAM using the 2 cores.
I'm using DMA for SPI (and also for the SD I think ? )
While I'm writing data into buf1 on core 0 there is a SPI transaction that output buf2 on core 1.
And then, there is another SPI transaction for buf1 on core 1 while writing data into buf2 on core 0.

The problem is the amount of RAM that it uses.

Is there a way to use DMA buffers directly from SD Card peripheral to SPI peripheral without using so much RAM ?
For me currently, it does :
SD CARD -> DMA-> RAM -> DMA -> SPI and It could be : SD CARD -> DMA-> SPI
I have tried using the external PSRAM of a WROVER B module but the speed is 10 times slower :(

Re: Transfer data from SD Card (with SD/MMC host) to SPI Output in real time

Posted: Tue Jan 07, 2020 2:20 am
by ESP_Sprite
No, sorry, DMA always is from or to RAM (hence direct *memory* access).

Re: Transfer data from SD Card (with SD/MMC host) to SPI Output in real time

Posted: Tue Jan 07, 2020 1:05 pm
by _0b00t_
Is there a better way to do this ? Using only 1 core and not 2 cores ?
For example, can I trigger easily an interruption when the SD host has finished to write data into a buffer using sdmmc_read_sectors() ?
If it's possible I can send a SPI transaction into the interruption ?

Re: Transfer data from SD Card (with SD/MMC host) to SPI Output in real time

Posted: Tue Jan 07, 2020 2:23 pm
by Aeronautic
Create two large buffers (choosing buffers sizes, remember that maximum single DMA descriptor size is hardcoded to 4096-4 bits; dont know what happens when have to use multiple DMAs- see lldesc_setup_link).
Use only one core. Lets do: xSemaphoreTake(sdcard_semaphore_1,..), sdmmc_read_sectors to buffer_1 and than start SPI transmission in background. When transfer is finished give semaphore from post transfer ISR.
When buffer_1 is transferred to SPI device, read SD card data to buffer_2 same way as above: one is reading SD card, one is transmitting via SPI.

Re: Transfer data from SD Card (with SD/MMC host) to SPI Output in real time

Posted: Wed Jan 08, 2020 2:39 am
by ESP_Sprite
Or better: start two threads, one for reading, one for writing, and shuttle buffers between the two using a queue or something. As the tasks will block (=their code is not ran by the CPU so it has time to run other tasks) during DMA, you can put them both on the same core and they won't get in eachothers way.