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.

Linux/PROCESSOR-SDK-AM335X: Interface testing

Part Number: PROCESSOR-SDK-AM335X

Tool/software: Linux

We've a custom board based on AM335x-EVM-SK. We are using ti-processor-sdk-linux-am335x-evm-05.00.00.15.

We tested the following 3 interfaces to prove its working to our customer. They're specifically asking about EDMA interface test along with its throughput.

1. I2C tested with external IC.

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>

static uint8_t mode;
static uint8_t bits = 8;
static uint32_t speed = 500000;
static uint16_t delay;
const char *device = "/dev/spidev0.0";
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
char buf[10];
char buf2[10];
int com_serial;
int failcount;
struct spi_ioc_transfer xfer[2];
struct spi_ioc_transfer xfer1[2];

void spi_write(int file)
{
    unsigned char   buf[32];
    int status;
    memset(buf, 0, sizeof buf);
    buf[0] = 0x06;
    xfer1[0].tx_buf = (unsigned long)buf;
    xfer1[0].len = 1; /* Length of  command to write*/
    status = ioctl(file, SPI_IOC_MESSAGE(1), xfer1);
    if (status < 0)
    {
        perror("SPI_IOC_MESSAGE");
        return;
    }
    buf[0] = 0x01;
    buf[1] = 0x30;
    xfer1[0].tx_buf = (unsigned long)buf;
    xfer1[0].len = 2; /* Length of  command to write*/
    status = ioctl(file, SPI_IOC_MESSAGE(1), xfer1);
    if (status < 0)
    {
        perror("SPI_IOC_MESSAGE");
        return;
    }
    printf("env: %02x %02x\n", buf[0], buf[1]);
    //    printf("ret: %02x %02x %02x %02x\n", buf2[0], buf2[1], buf2[2], buf2[3]);

    com_serial=1;
    failcount=0;
}


char * spi_read(int file)
{
    int status;
    memset(buf, 0, sizeof buf);
    memset(buf2, 0, sizeof buf2);
    buf[0] = 0x05;//0x9E;
    //    buf[1] = 0x00;
    //    buf[2] = 0x00;
    //    buf[3] = 0x00;
    xfer[0].tx_buf = (unsigned long)buf;
    xfer[0].len = 1; /* Length of  command to write*/
    xfer[1].rx_buf = (unsigned long) buf2;
    xfer[1].len = 1; /* Length of Data to read */
    status = ioctl(file, SPI_IOC_MESSAGE(2), xfer);
    if (status < 0)
    {
        perror("SPI_IOC_MESSAGE");
        return 0;
    }
    //printf("env: %02x %02x %02x\n", buf[0], buf[1], buf[2]);
    printf("ret: %02x\n", buf2[0]);
}
int main(int argc, char *argv[])
{
    int file;

    if ((file = open(device,O_RDWR)) < 0)
    {
        printf("Failed to open the bus.");
        /* ERROR HANDLING; you can check errno to see what went wrong */
        exit(1);
    }

    printf("success to open the bus.");

    if (ioctl(file, SPI_IOC_RD_MODE, &mode) < 0)
    {
        perror("SPI rd_mode");
        return 0;
    }
    //    if (ioctl(file, SPI_IOC_RD_LSB_FIRST, &lsb) < 0)
    //    {
    //        perror("SPI rd_lsb_fist");
    //        return;
    //    }

    if (ioctl(file, SPI_IOC_WR_BITS_PER_WORD, &bits)<0)
    {
        perror("can't set bits per word");
        return 0;
    }

    if (ioctl(file, SPI_IOC_RD_BITS_PER_WORD, &bits) < 0)
    {
        perror("SPI bits_per_word");
        return 0;
    }

    if (ioctl(file, SPI_IOC_WR_MAX_SPEED_HZ, &speed)<0)
    {
        perror("can't set max speed hz");
        return 0;
    }

    if (ioctl(file, SPI_IOC_RD_MAX_SPEED_HZ, &speed) < 0)
    {
        perror("SPI max_speed_hz");
        return 0;
    }

    printf("spi mode %d, %d bits, %d Hz max\n",mode, bits, speed);
    //    transfer(file);
        spi_write(file);
//    spi_read(file);
    return 0;
}

2. SPI tested with external NOR Flash. In this code, we're reading and writing at different times. not simultaneously.

#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <stdlib.h>
#include <getopt.h>
#include <string.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/types.h>
#include <linux/spi/spidev.h>

static uint8_t mode;
static uint8_t bits = 8;
static uint32_t speed = 500000;
static uint16_t delay;
const char *device = "/dev/spidev0.0";
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
char buf[10];
char buf2[10];
int com_serial;
int failcount;
struct spi_ioc_transfer xfer[2];
struct spi_ioc_transfer xfer1[2];

void spi_write(int file)
{
    unsigned char   buf[32];
    int status;
    memset(buf, 0, sizeof buf);
    buf[0] = 0x06;
    xfer1[0].tx_buf = (unsigned long)buf;
    xfer1[0].len = 1; /* Length of  command to write*/
    status = ioctl(file, SPI_IOC_MESSAGE(1), xfer1);
    if (status < 0)
    {
        perror("SPI_IOC_MESSAGE");
        return;
    }
    buf[0] = 0x01;
    buf[1] = 0x30;
    xfer1[0].tx_buf = (unsigned long)buf;
    xfer1[0].len = 2; /* Length of  command to write*/
    status = ioctl(file, SPI_IOC_MESSAGE(1), xfer1);
    if (status < 0)
    {
        perror("SPI_IOC_MESSAGE");
        return;
    }
    printf("env: %02x %02x\n", buf[0], buf[1]);
    //    printf("ret: %02x %02x %02x %02x\n", buf2[0], buf2[1], buf2[2], buf2[3]);

    com_serial=1;
    failcount=0;
}


char * spi_read(int file)
{
    int status;
    memset(buf, 0, sizeof buf);
    memset(buf2, 0, sizeof buf2);
    buf[0] = 0x05;//0x9E;
    //    buf[1] = 0x00;
    //    buf[2] = 0x00;
    //    buf[3] = 0x00;
    xfer[0].tx_buf = (unsigned long)buf;
    xfer[0].len = 1; /* Length of  command to write*/
    xfer[1].rx_buf = (unsigned long) buf2;
    xfer[1].len = 1; /* Length of Data to read */
    status = ioctl(file, SPI_IOC_MESSAGE(2), xfer);
    if (status < 0)
    {
        perror("SPI_IOC_MESSAGE");
        return 0;
    }
    //printf("env: %02x %02x %02x\n", buf[0], buf[1], buf[2]);
    printf("ret: %02x\n", buf2[0]);
}
int main(int argc, char *argv[])
{
    int file;

    if ((file = open(device,O_RDWR)) < 0)
    {
        printf("Failed to open the bus.");
        /* ERROR HANDLING; you can check errno to see what went wrong */
        exit(1);
    }

    printf("success to open the bus.");

    if (ioctl(file, SPI_IOC_RD_MODE, &mode) < 0)
    {
        perror("SPI rd_mode");
        return 0;
    }
    //    if (ioctl(file, SPI_IOC_RD_LSB_FIRST, &lsb) < 0)
    //    {
    //        perror("SPI rd_lsb_fist");
    //        return;
    //    }

    if (ioctl(file, SPI_IOC_WR_BITS_PER_WORD, &bits)<0)
    {
        perror("can't set bits per word");
        return 0;
    }

    if (ioctl(file, SPI_IOC_RD_BITS_PER_WORD, &bits) < 0)
    {
        perror("SPI bits_per_word");
        return 0;
    }

    if (ioctl(file, SPI_IOC_WR_MAX_SPEED_HZ, &speed)<0)
    {
        perror("can't set max speed hz");
        return 0;
    }

    if (ioctl(file, SPI_IOC_RD_MAX_SPEED_HZ, &speed) < 0)
    {
        perror("SPI max_speed_hz");
        return 0;
    }

    printf("spi mode %d, %d bits, %d Hz max\n",mode, bits, speed);
    //    transfer(file);
        spi_write(file);
//    spi_read(file);
    return 0;
}

3. EDMA tested with sample application(dmatest) provided in the sdk using modprobe dmatest timeout=200 iterations=500 run=1 verbose=on.

One thing i want to know is that is this transferring data within processor's memory or between processor and FPGA?

Now, we want to test all these 3 interfaces with FPGA i.e. to send and receive data to and from FPGA.

Please suggest me changes in my codes.

Any help in this regard is appreciated as we're in a strict time restriction.

Thank You.

  • Hi Vamsi,

    Vamsi Siddhani said:

    3. EDMA tested with sample application(dmatest) provided in the sdk using modprobe dmatest timeout=200 iterations=500 run=1 verbose=on.

    One thing i want to know is that is this transferring data within processor's memory or between processor and FPGA?

    dmatest does memcpy using edma.

    Vamsi Siddhani said:
    Now, we want to test all these 3 interfaces with FPGA i.e. to send and receive data to and from FPGA.

    What is the FPGA interface to AM335x? How is it connected to I2C and SPI?

  • Please check the below image for interfaces.

  • Hi Vamsi,

    The diagram shows the FPGA is connected to the AM335x SPI1, GPMC, and I2C interfaces, so your I2C and SPI test applications should communicate to the corresponding I2C node and SPI device of the FPGA, if your test applications talk to the corresponding I2C and SPI device node.