This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

RTOS/AM5728: Inconsistent SPI transfers

Part Number: AM5728


Tool/software: TI-RTOS

Hi Team,

   I am Using PROCESSOR-SDK_RTOS-AM572x - pdk_am57xx_1_0_8 .I am running TI-RTOS on DSP core. I have written a abstraction layer for my slave FPGA Sitting on SPI3CS0, While doing single spi transaction multiple times in a loop, I am seeing  some spi transactions are missing. I went through the driver the code is in proper sync with data sheet. I wonder why I am facing this inconsistent SPI transactions. Clock is in PHA0POL0 with a speed of 1 MHz and CS is in active low state.

Please help me in this regard, and let me know if any extra inputs needed.

Thanks and Regards,

Pratik.   

  • The RTOS team have been notified. They will respond here.
  • Hi,

    We have SPI driver examples under pdk_am57xx_1_0_x\packages\ti\drv\spi and a wiki page: processors.wiki.ti.com/.../Processor_SDK_RTOS_QSPI-McSPI

    Do you use TI AM572x IDK EVM or your own board for this testing? Can you try the MCSPI examples in a loop to see if you missed any transaction?

    Also you mentioned "speed of 1 MHz". From my reading of AM572x TRM, 24.4 Multichannel Serial Peripheral Interface.
    In master mode, the baud rate of the SPI serial clock is programmable using the 48-MHz reference
    clock (from the power, reset, and clock managment [PRCM] module). Table 24-290 lists the
    spim_sclk bit rates obtained for data transfer when programming the clock divider (the
    SPIm.MCSPI_CHxCONF[5:2] CLKD bit field). What divider you used to achieve 1MHz?

    Regards, Eric
  • Hi Eric,

       I am Using phytech phycore-AM5728 board for this testing.

      I have tried MCSPI example in loop, I have attached the Image from the oscilloscope.I am doing a single transaction multiple times with a delay of 10 ms, I probed the sclk line, I can see some transaction missing. 

      

    I above Image The time between two cursor is 10 ms, Which is proper but In below Image the time between two cursor is 38 ms i.e some transactions are missing in between.

    I can clearly see some transactions are missing between the two cursors.

    The clock speed 1 MHz is programmed as below. The spiInClk is 40 MHz spiOutClk is 1 MHz. The below code is found in path 

    /ti/pdk_am57xx_1_0_8/packages/ti/csl/src/ip/mcspi/V0/priv/mcspi.c

    void McSPIClkConfig(uint32_t baseAddr,
                        uint32_t spiInClk,
                        uint32_t spiOutClk,
                        uint32_t chNum,
                        uint32_t clkMode)
    {
        uint32_t fRatio;
        uint32_t spiClk;
        uint32_t clkD;
        /*TI_INSPECTED 105 D: MISRAC_2012_R.2.2
         * "Reason - LDRA tool issue not able to understand HW_WR_FIELD32 macros
         *" */
        uint32_t extClk;
    
        /* Calculate the value of fRatio. */
        fRatio = spiInClk / spiOutClk;
    
        /* If fRatio is not a power of 2, set granularity of 1 clock cycle */
        if ((uint32_t) 0U != (fRatio & (fRatio - 1U)))
        {
            /* Set the clock granularity to 1 clock cycle.*/
            HW_WR_FIELD32(
                baseAddr + MCSPI_CHCONF(chNum),
                MCSPI_CH0CONF_CLKG,
                MCSPI_CH0CONF_CLKG_ONECYCLE);
    
            /* Calculate the ratios clkD and extClk based on fClk */
            extClk = (fRatio - 1U) >> 4U;
            clkD   = (fRatio - 1U) & (uint32_t) MCSPI_CLKD_MASK;
    
            /* Set the extClk field of MCSPI_CHCTRL register.*/
            HW_WR_FIELD32(
                baseAddr + MCSPI_CHCTRL(chNum),
                MCSPI_CH0CTRL_EXTCLK,
                extClk);
        }
        else
        {
            clkD   = 0U;
            /* Clock granularity of power of 2.*/
            HW_WR_FIELD32(
                baseAddr + MCSPI_CHCONF(chNum),
                MCSPI_CH0CONF_CLKG,
                MCSPI_CH0CONF_CLKG_POWERTWO);
    
            while (1U != fRatio)
            {
                fRatio /= 2U;
                clkD++;
            }
        }
    
        /* Configure the clkD field of MCSPI_CHCONF register.*/
        HW_WR_FIELD32(
            baseAddr + MCSPI_CHCONF(chNum),
            MCSPI_CH0CONF_CLKD,
            clkD);
    
        /*Clearing the clkMode field of MCSPI_CHCONF register.*/
        spiClk = HW_RD_REG32(baseAddr + MCSPI_CHCONF(chNum));
    
        spiClk &= ~((uint32_t) MCSPI_CH0CONF_PHA_MASK | (uint32_t) MCSPI_CH3CONF_POL_MASK);
    
        /* Configure the clkMode of MCSPI_CHCONF register.*/
        spiClk |= (clkMode & (MCSPI_CH0CONF_PHA_MASK | MCSPI_CH3CONF_POL_MASK));
    
        HW_WR_REG32(baseAddr + MCSPI_CHCONF(chNum), spiClk);
    }
    

  • Hi,

    Can you elaborate the two pics you posted? To me it looked the same, one group contains 3 spikes of SCLK. In the first pic, you measured the gap of the 2nd and 3rd spike in the SAME group, it is 10ms. Then, in the 2nd picture, you measured the gap between 3rd spike of a group to the 1st spike of the NEXT group, it is 38 ms? If you do the same measurement, it is also 10ms in the second group. Or 38ms in the first group.

    Regards, Eric
  • Hi Eric,

         The expected capture from the oscilloscope is continuous spikes with a 10 ms delay in between, But some spikes are missing as seen from the pictures. There are no groups of spikes  in above pictures,The second picture signifies that there is transaction miss in between, when I measure the delay between 2 spikes in between in the second picture it is 38 ms( as shown by cursor ) which should be 10 ms which clearly signifies there are 2 transaction miss in between. I have attached the snippet of the code.

     while(1) {
    
        transaction.count = McSPI_DATA_COUNT;
        transaction.txBuf = gTxBuffer;
        transaction.rxBuf = gRxBuffer;
        ret = SPI_transfer(gSpiHandle, &transaction);
        Task_sleep(10); // 10 ms delay
    }

    Currently I am trying with a blocking mode of transfer, The captured above pictures are for blocking mode. When I changed it to callback mode I am seeing more transaction miss than blocking mode.

  • Hi,

    I tried the MCSPI_BasicExample_idkAM572x_c66xExampleProject on AM572x IDK EVM, C66x core. I used the blocking mode and SPI_POL0_PHA0 and data rate 1MHz. I used a while loop to continue do a SPI_transfer with a Task_sleep of 10ms. I also used a timer (TSCL) to record the timestamp, the SPI read the data from industrial input module by shortening J37 pin 1 and 2. The code like this:

    while(1) {
    rxBuf[0] = 0xFF;
    LoadData();
    transaction.count = transferLength;
    transaction.txBuf = &txBuf[0];
    transaction.rxBuf = &rxBuf[0];
    retVal = SPI_transfer(handle, &transaction);
    Task_sleep(10);
    delay(DELAY_VALUE);
    stamp[i++%1000] = TSCL;

    if(false == retVal)
    {
    SPI_log("\n Error occurred in spi transfer \n");
    }
    else
    {
    /**
    * This below is check is required for callback mode to indicate the
    * transfer completion.
    */
    if(SPI_MODE_CALLBACK == spiParams.transferMode)
    {
    while(txCompleteCallbackFlag == 1U);
    }

    retVal = VerifyData((uint8_t *)&serializerData[0], &rxBuf[0], transferLength);

    if(true == retVal)
    {
    SPI_log("\n All tests have passed. \n");
    }
    else
    {
    SPI_log("\n Some tests have failed. \n");
    }
    }
    }

    I was able to look at the timestamp from CCS memory windows and also the print out of the UART to see if data read-back is correct or not. I also changed Task_sleep with a smaller number and remove the UART print by writing pass/fail into memory. I didn't see any SPI data transfer miss. So I don't think there any issue for this.

    Can you reproduce your issue on TI AM57x EVM?

    Regards, Eric