SPI Set up for BeagleBone Black.

2,107 views
Skip to first unread message

Jinao Gao

unread,
Jul 16, 2018, 4:03:30 PM7/16/18
to BeagleBoard
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!

Robert Nelson

unread,
Jul 16, 2018, 4:27:26 PM7/16/18
to Beagle Board, gaoj...@gmail.com
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

--
Robert Nelson
https://rcn-ee.com/

Jinao Gao

unread,
Jul 16, 2018, 4:54:46 PM7/16/18
to BeagleBoard
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.

evilwulfie

unread,
Jul 16, 2018, 5:14:33 PM7/16/18
to beagl...@googlegroups.com
slots does not exist on new images
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/e668b51f-fd46-4041-aed5-fb64fbc56192%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jinao Gao

unread,
Jul 16, 2018, 5:17:56 PM7/16/18
to BeagleBoard
I saw many of the tutorials of older versions used echo > $SLOTS. Do I still need this step for stretch?

Robert Nelson

unread,
Jul 16, 2018, 5:34:27 PM7/16/18
to Beagle Board
On Mon, Jul 16, 2018 at 3:54 PM, Jinao Gao <gaoj...@gmail.com> wrote:
> 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 are gone.. Use u-boot overlays:

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

Regards,

Jason Kridner

unread,
Jul 16, 2018, 7:22:41 PM7/16/18
to beagl...@googlegroups.com


On Jul 16, 2018, at 3:03 PM, Jinao Gao <gaoj...@gmail.com> wrote:

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. 


Appreciate in advance!

--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.

Jinao Gao

unread,
Jul 16, 2018, 10:54:35 PM7/16/18
to BeagleBoard
Sorry, I am a little bit confused. Do you mean I can run SPI code after uncommenting this line in uEnv.txt?

Jinao Gao

unread,
Jul 16, 2018, 10:58:51 PM7/16/18
to BeagleBoard
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.

Dennis Lee Bieber

unread,
Jul 17, 2018, 10:45:50 AM7/17/18
to beagl...@googlegroups.com
On Mon, 16 Jul 2018 19:58:51 -0700 (PDT), Jinao Gao
<gaoj...@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.


>On Monday, July 16, 2018 at 7:22:41 PM UTC-4, Jason Kridner wrote:

<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...



--
Wulfraed Dennis Lee Bieber AF6VN
wlf...@ix.netcom.com HTTP://wlfraed.home.netcom.com/

Jinao Gao

unread,
Jul 17, 2018, 12:20:30 PM7/17/18
to BeagleBoard
Thank you Dennis! I will follow your post!

Jinao Gao

unread,
Jul 17, 2018, 1:03:22 PM7/17/18
to BeagleBoard
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?

On Monday, July 16, 2018 at 5:34:27 PM UTC-4, RobertCNelson wrote:

Jinao Gao

unread,
Jul 17, 2018, 1:03:41 PM7/17/18
to BeagleBoard
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?

On Monday, July 16, 2018 at 7:22:41 PM UTC-4, Jason Kridner wrote:

Robert Nelson

unread,
Jul 17, 2018, 1:21:39 PM7/17/18
to Beagle Board
On Tue, Jul 17, 2018 at 12:03 PM, Jinao Gao <gaoj...@gmail.com> wrote:
> 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?

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

Jinao Gao

unread,
Jul 17, 2018, 1:24:12 PM7/17/18
to BeagleBoard
Thank you for your help!

Jinao Gao

unread,
Jul 17, 2018, 2:05:43 PM7/17/18
to BeagleBoard
Hi Robert, 
I just got another question. If I'm using spi1, do I still need to disable HDMI as old versions?

On Tuesday, July 17, 2018 at 1:21:39 PM UTC-4, RobertCNelson wrote:

Robert Nelson

unread,
Jul 17, 2018, 2:13:16 PM7/17/18
to Beagle Board
On Tue, Jul 17, 2018 at 1:05 PM, Jinao Gao <gaoj...@gmail.com> wrote:
> 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

Jinao Gao

unread,
Jul 18, 2018, 2:01:22 PM7/18/18
to BeagleBoard
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?

Robert Nelson

unread,
Jul 18, 2018, 2:13:13 PM7/18/18
to Beagle Board
On Wed, Jul 18, 2018 at 1:01 PM, Jinao Gao <gaoj...@gmail.com> wrote:
> 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

Jinao Gao

unread,
Jul 18, 2018, 4:06:26 PM7/18/18
to BeagleBoard
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

Robert Nelson

unread,
Jul 18, 2018, 6:02:52 PM7/18/18
to Beagle Board
On Wed, Jul 18, 2018 at 3:06 PM, Jinao Gao <gaoj...@gmail.com> wrote:
> 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?

This will give us some clues:

sudo /opt/scripts/tools/version.sh

Jinao Gao

unread,
Jul 18, 2018, 6:19:25 PM7/18/18
to BeagleBoard
I got this:

root@beaglebone:~# sudo /opt/scripts/tools/version.sh
git:/opt/scripts/:[31292bce1d4b35b497cc7a013d6d57e7e1f4f5c4]
eeprom:[A335BNLT00C03917BBBK1D19]
model:[TI_AM335x_BeagleBone_Black]
dogtag:[BeagleBoard.org Debian Image 2018-06-17]
bootloader:[microSD-(push-button)]:[/dev/mmcblk0]:[U-Boot 2018.03-00002-gac9cce7c6a]:[location: dd MBR]
bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot 2016.01-00001-g4eb802e]:[location: dd MBR]
kernel:[4.14.49-ti-r54]
nodejs:[v6.14.3]
uboot_overlay_options:[enable_uboot_overlays=1]
uboot_overlay_options:[uboot_overlay_addr4=/lib/firmware/BB-SPIDEV0-00A0.dtbo]
uboot_overlay_options:[uboot_overlay_addr5=/lib/firmware/BB-SPIDEV1-00A0.dtbo]
uboot_overlay_options:[uboot_overlay_pru=/lib/firmware/AM335X-PRU-RPROC-4-14-TI-00A0.dtbo]
uboot_overlay_options:[enable_uboot_cape_universal=1]
pkg check: to individually upgrade run: [sudo apt install --only-upgrade <pkg>]
pkg:[bb-cape-overlays]:[4.4.20180611.0-0rcnee0~stretch+20180611]
pkg:[bb-wl18xx-firmware]:[1.20180517-0rcnee0~stretch+20180517]
pkg:[kmod]:[23-2rcnee1~stretch+20171005]
pkg:[roboticscape]:[0.4.4-git20180608.0-0rcnee0~stretch+20180609]
pkg:[firmware-ti-connectivity]:[20170823-1rcnee1~stretch+20180328]
groups:[debian : debian adm kmem dialout cdrom floppy audio dip video plugdev users systemd-journal i2c bluetooth netdev cloud9ide gpio pwm eqep admin spi tisdk weston-launch xenomai]
cmdline:[console=ttyO0,115200n8 root=/dev/mmcblk0p1 ro rootfstype=ext4 rootwait coherent_pool=1M net.ifnames=0 quiet]
dmesg | grep pinctrl-single
[    1.033991] pinctrl-single 44e10800.pinmux: 142 pins at pa f9e10800 size 568
dmesg | grep gpio-of-helper
[    1.035166] gpio-of-helper ocp:cape-universal: ready
END

Robert Nelson

unread,
Jul 18, 2018, 8:43:32 PM7/18/18
to Beagle Board, Jinao Gao
On Wed, Jul 18, 2018 at 5:19 PM, Jinao Gao <gaoj...@gmail.com> wrote:
> I got this:
>
> root@beaglebone:~# sudo /opt/scripts/tools/version.sh
> git:/opt/scripts/:[31292bce1d4b35b497cc7a013d6d57e7e1f4f5c4]
> eeprom:[A335BNLT00C03917BBBK1D19]
> model:[TI_AM335x_BeagleBone_Black]
> dogtag:[BeagleBoard.org Debian Image 2018-06-17]
> bootloader:[microSD-(push-button)]:[/dev/mmcblk0]:[U-Boot
> 2018.03-00002-gac9cce7c6a]:[location: dd MBR]
> bootloader:[eMMC-(default)]:[/dev/mmcblk1]:[U-Boot
> 2016.01-00001-g4eb802e]:[location: dd MBR]

u-boot in the eMMC is blocking overlays from working properly..

sudo dd if=/dev/zero of=/dev/mmcblk1 bs=1M count=10

and reboot..

Jinao Gao

unread,
Jul 18, 2018, 11:21:50 PM7/18/18
to BeagleBoard
Thank you for your patient explanation! It just worked!
Reply all
Reply to author
Forward
0 new messages