2010-10-14 07:14:32     BF537 SPI driver problem

Document created by Aaronwu Employee on Aug 23, 2013
Version 1Show Document
  • View in full screen mode

2010-10-14 07:14:32     BF537 SPI driver problem

Shyam sundar (INDIA)

Message: 94514   

 

Hello world,

 

The following is the C code I am executing from the Userspace interface!!

 

Here I am trying access SPI interface on a customised board having BF537. For SPI interface I am trying to access a slave connected to PF4.

 

I do get error displaying can't open device: No such file or directory !!

 

For accessing SPI device through PF 4,  I have added the following lines in the file uClinux-dist/linux-2.6.x/arch/blackfin/mach-bf537/boards/custom_board.c

 

#if defined(CONFIG_BFIN_SPI_CODEC)

 

static struct bfin5xx_spi_chip spi_codec_chip_info = {

    .enable_dma = 1,         /* use dma transfer with this chip*/

    .bits_per_word = 16,

};

#endif

 

#if defined(CONFIG_BFIN_SPI_CODEC)

    {

        .modalias = "spidev", /* Name of spi_driver for this device */

        .max_speed_hz = 3250000,     /* max spi clock (SCK) speed in HZ */

        .bus_num = 0, /* Framework bus number */

        .chip_select = 4, /* Framework chip select. */

        .platform_data = NULL, /* No spi_driver specific config */

        .controller_data = &spi_codec_chip_info,

    },

#endif

 

Also I have enabled BFIN_SPI_CODEC option during the menuconfig!

 

When the kernel image gets loaded I dont see spi0.4 in the /dev directory!

 

#include <stdint.h>

#include <unistd.h>

#include <stdio.h>

#include <stdlib.h>

#include <malloc.h>

#include <string.h>

#include <getopt.h>

#include <fcntl.h>

#include <sys/ioctl.h>

#include <linux/types.h>

#include <linux/spi/spidev.h>

#include <sys/types.h>

 

 

#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))

#define BUF_LEN        0x1000

 

 

int config_codec(void);

 

int wrCnt,rdCnt;

 

struct sport_config sconfig;

unsigned char *message_buffer = NULL;

char *filename;

 

static void pabort(const char *s)

{

    perror(s);

    abort();

}

 

static const char *device = "/dev/spidev0.4";

static uint8_t mode;

static uint8_t bits = 16;

static uint32_t speed = 500000;

static uint16_t delay;

 

static void transfer_ctl_word(int fd)

{

    int ret;

    uint8_t tx[] = {

        0x88, 0x84, 0x25, 0x89,

    };

 

    uint8_t rx[ARRAY_SIZE(tx)] = {0, };

 

    struct spi_ioc_transfer tr = {

        .tx_buf = (unsigned long)tx,

        .rx_buf = (unsigned long)rx,

        .len = ARRAY_SIZE(tx),

        .delay_usecs = delay,

        .speed_hz = speed,

        .bits_per_word = bits,

    };

 

    ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr);

    if (ret == 1)

        pabort("can't send spi message");

 

    for (ret = 0; ret < ARRAY_SIZE(tx); ret++) {

        if (!(ret % 6))

            puts("");

        printf("%.2X ", rx[ret]);

    }

    puts("");

}

 

 

int main(int argc, char *argv[])

{

    int ret = 0;

    int fd;

 

        if (argc < 2) {

        fprintf (stderr, "Usage: sport_test <file_to_play> <num_of_times> \n");

        return -1;

    }      

 

    filename = argv[1];

    ret=config_codec();

}

 

 

int config_codec()

{

 

    int spi_fd;

    int ret;

 

    printf("Configuring codec through SPI......../n");

  

    spi_fd = open(device, O_RDWR);

    if (spi_fd < 0)

        pabort("can't open device");

 

    ret = ioctl(spi_fd, SPI_IOC_WR_MODE, &mode);

    if (ret == -1)

        pabort("can't set spi mode");

 

    ret = ioctl(spi_fd, SPI_IOC_RD_MODE, &mode);

    if (ret == -1)

        pabort("can't get spi mode");

 

    ret = ioctl(spi_fd, SPI_IOC_WR_BITS_PER_WORD, &bits);

    if (ret == -1)

        pabort("can't set bits per word");

 

    ret = ioctl(spi_fd, SPI_IOC_RD_BITS_PER_WORD, &bits);

    if (ret == -1)

        pabort("can't get bits per word");

 

    ret = ioctl(spi_fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed);

    if (ret == -1)

        pabort("can't set max speed hz");

 

    ret = ioctl(spi_fd, SPI_IOC_RD_MAX_SPEED_HZ, &speed);

    if (ret == -1)

        pabort("can't get max speed hz");

 

    printf("spi mode: %d\n", mode);

    printf("bits per word: %d\n", bits);

    printf("max speed: %d Hz (%d KHz)\n", speed, speed/1000);

 

    transfer_ctl_word(spi_fd);

 

    close(spi_fd);

 

    printf("Successfully configured codec through SPI !!!/n");

 

    ret=1;

 

    return ret;

 

}

 

QuoteReplyEditDelete

 

 

2010-10-14 09:45:59     Re: BF537 SPI driver problem

Shyam sundar (INDIA)

Message: 94517   

 

Oh looks like I had to define CONFIG_SPI_SPIDEV in make menuconfig routine!!!

QuoteReplyEditDelete

 

 

2010-10-18 07:06:43     Re: BF537 SPI driver problem

Shyam sundar (INDIA)

Message: 94674   

 

Hello world,

 

When I do  specify chip_select=4, while using the spidev driver,

 

Does it indicate that I am selecting PF4 or SSEL4?

QuoteReplyEditDelete

 

 

2010-10-18 10:15:10     Re: BF537 SPI driver problem

Shyam sundar (INDIA)

Message: 94675   

 

chip_select=4 means SSEL4 !!

QuoteReplyEditDelete

 

 

2010-10-18 10:16:07     Re: BF537 SPI driver problem

Shyam sundar (INDIA)

Message: 94676   

 

How is the polarity of the chip select controlled???

QuoteReplyEditDelete

 

 

2010-10-18 14:12:34     Re: BF537 SPI driver problem

Mike Frysinger (UNITED STATES)

Message: 94682   

 

we have a wiki. please search it.

 

  docs.blackfin.uclinux.org/doku.php?id=spi

Attachments

    Outcomes