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/am3359: SPI loopback example

Part Number: AM3359


Tool/software: TI-RTOS

hi

my own board is icev2AM335x.i want to embedded the program whose directory  is  "pdk_am335x_1_0_5\packages\ti\drv\spi\example\mcspiLoopbackApp\src"(windows)

what i do is add some code in the mcspiLoopbackApp\src

such as

boardCfg = BOARD_INIT_PINMUX_CONFIG |
        BOARD_INIT_MODULE_CLOCK |
        BOARD_INIT_UART_STDIO;
    Board_init(boardCfg);

and use SPI1 single channel to transmit and recieve data

and short  the pin spi_d0 and spi_d1

check the pinmux

check the register

write the CONTROL_MODULE Registers to set the pin mux mode

i have done anything what i supposed to do

but i cannot work as well when is start in the McSPIVerifyData

i check the mcspi_tx0 and mcspi_rx0

i found that mcspi_rx0 value is 0

so i think is the am335 support  the loopback?

just short the spi1_d0 and spi_d1 ,does  the  spi1 master can  transmit and recieve itself .

if it support ,please tell me what should i check to use the loopbackapp in icveam335x

 

  • The RTOS team have been notified. They will respond here.
  • the program is there

    #define MCSPI_INSTANCE 1
    SPI_Params gSpiParams = {
    SPI_OPER_MODE_BLOCKING, /* transferMode */
    SemaphoreP_WAIT_FOREVER,/* transferTimeout */
    NULL, /* transferCallbackFxn */
    SPI_MASTER, /* mode */
    1000000, /* bitRate */
    8, /* dataSize */
    SPI_POL0_PHA0, /* frameFormat */
    NULL /* custom */
    };

    void spi_test(UArg arg0, UArg arg1)
    {
    //SPI_Params spiParams; /* SPI params structure */
    //SPI_Handle handle; /* SPI handle */
    SPI_Transaction transaction; /* SPI transaction */
    int32_t retVal; /* return value */



    SPI_log("\n McSPI Internal Loopback test app started \n");
    SPI_log("\n The Mode of transfer is Interrupt Mode \n");
    /* Modify the default SPI configurations if necessary */

    spi_initConfig();


    /* Init SPI driver */
    SPI_init();

    /* Open MCSPI instance 1 driver */
    gSpiHandle = SPI_open(MCSPI_INSTANCE, &gSpiParams);
    if(gSpiHandle == NULL)
    {
    printf("\nError opening MCSPI driver\n");
    }

    McSPIInitializeBuffers();



    transaction.count = McSPI_DATA_COUNT;
    transaction.txBuf = gTxBuffer;
    transaction.rxBuf = gRxBuffer;
    SPI_transfer(gSpiHandle, &transaction);

    McSPIBuffervalue();
    retVal = McSPIVerifyData();

    if(retVal != 0)
    {
    SPI_log("\n McSPI Data Transmission is Failed \n");

    }
    else
    {
    SPI_log("\n McSPI Data Transmission is successful \n");
    }

    SPI_close(gSpiHandle);



    while(1);
    }

    also have board_init() in main() function
    just
    Board_moduleClockInit();//init the spi clk
    Board_pinmuxConfig();//mcspi0 mcspi1 pinmux it's right pin address
    Board_uartStdioInit();//init uart

    please tell me what should i check to in the project
    i have readed the spi_v1.c and spi_soc.c to check the register . it's all right when i debug .
  • Edison,
    Will need some time to look into this and get back to you.

    Lali
  • i ask this question twice but noboby help me.....
  • Edison,

    What specifically are the errors you are seeing? Do you have some debug data?
    Are you able to put a logic analyzer on the pins to see the behavior?
    What happens at McSPIVerifyData?

    Lali
  • I check the SPI_v0.c and i found that the spi use like that
    static NOR_STATUS Nor_spiCmdRead(SPI_Handle handle,
    uint8_t *cmdBuf,
    uint32_t cmdLen,
    uint8_t *rxBuf,
    uint32_t rxLen)
    {
    SPI_Transaction transaction; /* SPI transaction structure */
    uint32_t xferEnable;
    uint32_t terminateXfer = 0;
    bool retVal;

    /* Enable transfer */
    xferEnable = 1;
    SPI_control(handle, SPI_V0_CMD_XFER_ACTIVATE, (void *)&xferEnable);

    /* If no read data, release CS at the end of write */
    if (rxLen == 0)
    {
    terminateXfer = 1;
    }

    /* Write Command */
    transaction.txBuf = cmdBuf;
    transaction.rxBuf = NULL;
    transaction.count = cmdLen;
    transaction.arg = (void *)&terminateXfer;

    retVal = SPI_transfer(handle, &transaction);
    ....
    }

    first enable the CS or loopback mode or other

    the function code in SPI_V0 is
    static int32_t SPI_control_v0(SPI_Handle handle, uint32_t cmd, const void *arg)
    {
    SPI_v0_HWAttrs const *hwAttrs = NULL;
    uint32_t *cmd_args = (uint32_t *)arg;
    int32_t retVal = SPI_STATUS_SUCCESS;

    /* Input parameter validation */
    OSAL_Assert(handle == NULL);

    /* Get the pointer to the object and hwAttrs */
    hwAttrs = handle->hwAttrs;

    switch (cmd)
    {
    case SPI_V0_CMD_XFER_ACTIVATE:
    if (cmd_args[0])
    {
    SPIXferEnable(hwAttrs->baseAddr);
    }
    else
    {
    SPIXferDisable(hwAttrs->baseAddr);
    }
    break;

    case SPI_V0_CMD_LOOPBACK:
    if (cmd_args[0])
    {
    SPILoopbackEnable(hwAttrs->baseAddr);
    }
    else
    {
    SPILoopbackDisable(hwAttrs->baseAddr);
    }
    break;

    case SPI_V0_CMD_PWRDOWN:
    if (cmd_args[0])
    {
    SPIPwrDownEnable(hwAttrs->baseAddr);
    }
    else
    {
    SPIPwrDownDisable(hwAttrs->baseAddr);
    }
    break;

    case SPI_V0_CMD_DELAY:
    SPIDelaySetup(hwAttrs->baseAddr, cmd_args[0], cmd_args[1]);
    break;

    case SPI_V0_CMD_SHIFT_DIR:
    SPISetShiftDir(hwAttrs->baseAddr, cmd_args[0]);
    break;

    default:
    retVal = SPI_STATUS_UNDEFINEDCMD;
    break;
    }
    return retVal;
    }


    but am335x use SPI_v1
    static int32_t SPI_control_v1(SPI_Handle handle, uint32_t cmd, const void *arg)
    {
    /* Input parameter validation */
    OSAL_Assert(handle == NULL);

    return SPI_STATUS_UNDEFINEDCMD;
    }
    it do nothing it just set the transaction structure and start to transfer data through spi


    spi v0 and spi V1 have different register operation. in order to transfer data what should i do
    it recieve all 0