Post Go back to editing

adi_spi_DMAWrite() taking too long (more in general, ADI SPI driver functions are slow)

Category: Software
Product Number: ADSP-21569
Software Version: CCES 2.12.1 (but I already tested that CCES 3.0.2 is the same)

Back for the second episode of my series.

I have therefore expanded the project code illustrated in the first post of this series (here: SPI slave mode shifting 1s on MISO pin during adi_spi_DMARead() operation - Q&A - ADSP-2156x - EngineerZone) to get one step closer to the real-world application I'm going to develop.

In my application idea, master SPI is going to transfer N bytes to the slave, then slave SPI is going to transfer M bytes back to the master, all in a single transaction (by transaction I mean that, from SPI masters' point of view, the whole data exchange would be equivalent to a single transfer of N+M bytes).

To simulate this new scenario, I then applied the following changes to the code:

  • in main() function, I switched to software slave select mode, then I asserted slave select line right before DMA write call (let me say in the meantime that adi_spi_SoftwareAssert() is really a poor naming choice for a function dealing with slave select line driving....):

  • I modified data buffer lengths and added a third buffer for slaves' response data:

  <--- in SPIDMAMode.h, replacing DESC_BUFFER_SIZE macro

 <--- in SPIDMAMode.c

  • I modified PrepareDataBuffers() function to initialize SrcData with REQUEST_LEN bytes of dummy data and padding it with RESPONSE_LEN bytes used to retrieve response data back from the SPI slave, and I added a second PrepareResponseBuffer() function that will be used later by the SPI slave to simulate the slave is preparing something to send back to the master:

  • I modified PrepareDescriptors() function basically to make it consistent with applied changes to source/destination buffers lengths:

  • Then, finally, I modified interrupt callback as follows, also passing SPI handlers as callback parameter:

 <--- new callback code

 <--- changes in main() to pass SPI handlers as callback parameters.

Keeping SPI clock to around 1.3 MHz as in my previous post the result is exactly as expected:

but later when trying to raise clock frequency just a little bit to around 1.6MHz, this is what starts to happen:

clearly meaning that adi_spi_DMAWrite() inside Callback() is taking too long while disabling/enabling SPI slave peripheral.

This is what emerges by "looping the SPI dance forever" then analyzing the situation with statistical profiling:

So, the question is: how can I improve this behavior? There's no solution other than stop using ADI SPI driver and switching to a lower-level approach?

Thanks in advance to anyone who wants to contribute



broken link, fixed?
[edited by: SpoonMan999 at 1:50 PM (GMT -4) on 20 Mar 2025]
Parents Reply Children
  • Hi,

    We understand that you want to transfer data between the master and slave using SPI. Initially, data should be transmitted from the master to the slave, and once that is finished, the transmission should occur in the opposite direction, from the slave to the master. The issue you are encountering is that the data transfer from slave to master is not functioning correctly when the SPI clock is set to 1.6MHz but works fine when the clock is set to 1.3MHz. You suspect that latency may be causing this issue. Could you please confirm if this is correct?

    Additionally, we have the following questions to narrow down the issue.

    1) Could you confirm whether the callback execution time is the same for both 1.3MHz and 1.6MHz SPI clock frequencies?
    2) Are there any error bits enabled in the SPI/DMA status register? Can you please share screenshot of register browser window.
    3) Are the SPI modules properly disabled before being reconfigured for slave transmission and master reception?
    4) Just to ensure this behavior, is it possible to configure the API outside of the callback and check if the issue still persists.

    Regards,
    Nandini C

  • Hi Nandini, happy to read you again even here Slight smile

    > Could you please confirm if this is correct?

    Yes, I confirm, your understanding of the scenario is correct.

    > 1) Could you confirm whether the callback execution time is the same for both 1.3MHz and 1.6MHz SPI clock frequencies?

    Measured 1 us latency @ 1.6 MHz, 0.9375 us latency @ 1.23 MHz. I measured it by means of a low speed logic analyzer, so I think that 62.5 ns time difference is probably more of a measurement error than a real latency difference.

    > 2) Are there any error bits enabled in the SPI/DMA status register? Can you please share screenshot of register browser window.

    I don't have the information about when you would like to see registers content, in the following you can see the content I captured at the end of the whole transfer (SPI1 read 8 bytes then wrote 2 bytes then I captured the registers content):

    I don't see any error flag set, additionally Callback() is never invoked for events different from ADI_SPI_EVENT_TX_PROCESSED or ADI_SPI_EVENT_RX_PROCESSED so I were already almost sure that any error condition had been triggered.

    > 3) Are the SPI modules properly disabled before being reconfigured for slave transmission and master reception?

    Disabled? Why? You have to tell me the answer to your own question, since ADI code in adi_spi_DMAWrite() and adi_spi_DMARead() is in charge of disabling/enabling SPI peripheral and related while changing settings:

    > 4) Just to ensure this behavior, is it possible to configure the API outside of the callback and check if the issue still persists.

    Could you please clarify what do you want me to do? I can't fully understand what you mean, sorry.

    Thanks in advance for your support

  • Hi,

    We are working on modifying the BSP example based on the code snippets you shared to replicate the issue on our end. We will get back to you if we encounter any problems or need further information.

    Regards,
    Nandini C

  • Hi, sure, let me know, in case I can even share the whole project with you.

  • Hi,

    Thank you. Can you please share the project file, so that we can try to replicate and assist you better on this.

    Regards,
    Nandini C

  • Hi,
    Thank you for sharing the example code. We are checking the code and will get back to you early in the next week.
    Regards,
    Nandini C
  • Hi,

    We are checking internally regarding your query and will get back to you as soon as possible.

    Regards,
    Nandini C