SPI Set up for BeagleBone Black.

Hi, I am brand new for Beaglebone Black and trying to set up SPI. I did find some tutorials and instructions online, but none of them worked. I am not sure if it was due to the version of the image. Is there anyone can provide me some instructions on how to enable SPI on BeagleBone Black, or share me a link? The releases of image I tried was Debian 9.4 and 8.6.

Appreciate in advance!

Grab the latest:

https://beagleboard.org/latest-images

Double check:

sudo /opt/scripts/tools/version.sh

Then just set:

uboot_overlay_addr4=/lib/firmware/BB-SPIDEV1-00A0.dtbo

in /boot/uEnv.txt

Regards

Thank you! I just did. After this, do I need to type a command line of : SLOTS=/sys/devices/platforms/bone_capemgr/slots?
If so, I cannot find slots under bone_capemgr.

slots does not exist on new images

I saw many of the tutorials of older versions used echo > $SLOTS. Do I still need this step for stretch?

Slots are gone.. Use u-boot overlays:

uboot_overlay_addr4=/lib/firmware/BB-SPIDEV1-00A0.dtbo

Regards,

Hi, I am brand new for Beaglebone Black and trying to set up SPI. I did find some tutorials and instructions online, but none of them worked. I am not sure if it was due to the version of the image. Is there anyone can provide me some instructions on how to enable SPI on BeagleBone Black, or share me a link? The releases of image I tried was Debian 9.4 and 8.6.

What did you try? Which kernel? Are you trying to use SPIDEV or another SPI driver? Does the /dev/spidevX.X interface show up already for the SPI you want?

Our goal with the latest images is to:

  1. have the spidev show up by default,
  2. allow overlays to disable the spidev for a native SPI driver as needed, and
  3. use ‘config-pin’ to dynamically enable the right pinmux mode for the used pins.

Did the instructions you followed comprehend these elements of the setup and what enables them? The spidev must be enabled in the base device tree or an overlay for (1). The overlays must be applied in u-boot, not the kernel capemgr, for (2). The pinmux helpers must be enabled and named properly to match the config-pin script for (3).

If I had internet access to look up the SPI pinouts and existing instructions, I’d provide those here, but I hope this background helps.

Sorry, I am a little bit confused. Do you mean I can run SPI code after uncommenting this line in uEnv.txt?

I was trying to follow this link first: https://elinux.org/BeagleBone_Black_Enable_SPIDEV
Then I found it was too old. Then I followed a book named Exploring BeagleBone, apparently it was too old as well. Then I saw a video on youtube, he was using Debian 8.6 but still did not work. Currently I am pretty confused about what I need to set before running SPI code.

On Mon, 16 Jul 2018 19:58:51 -0700 (PDT), Jinao Gao
<gaojinao@gmail.com> declaimed the following:

I was trying to follow this link
first: https://elinux.org/BeagleBone_Black_Enable_SPIDEV
Then I found it was too old. Then I followed a book named Exploring
BeagleBone, apparently it was too old as well. Then I saw a video on
youtube, he was using Debian 8.6 but still did not work. Currently I am
pretty confused about what I need to set before running SPI code.

  First thing -- ignore ALL those old instructions.

  <SNIP>

What did you try? Which kernel? Are you trying to use SPIDEV or another
SPI driver? Does the /dev/spidevX.X interface show up already for the SPI
you want?

Our goal with the latest images is to:
1) have the spidev show up by default,
2) allow overlays to disable the spidev for a native SPI driver as needed,
and
3) use ‘config-pin’ to dynamically enable the right pinmux mode for the
used pins.

Did the instructions you followed comprehend these elements of the setup
and what enables them? The spidev must be enabled in the base device tree
or an overlay for (1). The overlays must be applied in u-boot, not the
kernel capemgr, for (2). The pinmux helpers must be enabled and named
properly to match the config-pin script for (3).

  If I understand Mr. Kridner, recent releases should have SPI device
available without doing anything...

  This is from the January LXQT image (Debian Stretch 9.3
https://debian.beagleboard.org/images/bone-debian-9.3-lxqt-armhf-2018-01-28-4gb.img.xz
) on my BBB eMMC:

debian@beaglebone:~$ uname -a
Linux beaglebone 4.9.78-ti-r94 #1 SMP PREEMPT Fri Jan 26 21:26:24 UTC 2018
armv7l GNU/Linux
debian@beaglebone:~$ ls -la /dev/sp*
crw-rw---- 1 root spi 153, 1 Jul 12 16:36 /dev/spidev1.0
crw-rw---- 1 root spi 153, 0 Jul 12 16:36 /dev/spidev1.1
crw-rw---- 1 root spi 153, 3 Jul 12 16:37 /dev/spidev2.0
crw-rw---- 1 root spi 153, 2 Jul 12 16:37 /dev/spidev2.1
debian@beaglebone:~$

debian@beaglebone:~$ sudo config-pin p9_21 spi
debian@beaglebone:~$ sudo config-pin p9_18 spi
debian@beaglebone:~$ sudo config-pin p9_17 spi
Invalid mode: spi
debian@beaglebone:~$ sudo config-pin p9_22 spi
Invalid mode: spi
debian@beaglebone:~$ sudo config-pin p9_17 spi_cs
debian@beaglebone:~$ sudo config-pin p9_22 spi_sclk
debian@beaglebone:~$

... Seems to do for spi0 (on the old pinout diagrams). But spi1 doesn't
seem to be configured.

debian@beaglebone:~$ sudo config-pin p9_30 spi
debian@beaglebone:~$ sudo config-pin p9_29 spi
P9_29 pinmux file not found!
bash: /sys/devices/platform/ocp/ocp*P9_29_pinmux/state: No such file or
directory
Cannot write pinmux file: /sys/devices/platform/ocp/ocp*P9_29_pinmux/state
debian@beaglebone:~$ sudo config-pin p9_28 spi_cs
P9_28 pinmux file not found!
bash: /sys/devices/platform/ocp/ocp*P9_28_pinmux/state: No such file or
directory
Cannot write pinmux file: /sys/devices/platform/ocp/ocp*P9_28_pinmux/state
debian@beaglebone:~$ sudo config-pin p9_31 spi_sclk
P9_31 pinmux file not found!
bash: /sys/devices/platform/ocp/ocp*P9_31_pinmux/state: No such file or
directory
Cannot write pinmux file: /sys/devices/platform/ocp/ocp*P9_31_pinmux/state
debian@beaglebone:~$

  Interesting: Following Mr. Nelson's original reply regarding activating
an overlay and rebooting resulted in only

debian@beaglebone:~$ ls -la /dev/spi*
crw-rw---- 1 root spi 153, 1 Jul 17 10:23 /dev/spidev1.0
crw-rw---- 1 root spi 153, 0 Jul 17 10:23 /dev/spidev1.1
debian@beaglebone:~$

/and/ wiped out most of the pinmux files at the same time. Took it out and
reboot shows all "four" entries. Looking at the config-pin source, the
three that failed above default assignment is "audio" which may have taken
control away from config-pin (part of HDMI?).

  How to use those is another matter -- I don't have a set up to work
with it...

Thank you Dennis! I will follow your post!

Hi Robert,

For my understanding at this point, while using the latest Debian image (stretch), if I want to use spi0, I don’t need to set
uboot_overlay_addr4=/lib/firmware/BB-SPIDEV1-00A0.dtbo, but can just type :“sudo config-pins" to set the pins. If I want to use spi1, I need to set uboot_overlay_addr4=/lib/firmware/BB-SPIDEV1-00A0.dtbo in /dev/uEnv.txt, but no need to config the pins. Is this correct?

Hi Jason,

For my understanding at this point, while using the latest Debian image (stretch), if I want to use spi0, I don’t need to set
uboot_overlay_addr4=/lib/firmware/BB-SPIDEV1-00A0.dtbo, but can just type :“sudo config-pins" to set the pins. If I want to use spi1, I need to set uboot_overlay_addr4=/lib/firmware/BB-SPIDEV1-00A0.dtbo in /dev/uEnv.txt, but no need to config the pins. Is this correct?

Correct you can use "either" method.. But in the context of your
question "enable SPI" i gave you the simple option to enable SPIDEV1..

Regards,

Thank you for your help!

Hi Robert,
I just got another question. If I’m using spi1, do I still need to disable HDMI as old versions?

If the pins you need are used by the hdmi interface, make sure to disable it:

https://elinux.org/Beagleboard:BeagleBoneBlack_Debian#U-Boot_Disable_on-board_devices

Regards,

Hi Robert,

Currently I can enable spi0 and spi1 and do some loop back with them separately. But every time I set
uboot_overlay_addr4=/lib/firmware/BB-SPIDEV1-00A0.dtbo
in uEnv.txt, the spidev1.0 and spidev1.1 interfaces will disappear. Is there a way to enable both of them at the same time?

uboot_overlay_addr4=/lib/firmware/BB-SPIDEV0-00A0.dtbo
uboot_overlay_addr5=/lib/firmware/BB-SPIDEV1-00A0.dtbo

Regards,

Hi Robert,

After I set the two lines you provided in uEnv.txt and reboot it, both of SPI interfaces worked. But after I restart the board again, all of the 4 SPI interfaces in /dev disappeared. They didn’t come back if I reboot the board. Do you have any idea about what is wrong with my board?

Best,
Jinao Gao