SPI hangs when I increase the clock frequency. What is happening?

I'm using a ADSP-SC573.

I run my SPI example in Core 0. It is setup to send 10 bytes on SPI0.

If I run the SPI clock at 2MHz using interrupt the adi_spi_ReadWrite() will never return, it hangs. If I run at 1MHz it works fine. And if I use DMA it always works. 

Feels like there is some kind of race condition in the drivers that makes it hang.

This is 1MHz (using interrupt), works fine:

This is 1MHz (using DMA):

This is 2MHz (using interrupt), it hangs, never returns from adi_spi_ReadWrite():

This is 2MHz (using DMA):

My test code (running in Core 0):

/*****************************************************************************
 * TestDrivers_Core0.cpp
 *****************************************************************************/

#define USE_DMA // Define to use DMA
#define SPI_CLOCK_FREQUENCY 2e6 // Defines the SPI clock frequency

#include <sys/platform.h>
#include <sys/adi_core.h>
#include "adi_initialize.h"
#include "TestDrivers_Core0.h"
#include <drivers/spi/adi_spi.h>
#include <stdio.h>

#ifdef USE_DMA
#define SPI_MEMORY_SIZE ADI_SPI_DMA_MEMORY_SIZE
#else
#define SPI_MEMORY_SIZE ADI_SPI_INT_MEMORY_SIZE
#endif

ADI_SPI_HANDLE hSpi;
uint8_t SpiMemory[SPI_MEMORY_SIZE];

bool test(void)
{
  while (1)
  {

    if (adi_spi_Open(0, &SpiMemory, SPI_MEMORY_SIZE, &hSpi)) break;

    /* device in master of the SPI interface */
    if (adi_spi_SetMaster(hSpi, true)) break;

    if (adi_spi_SetTransceiverMode(hSpi, ADI_SPI_TXRX_MODE)) break;

#ifdef USE_DMA
    /* use DMA */
    if (adi_spi_EnableDmaMode(hSpi, true)) break;
#else
    /* use interrupt */
    if (adi_spi_EnableDmaMode(hSpi, false)) break;
#endif
    /* SPI slave select in controlled by software not hardware */
    //if (adi_spi_SetHwSlaveSelect(hSpi, false)) break;
    if (adi_spi_SetHwSlaveSelect(hSpi, false)) break;

    if (adi_spi_ManualSlaveSelect(hSpi, true)) break;

    /* send zeros if tx SPI underflows*/
    if (adi_spi_SetTransmitUnderflow(hSpi, true)) break;

    /* data transitions on falling edge of clock */
    if (adi_spi_SetClockPhase(hSpi, false)) break;

    if (adi_spi_SetClockPolarity(hSpi, false)) break;

    /* Setup SPI clock */
    uint16_t spiClockRate = (112.5e6 / SPI_CLOCK_FREQUENCY) - 0.5f; // Note it is (112.5e6 / clkFrequency) - 1.0f + 0.5f     0.5f is for rounding before truncating
    if (adi_spi_SetClock(hSpi, spiClockRate)) break;

    /* SPI slave select is on SPI slave select 6 pin */
    if (adi_spi_SetSlaveSelect(hSpi, ADI_SPI_SSEL_ENABLE6)) break;

    /* SPI data transfers are 8 bit */
    if (adi_spi_SetWordSize(hSpi, ADI_SPI_TRANSFER_8BIT)) break;

    /* generate tx data interrupt when watermark level breaches 50% level */
    /* DMA watermark levels are disabled because SPI is in interrupt mode */
    if (adi_spi_SetTxWatermark(hSpi, ADI_SPI_WATERMARK_50, ADI_SPI_WATERMARK_DISABLE, ADI_SPI_WATERMARK_DISABLE)) break;

    /* generate rx data interrupt when watermark level breaches 50% level */
    /* DMA watermark levels are disabled because SPI is in interrupt mode */
    if (adi_spi_SetRxWatermark(hSpi, ADI_SPI_WATERMARK_50, ADI_SPI_WATERMARK_DISABLE, ADI_SPI_WATERMARK_DISABLE)) break;

    if (adi_spi_RegisterCallback(hSpi, NULL, NULL)) break;

    if (adi_spi_SlaveSelect(hSpi, true)) break;

    uint8_t prologue[10] = {1,2,3,4,5,6,7,8,9,10}; // 10 bytes to send

    ADI_SPI_TRANSCEIVER transceiver = { &prologue[0], 10, NULL, 0, NULL, 0 };
    if (adi_spi_ReadWrite(hSpi, &transceiver)) break;

    if (adi_spi_SlaveSelect(hSpi, false)) break;

    return true;
  }

  return false;
}



int main()
{
  /**
   * Initialize managed drivers and/or services that have been added to
   * the project.
   * @return zero on success
   */
  adi_initComponents();

  test();

  return 0;
}

I have found that it hangs forever in adi_osal_SemPend() in adi_osal_noos_sem.c. But I don't know why.

If I debug where it is stuck. It can't return because pSemNative->nCount is already 0 and therefore cant enter the if-statement that sets eRetStatus = ADI_OSAL_SUCCESS.

Why is this happening?



Corrected spelling
[edited by: masip at 11:04 AM (GMT -4) on 10 Jun 2021]