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

Edit Notes

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

    by forcing READY line low as the first instruction in Callback() code and forcing it high again as the last instruction in Callback() code, I verified that the overall execution time of Callback() does not take (relatively) that long, but that the most expensive part of the whole DMA mode switching operation resides in the interrupt latency!

    As you can see in the image above, I measured around 1us delay starting from CLK rising edge during last bit in the last SPI master transmitted byte and ending when READY line is brought low by Callback() invocation. 1us latency looks to be way too much.

Reply
  • Hello again,

    by forcing READY line low as the first instruction in Callback() code and forcing it high again as the last instruction in Callback() code, I verified that the overall execution time of Callback() does not take (relatively) that long, but that the most expensive part of the whole DMA mode switching operation resides in the interrupt latency!

    As you can see in the image above, I measured around 1us delay starting from CLK rising edge during last bit in the last SPI master transmitted byte and ending when READY line is brought low by Callback() invocation. 1us latency looks to be way too much.

Children
No Data

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.