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

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

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

Postby _0b00t_ » Mon Jan 06, 2020 5:38 pm

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 :(

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

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

Postby ESP_Sprite » Tue Jan 07, 2020 2:20 am

No, sorry, DMA always is from or to RAM (hence direct *memory* access).

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

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

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

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 ?

Aeronautic
Posts: 15
Joined: Thu Jan 02, 2020 12:07 am

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

Postby Aeronautic » Tue Jan 07, 2020 2:23 pm

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.

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

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

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

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.

Who is online

Users browsing this forum: nopnop2002 and 123 guests