cancel
Showing results for 
Search instead for 
Did you mean: 

Differences between DMA call back and Interrupt call back (SPI, UART, etc)

HDaji.1
Senior

If I want to do some communication using SPI or UART, there are options like DMA or Interrupt, both of which give me callback. That means after MCU issues or start Tx/Rx function, it is free to do something else while waiting for the Tx/Rx complete callback.

Can anyone enlighten me what are the pros and cons of using DMA or interrupt? Is DMA always preferred?

1 ACCEPTED SOLUTION

Accepted Solutions
GwenoleB
ST Employee

Hello @HDaji.1​ ,

What you need to know about Interrupt and DMA is the CPU usage. DMA works independently of CPU, in this way some tasks can be executed when receiving data from SPI/UART. DMA will load/store data in memory that you have allocated for. Interrupt needs some clock cycles to enter into the subroutine, then execute it and exit the ISR. During this time, all tasks are stopped.

The choice between interrupt and DMA depends of your application, but generally DMA is preferred and especially when memory for computing or communication IPs are used in continuous.

Even if DMA doesn't need interrupt to work, it's possible to configure some if you need (for example trigger IRQ after each DMA transfer or DMA error occurs).

I hope it will help.

Best regards,

Gwénolé

View solution in original post

2 REPLIES 2
GwenoleB
ST Employee

Hello @HDaji.1​ ,

What you need to know about Interrupt and DMA is the CPU usage. DMA works independently of CPU, in this way some tasks can be executed when receiving data from SPI/UART. DMA will load/store data in memory that you have allocated for. Interrupt needs some clock cycles to enter into the subroutine, then execute it and exit the ISR. During this time, all tasks are stopped.

The choice between interrupt and DMA depends of your application, but generally DMA is preferred and especially when memory for computing or communication IPs are used in continuous.

Even if DMA doesn't need interrupt to work, it's possible to configure some if you need (for example trigger IRQ after each DMA transfer or DMA error occurs).

I hope it will help.

Best regards,

Gwénolé

HDaji.1
Senior

Thx. I got the idea.