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.

Enabling SPI on beaglebone black

I'm getting my hands on a beaglebone black board this week.  

I've some experience with using the AM335x EVM dev kit, as far as building uboot, kernel, SD boot card, etc by following the guides here.

I've been asked to get the SPI interface working on the beaglebone black board.  For some google searches, I see some pretty straight forward pages about doing this on beaglebone via the Cape Manager.  Doing some research on that, I'm not sure that's even part of the kernel referred to in the afore-linked Sitara Linux Dev Guide from your site.

Does the linux referred to in your guides have this Cape Manager, or do I need to apply patches or start with a different kernel?

What's the best way to proceed if I start with your Sitara DEev kit (again, the afore-linked docs)?

Paul

  • Hi Paul,

    In latest TI SDK 01.00.00.03 the spi support is enabled by default in the kernel. Check /sys/class directory, you should have spi_master & spidev directories.

    You can enable spi0 on your expansion headers. So to fully enable spi0 you should add the following lines in am335x-boneblack.dts:
    1. in &am33xx_pinmux { device tree node add spi0 pinmux settings:
    spi0_pins: spi0_pins {
                pinctrl-single,pins = <
                           0x150 (PIN_OUTPUT_PULLUP | MUX_MODE0)
                           0x154 (PIN_INPUT_PULLUP | MUX_MODE0)
                           0x158 (PIN_INPUT_PULLUP | MUX_MODE0)
                           0x15C (PIN_OUTPUT_PULLUP | MUX_MODE0)
                 >;
    };

    2. Then add the &spi0 dts node:
    &spi0 {
             status = "okay";
             pinctrl-names = "default";
             pinctrl-0 = <&spi0_pins>;
            spidev@0 {
                      spi-max-frequency = <24000000>;
                      reg = <0>;
                      compatible = "linux,spidev";
            };
    };

    And recompile your device tree.:
    1. export ARCH=arm
    2. export PATH=$PATH:/home/x0155517/ti-processor-sdk-linux-am335x-evm-01.00.00.03/linux-devkit/sysroots/i686-arago-linux/usr/bin/
    3. export CROSS_COMPILE=arm-linux-gnueabihf-
    4. make am335x-boneblack.dtb/

    Then copy the newly built device tree binary on your sdcard:
    1. sudo mv devicetree-zImage-am335x-boneblack.dtb ./devicetree-zImage-am335x-boneblack.dtb.old
    2. sudo cp ~/ti-processor-sdk-linux-am335x-evm-01.00.00.03/board-support/linux-3.14.43+gitAUTOINC+875c69b2c3-g875c69b/arch/arm/boot/dts/am335x-boneblack.dtb ./devicetree-zImage-am335x-boneblack.dtb

    Now your spidev1.0 should be fully enabled. Check the /sys/class/spidev/spidev1.0 directory. Having this in your filesystem you can use the spidev_test.c api provided in Documentation/spi, as described here: elinux.org/BeagleBone_Black_Enable_SPIDEV

    Best Regards,
    Yordan

  • Ok , doing this now.  No changes needed to u-boot build?

  • Hi Paul,

    Correct, you don't need to change u-boot.

    Best Regards,
    Yordan
  • To clarify further: the CAPE manager is a custom driver of the debian beaglebone kernels. It consists of a device tree overlay mechanism that allows live-patching of the device tree, together with an autodetection mechanism that uses I²C bus 1 to scan for CAPEs and automatically load their associated device tree overlay. This allows a CAPE to work "plug & play" as long as its device tree overlay is included in the linux distribution.

    You can also force-load a CAPE and people have (ab)used that as a general way to apply device tree overlays. Since device tree overlays had obvious utility beyond just the CAPE manager, support for them has moved upstream in 4.x kernels. The source format is still the same, except the pointless properties describing your "CAPE" are no longer needed. Apparently the binary format isn't quite the same so you do need the right version of dtc, and the configuration mechanism to load them has changed.

    I personally still prefer changing the main device tree file instead of patching it at runtime using overlays: I've noticed the kernel does not always react too well to dynamic device tree changes.

  • Hello,


    I try to use SPI0 on a beagle bone black with standard Debian image (BeagleBoard.org Debian Image 2016-05-13). I use the dtbo BB-SPIDEV0. I can see /dev/spidev0.0 and open it correctly in user space application. But, there is no spi signal that leaves the board ... I check in /sys/kernel/debug/pinctrl/44*/pins and see that mode is set to 0x07, that corresponds to GPIO. I don't understand why spi level is correct but not pins. Do you have an idea for that ?


    Thanks in advance

    Best regards

    Mickael leforestier

  • This is a known bug in the device trees included with some of the debian packaged kernels. It has been fixed, please upgrade your kernel to the latest version of whatever kernel series you prefer (e.g. sudo apt-get install linux-image-4.4.24-ti-r55 )