How does the IMX6 SPI use DMA to transfer data?

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How does the IMX6 SPI use DMA to transfer data?

2,886 Views
864535720
Contributor II

Hello everyone
I am using the IMX6Q development board of NXP official website. When I was using SPI for communication, I found that the SPI only uses DMA transfers when the bytes I transfer are larger than 64 bytes. When my data volume is less than 64 bytes, the SPI uses GPIO transmission. In my actual project, every byte I transfer is less than 64 bytes. However, because of the large amount of data, it is desirable to use DMA for transmission. Do you have any good suggestions?

Labels (1)
0 Kudos
8 Replies

2,249 Views
radhikasomaiya
Senior Contributor II

Hi,

From the Reference manual chapter 21:

User need to configure ECSPI.DMAREG register to enable the data transfer of ECSPI via DMA when the appropriate conditions are matched, the block will send out a DMA request. ECSPI.DMAREG register's field 7 is responsible for enables/disables the TXFIFO Empty DMA Request and field 0-5 (TX THRESHOLD shown in attached picture) is responsible to defines the FIFO threshold that triggers a TX DMA/INT request and a TX DMA/INT request is issued when the number of data entries in the TXFIFO is not greater than TX_THRESHOLD.

Here from the reference manual, i didn't found the default value but it is configurable using ECSPI.DMAREG.

For your reference page no. 990 (i.MX 6Dual/6Quad Applications Processor Reference Manual)

pastedImage_1.png pastedImage_2.png

I hope this helps!

2,249 Views
864535720
Contributor II

hi,Radhika Somaiya

   I modified the dma register based on the information you provided. At the same time I forced the change of

transfer->len > spi_imx_get_fifosize(spi_imx). Let all the data be transmitted via dma. Although my data was finally transmitted via dma, the data received was confusing and erroneous.
I would like to ask why there is a restriction of transfer->len > spi_imx_get_fifosize(spi_imx). Also want to know how to change this limit.

0 Kudos

2,249 Views
radhikasomaiya
Senior Contributor II

@其东 刘:

Please find my answers inline:

I would like to ask why there is a restriction of transfer->len > spi_imx_get_fifosize(spi_imx). Also want to know how to change this limit. -

[Radhika] This is the kernel optimization that decides when to use DMA and when to use GPIO.

Can you please provide below mentioned information for more clarification of your issue and changes you done?

  • Are you setting both the fields TX_THRESHOLD and RX_THRESHOLD of ECSPI.DMAREG  register? If yes then what values are you setting up? What is the behavior by changing this values only( No other changes in code ).
  • What are you changing in spi_imx_get_fifosize API? As per my understanding, it is not good idea to remove check for spi_imx_get_fifosize API. Instead, change values or logic accordingly.  What is the behavior by changes in the code only (spi_imx_get_fifosize)(Assuming there are no other changes).
  • Can you provide your sample application for DMA with steps to test it at our end?

Regards,

Radhika Somaiya

2,249 Views
864535720
Contributor II

hi,Radhika Somaiya:

   First of all, thank you very much for your help.

   I mainly modified the following places:

  1、 ECSPIx_DMAREG    (RX_THRESHOLD  TX_THRESHOLD)
   2、spi_imx->tx_config.dst_maxburst
   3、spi_imx->rx_config.src_maxburst

   4、The return value of the spi_imx_can_dma() function

first:

   When I set RX_THRESHOLD to 0x00
                     TX_THRESHOLD is set to 0x3f

result

   When the transmitted data is less than 64 bytes, spi uses PIO for data transmission and the transmission is successful.

   When the transmitted data is larger than 64 bytes, the kernel prints the following information::

   can't send spi message: Connectiospi_master spi1: failed to transfer one message from queue
    n timed out
    Aborted

next:Next, I modified it again in the spi_imx_sdma_init function.

      spi_imx->tx_config.dst_maxburst = 1;
      spi_imx->rx_config.src_maxburst = 1;

result

   When the transmitted data is less than 64 bytes, spi uses PIO for data transmission and the transmission is successful.

   When the transmitted data is larger than 64 bytes, the dma transmission is used and the transmission is successful.

Next, I made changes in the spi_imx_can_dma function. I forced the spi_imx_can_dma() function to return true even if transfer->len < spi_imx_get_fifosize(spi_imx)

result

   When the transmitted data is less than 64 bytes, spi uses dma for data transmission and the transmission is successful.
   When the transmitted data is larger than 64 bytes, the dma transmission is used and the transmission is successful.

So I think it might be a problem with spi_imx->tx_config.dst_maxburst and spi_imx->rx_config.src_maxburst. But in the file dmaengine.h it says:

* @src_maxburst: the maximum number of words (note: words, as in
 * units of the src_addr_width member, not bytes) that can be sent
 * in one burst to the device. Typically something like half the
 * FIFO depth on I/O peripherals so you don't overflow it. This
 * may or may not be applicable on memory sources.
 * @dst_maxburst: same as src_maxburst but for destination target
 * mutatis mutandis.

I want to ask, why is there such a problem?

Attachment is my spi-imx.c source code。

0 Kudos

2,249 Views
radhikasomaiya
Senior Contributor II

Hi 其东 刘,

I just want to confirm here that you are talking about transmitting and receiving of data both by the word transmission here. Am I understanding correctly here as you were facing the issue in reception only? Are able to receive the data properly now?

Regards,

Radhika Somaiya

0 Kudos

2,249 Views
864535720
Contributor II

Data can now be received normally.
But for the configuration involved in the program, I still feel a little problem. For example: when I set this up: spi_imx->tx_config.dst_maxburst = 32;
Spi_imx->rx_config.src_maxburst = 32;
The kernel will print: spi_master spi1: I/O Error in RX tail
Problems arise during the transfer of data.
Can you provide some other information for me to refer to?

0 Kudos

2,249 Views
gusarambula
NXP TechSupport
NXP TechSupport

Hello Anthony,

The Linux driver does not use the DMA feature for SPI. You would need to modify the driver located in drivers/spi/spi_imx.c

I hope this helps!

Regards,

2,249 Views
864535720
Contributor II

hello gusarambula,

   I want to use dma. And I think all my data is transmitted via dma. But in the spi-imx.c file. Inside the spi_imx_transfer function. Dma is only used when transfer->len > spi_imx_get_fifosize(spi_imx). I would like to ask, why is there a limit here?

0 Kudos