SPI&GPIO

You have a problem with your Wandboard and want to ask the community for help.

SPI&GPIO

Postby x0rad » Thu Sep 19, 2013 7:59 am

Hello.
I don't have experience with Linux.
I plan to transfer data from MCU through SPI in master-mode.
How can i setting SPI? Where i can found information about SPI and GPIO in linux?
Thanks!
x0rad
 
Posts: 14
Joined: Thu Sep 19, 2013 7:44 am

Re: SPI&GPIO

Postby bhansen » Thu Sep 19, 2013 11:35 pm

Hi x0rad. I'm new to the Wandboard, but have created various GPIO, I2C and SPI drivers for other embedded Linux systems before.

Have you read through the Linux kernel documentation? You may find useful info in https://www.kernel.org/doc/Documentatio ... pi-summary and https://www.kernel.org/doc/Documentation/gpio.txt

My recommended course of action would then be to find out which physical pins on the Wandboard you want to use. Then figure out what they are called in the kernel source. Check that your kernel has been compiled with support for the I/O. Try wiggling the pins on the command-line (for example, if your kernel supports the sysfs interface, you should be able to toggle the pin states in /sys/class/gpio). Next, write a simple program to do the same wiggling, but from within the program instead of the command line.

Good luck!
Bjarne
bhansen
 
Posts: 1
Joined: Thu Sep 19, 2013 11:17 pm

Re: SPI&GPIO

Postby x0rad » Fri Sep 20, 2013 7:20 am

Hi!
I use Ubuntu 11.10(kernel v. 3.0.35).
To enable the SPI should I rebuild kernel?!
Where can I get the source code for my wandboard?
Or try to use Yocto-project?

In wandoard GPIO pins are called for example "GPIO4_36"
but in linux it's is numeric name "200". How do I know that name?

I have program:
Code: Select all
int gpio200_out(void)
{
    int fd;
    int ret = 0;

    fd = open("/sys/class/gpio/export", O_WRONLY);
    if (fd < 0) {
        printf("open export ");
        return -1;
    }

    write(fd, "200", 4);
    close(fd);

    int directionFd;
    directionFd=open("/sys/class/gpio/gpio200/direction", O_RDWR);
    if(directionFd<0){
      printf("Can't open direction");
      return -1;
    }
    write(directionFd, "out",4);
    close(directionFd);

    int valueFd;
    valueFd = open("/sys/class/gpio/gpio200/value", O_RDWR);
    if(valueFd<0){
      printf("can't open value");
      return -1;
    }
    write(valueFd, "1", 2);
    close(valueFd);
    return ret;
}

It's compiles and runs without errors.
I think so=)
How do I know what it is pin?
Thanks!
/-----
Yeah. This program work. GPIO200 = GPIO_4 = GPIO1_24(on JP4)
???
x0rad
 
Posts: 14
Joined: Thu Sep 19, 2013 7:44 am

Re: SPI&GPIO

Postby mki » Sat Sep 21, 2013 9:22 am

Hi,
the blog from the guys of nexus-computing probably helps a lot. There are two parts about working with GPIOs on the Wandboard.
First part (interesting for you) is complete linux program, second part is integration to Android which you don't need. http://android.serverbox.ch/
In the kernel files for IMX6 you find e.g. arch/arm/mach-mx6/board-wand.c. In that file you find how the GPIOs are initialized.
Hope this helps pushing forward.

BR
Markus
mki
 
Posts: 20
Joined: Mon Sep 02, 2013 9:11 am

Re: SPI&GPIO

Postby x0rad » Mon Sep 23, 2013 5:58 pm

Hi.
Tell me, what changes should I make to board_wand.c to gain access to /dev/spi from user space?
And I not understand how Linux assigns numbers to /sys/class/gpioN ?
Thanks!
x0rad
 
Posts: 14
Joined: Thu Sep 19, 2013 7:44 am

Re: SPI&GPIO

Postby Tapani » Tue Sep 24, 2013 7:33 am

Regarding GPIO numbering, imx6 gpios are usually referred to by pairs, (bank, nr), where each gpio bank has 32 gpios.
Kernel exports them as one number, N = (bank-1)*32 + nr

So your example GPIO4_36 does not exist, but GPIO7_8 would equal gpio200 (since (7-1)*32 + 8 = 200)

About /dev/spi, have you tried enabling SPIDEV in kernel config?
Tapani
 
Posts: 712
Joined: Tue Aug 27, 2013 8:32 am

Re: SPI&GPIO

Postby x0rad » Tue Sep 24, 2013 1:17 pm

Thanks!
Yes. I enabled "CONFIG_SPI_SPIDEV=y".
(In wandboard_ubuntu_defconfig & wandboard_defconfig)
In board_wand.c added:
Code: Select all
static struct spi_board_info wbquad_spi_devices[] = {
    {
        .modalias = "spidev",
        .max_speed_hz = 2500000,
        .bus_num = 0,
        .chip_select = 0,
        .mode = SPI_MODE_0,
    },
    {
        .modalias = "spidev",
        .max_speed_hz = 2500000,
        .bus_num = 0,
        .chip_select = 1,
        .mode = SPI_MODE_0,
    }
};

...
Code: Select all
static void __init wand_init_spi(void) {
   WAND_SETUP_PADS(wand_spi_pads);
       
   imx6q_add_ecspi(0, &wand_spi1_data);
   imx6q_add_ecspi(1, &wand_spi2_data);
        spi_register_board_info(wbquad_spi_devices, ARRAY_SIZE(wbquad_spi_devices));
}


I builded it, but can't find "spi" in /dev.
What am I doing wrong?
//----------------------------------
Ok. It is magic.
I get /dev/spidev0.0 and it work!
Last question...
But why only one?
x0rad
 
Posts: 14
Joined: Thu Sep 19, 2013 7:44 am

Re: SPI&GPIO

Postby nma » Wed Oct 09, 2013 8:04 am

x0rad wrote:Thanks!
Yes. I enabled "CONFIG_SPI_SPIDEV=y".
(In wandboard_ubuntu_defconfig & wandboard_defconfig)
In board_wand.c added:
Code: Select all
static struct spi_board_info wbquad_spi_devices[] = {
    {
        .modalias = "spidev",
        .max_speed_hz = 2500000,
        .bus_num = 0,
        .chip_select = 0,
        .mode = SPI_MODE_0,
    },
    {
        .modalias = "spidev",
        .max_speed_hz = 2500000,
        .bus_num = 0,
        .chip_select = 1,
        .mode = SPI_MODE_0,
    }
};

...
Code: Select all
static void __init wand_init_spi(void) {
   WAND_SETUP_PADS(wand_spi_pads);
       
   imx6q_add_ecspi(0, &wand_spi1_data);
   imx6q_add_ecspi(1, &wand_spi2_data);
        spi_register_board_info(wbquad_spi_devices, ARRAY_SIZE(wbquad_spi_devices));
}


I builded it, but can't find "spi" in /dev.
What am I doing wrong?
//----------------------------------
Ok. It is magic.
I get /dev/spidev0.0 and it work!
Last question...
But why only one?


You should change bus number for second bus to register to spidev. So in second struct .bus_num =1.
Then you will have two devices spidev0.0 and spidev1.1
nma
 
Posts: 1
Joined: Wed Oct 09, 2013 7:58 am

Re: SPI&GPIO

Postby Tapani » Wed Oct 09, 2013 8:18 am

While not related to the latest posts, this is related to this thread and others with GPIO issues might look in this thread before posting.

I wrote a short summary of the Wandboard External GPIOs in the wandboard wiki: http://wiki.wandboard.org/index.php/External_gpios
Admittedly, they are a little messy to deal with, so I hope that the table there might clarify things. Or at least function as a reference.
Tapani
 
Posts: 712
Joined: Tue Aug 27, 2013 8:32 am

Re: SPI&GPIO

Postby x0rad » Thu Oct 10, 2013 6:43 am

Great work, thanks!
I was also interested in some questions.
1. For example, if I disable a i2c, is it possible to reassign the it pin as eGPIO?
2. This question is more to Linux. Is it possible to configure the external interrupt on GPIO?
x0rad
 
Posts: 14
Joined: Thu Sep 19, 2013 7:44 am

Next

Return to Getting started

Who is online

Users browsing this forum: Baidu [Spider] and 5 guests

cron