cancel
Showing results for 
Search instead for 
Did you mean: 

SPI vs DMA SPI.

JAlca
Senior

Hi all,

I'm triyng to make the fastest possible driver to comunicate with an ILI9341.

My question is about DMA.

If I send a burst of bytes to the ILI9341, lets say 1000, is the DMA version faster than normal version?

I mean if

         HAL_SPI_Transmit(HSPI_INSTANCE, BurstBuffer, 1000, 100);

Is different in speed of execution than

        HAL_SPI_TransmitDMA(HSPI_INSTANCE, BurstBuffer, 1000);

4 REPLIES 4

Probably not (unless HAL_SPI_Transmit is written worse than I thought and you use some extreme baudrate and no optimization etc.); but DMA allows you to do other things while it transmits.

JW

TDK
Guru

In general they should be the same but if your baud rate is fast enough, HAL_SPI_Transmit might have pauses between bytes and therefore be slower.

If you feel a post has answered your question, please click "Accept as Solution".
Nikita91
Lead II

The DMA is valid in some cases:

- The CPU is fast

- The frequency of SPI is low

- the size of the data is large

Under these conditions DMA can be more interesting than polling.

Why:

DMA preparation takes time. This DMA configuration time must be short compared to the duration of SPI data transmission.

If the SPI frequency is high, this preparation time may be equivalent to that of the transmission of the data packet: In this case, 50% of the time is lost!

A priori for video the SPI frequency is high. So you have to measure ...

If you use an RTOS, another task can run while the transmitting task sleep waiting the DMA end. But task switching take time. So test...

An oscilloscope is your friend.

L4R5 120 MHZ: Trace 1 SPI clock (30 MHz), trace 2 Task work: Polling0693W000000X1UNQA0.png

L4R5 120 MHZ: Trace 1 SPI clock, trace 2 Task work: DMA

Before the SPI data: DMA start (DMA was configured before)

After the SPI data: DMA Interrupt handler, task signaling, task switch, and at the end DMA clear.

0693W000000X1UhQAK.png

In this case polling: 13µs, DMA 40%µs

The SPI frequency is fast, the message is short: not suitable for DMA!

And remember: in general, the HAL functions are not fast. It might be better to write your own polling write routine: it's not complicated once HAL has configured the SPI ...

S.Ma
Principal

If DMA is available and sending at least 16 bytes of data, I would use DMA under interrupts.

Actually, if you implement a smart SPI with a state machine running step by step triggered by ISRs (SPI, DMA, Timer, etc...) it can actually run as background task even in bare metal mode. Don't think DMA in polling mode if just waiting for it to complete.

With DMA HW assist, I expect an average baudrate higher when the core clocked is reduced to save power when the product is becoming functional.