greiman/SdFat-beta

DMA Writes

Closed this issue · 1 comments

Hi - first I would like to thank you for the great work.

I was wondering if the SD FS Libraries can support DMA writes and would it improve write speeds?

Not sure if it is possible to come up with an interface that can be supported by underlying hardware such as Arduino, Teensy, ESP32 etc.

Many boards are supported with DMA. Custom drivers are in the src/SpiDriver/ folder.

Write speed mainly depends on dedicated SPI access to an SD card.

SD card emulate 512 byte sectors in 512 KiB flash pages. To optimize write speed you must maintain access to the SD. If you release access, the entire 512 KiB page is programmed. If you write another 512 byte virtual sector, data must be moved to the a new flash page. The result can be 400 KB/sec write performance for a 90 MB/sec SD. There may be 200 MB/sec internal data movement in the SD and extreme flash wear.

So DMA may slow write speed if it requires release of the SD. On Teensy with 4-bit SDIO, DMA can be 40 times slower than programmed transfers to a FIFO. Writes using programmed transfers on Teensy 4.0 run at 22 MB/sec for writes.

In short, SD cards are complex and DMA may not be very helpful.

Often DMA requires 4-byte aligned data which is incompatible with files since they are byte aligned. Even if a write buffer is 4-byte aligned you can't use DMA unless the file position is a multiple of four.