Beaglebone SPI

I am new to Beaglebone & not too familiar with Linux.

My application requires data to be acquired from a device on SPI & transmit it on LAN.

I am using the preloaded Angstrom OS.

I have setup the environment for development by precisely following

http://jkuhlm.bplaced.net/hellobone/

With this platform, I am able to develop application for LAN transmission.

For SPI interface I have followed

http://elinux.org/BeagleBone_Black_Enable_SPIDEV

I have to use SPI0. I am able to reach properly upto the step of compiling & running the spidev_test code. Following are my questions

  1. Does the preloaded Angstrom has SPI device built in the kernel or should the kernel be rebuilt by including the spidev.c?

  2. Will the gcc libraries compile the SPIdev_test code? I am getting ‘undefined error for SPI_TX_QUAD’ and many more which I am finding defined in spi.h which is not in gcc include. Can I simply copy spi.h file into the include directory and compile?

  3. With reference to the below segment in the .dts file, sclk is mentioned as input. However, I would like BBB to be master to generate clock for the external device. In such case, should the change the value to 0x10?

4.  fragment@0 {
5.          target = <&am33xx_pinmux>;
6.          __overlay__ {
7.              spi0_pins_s0: spi0_pins_s0 {
8.                  pinctrl-single,pins = <
9.                    0x150 0x30  /* spi0_sclk, INPUT_PULLUP | MODE0 */
10.                    0x154 0x30  /* spi0_d0, INPUT_PULLUP | MODE0 */
11.                    0x158 0x10  /* spi0_d1, OUTPUT_PULLUP | MODE0 */
12.                    0x15c 0x10  /* spi0_cs0, OUTPUT_PULLUP | MODE0 */
13.                  >;
14.              };
15.          };
16.      };
  1. The pin mapping file shows that the SPI pins are mapped to 84,…… How to verify that it has been correctly mapped to the processor pin number.

equest help for these trivial questions.

Thanks

As far as the spec, only spi3 and spi4 are exposed.
Neverthless try the below link.

http://www.brianhensley.net/2012/02/spi-working-on-beagleboard-xm-rev-c.html

or

http://linuxdeveloper.blogspot.sg/2011/10/enabling-spi-on-beagleboard-xm.html

I am new to Beaglebone & not too familiar with Linux.

My application requires data to be acquired from a device on SPI &
transmit it on LAN.

I am using the preloaded Angstrom OS.

I have setup the environment for development by precisely following

HelloBone - HelloBone

With this platform, I am able to develop application for LAN transmission.

For SPI interface I have followed

BeagleBone Black Enable SPIDEV - eLinux.org

I have to use SPI0. I am able to reach properly upto the step of
compiling & running the spidev_test code. Following are my questions

1. Does the preloaded Angstrom has SPI device built in the
    kernel or should the kernel be rebuilt by including the spidev.c?

Yes, SPI is included in the Angstrom kernel.

2. Will the gcc libraries compile the SPIdev_test code? I
    am getting ‘undefined error for SPI_TX_QUAD’ and many more which I
    am finding defined in spi.h which is not in gcc include. Can I
    simply copy spi.h file into the include directory and compile?

Where did you get spidev.c from? You must use the same source as the
kernel; if you use a newer source it may not compile with the older
version of the kernel you are using.

3. With reference to the below segment in the .dts file,
    sclk is mentioned as input. However, I would like BBB to be master
    to generate clock for the external device. In such case, should the
    change the value to 0x10?

No, this a "quirk" with the spi driver, the clock is set as INPUT but it
will also OUTPUT on the pin.

4. fragment@0 {

5. target = <&am33xx_pinmux>;

6. __overlay__ {

7. spi0_pins_s0: spi0_pins_s0 {

8. pinctrl-single,pins = <

9. 0x150 0x30 /* spi0_sclk, INPUT_PULLUP | MODE0 */

10. 0x154 0x30 /* spi0_d0, INPUT_PULLUP | MODE0 */

11. 0x158 0x10 /* spi0_d1, OUTPUT_PULLUP | MODE0 */

12. 0x15c 0x10 /* spi0_cs0, OUTPUT_PULLUP | MODE0 */

13. >;

14. };

15. };

16. };

4. The pin mapping file shows that the SPI pins are mapped to 84,…..
How to verify that it has been correctly mapped to the processor pin number.

This data can be found in the am335x TRM; you have to find the pinctrl
register in the TRM and then match the offset 0x150 to the table and
double check that it is SPI.

It's not a quirk of the driver, that you have to set SPI_CLK as an input even when the Sitara is master: It's the hardware. The SPI puts the SPI_CLK out for its MOSI data, but it needs the SPI_CLK to clock in its MISO data from the slave. The bit that you are calling "input" does not make the pin input: It activates the rx hardware. It can still be driven as an output with the RX_ACTIVE bit turned on. You need to do that even when you run the SPI hardware directly without the Linux driver.

Getting the SPI Master running is very easy. You do need to get the pinmux set so the right pins are available. Then:

#include <linux/spi/spidev.h>

// open it:
     fd = open(device, O_RDWR);
     if (fd < 0)
         pabort("can't open SPI device");

//Set up the mode, speed, bits/word, etc. using ioctl calls:
     // spi mode
     ret = ioctl(fd, SPI_IOC_WR_MODE, &mode);
     if (ret == -1)
         pabort("can't set spi mode");

Then you can use a struct spi_ioc_transfer and ioctl() calls to do reads or write.