element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
BeagleBoard
  • Products
  • Dev Tools
  • Single-Board Computers
  • BeagleBoard
  • More
  • Cancel
BeagleBoard
Blog BeagleBone: Enable SPI with Overlay and from Command Line
  • Blog
  • Forum
  • Documents
  • Quiz
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join BeagleBoard to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 28 Jul 2019 1:05 PM Date Created
  • Views 11839 views
  • Likes 6 likes
  • Comments 5 comments
  • overlay
  • bb
  • spi
Related
Recommended

BeagleBone: Enable SPI with Overlay and from Command Line

Jan Cumps
Jan Cumps
28 Jul 2019

A little side story in the project to control a stepper motor with the BeagleBone PRU.

How to enable SPI.

 

The  DRV8711 stepper motor controllerDRV8711 stepper motor controller that I use is configured with SPI commands.

On a Raspberri Pi, activating SPI is done via the configuration tool. Easy.

On the BB, it's more complex. It depends on the Linux flavour (and changing in the future, I've read - it's a bit tricky to find good documentation that's applicable for the current ).

I got success using these two methods for the current Debian 4-14 (4.14.108-ti-r104).

 

Enable SPI from Command Line

 

The BB has a MUX command line tool called config-pin. I used it in a previous blog to set the PRU output pins.

 

You can use the same command to assign the SPI#0 pins to their SPI functions.

 

config-pin P9_17 spi_cs
config-pin P9_18 spi
config-pin P9_21 spi
config-pin P9_22 spi_sclk

 

When you execute SPI commands, the 4 pins will be driven and read. By default they are assigned as GPIO and then they don't react on any SPI activity.

To reset them back to their default behaviour, execute these commands:

 

config-pin P9_17 default
config-pin P9_18 default
config-pin P9_21 default
config-pin P9_22 default

.

 

Enable SPI permanently via Overlay

 

There's a number of tutorials out there on how to do this. Not all use the same method and it (seems to be) dependent on the OS version at the time of writing.

What worked for me is this simple method:

 

edit the uEnv.txt file in the /boot directory as root:

 

sudo nano /boot/uEnv.txt

 

Then use one of the free slots to register the SPI0 overlay that's part of the distro:

 

###Additional custom capes
# 20190727 jc: enable SPI0 by default
uboot_overlay_addr4=/lib/firmware/BB-SPIDEV0-00A0.dtbo

 

Reboot the BB, and the pins are permanently in SPI mode.

 

sudo reboot

 

I used the test program spidev-test to check it, and it works.

You need to bridge the MISO and MOSI pins (P9_18 and P9_21) to test this program.

 

debian@beaglebone:~/bin$ ./spidev_test
spi mode: 0
bits per word: 8
max speed: 500000 Hz (500 KHz)

FF FF FF FF FF FF
40 00 00 00 00 95
FF FF FF FF FF FF
FF FF FF FF FF FF
FF FF FF FF FF FF
DE AD BE EF BA AD
F0 0D

 

The utility send a set of data via SPI MOSI and shows what is detected on MISO. Because they are bridged, the output equals the input.

image

image the spidev-test program in action

 

The cope capture below shows part of the communication.

The 4th channel, MISO, shows nothing because I had not bridged the input to output for this capture.

If I would have done that, you'd see a trace identical to channel 3.

The decoder would then show the identical data for MISO as it does for MOSI.

image

 

 

Related blog:
BeagleBone Control Stepper Motors with PRU - Part 1: Intentions
BeagleBone Control Stepper Motors with PRU - Part 2: Test Driving Outputs
BeagleBone: Enable SPI with Overlay and from Command Line
BeagleBone Control Stepper Motors with PRU - Part 3: Hardware Provisioning and Wiring
BeagleBone Control Stepper Motors with PRU - Part 4: SPI Setup
BeagleBone Control Stepper Motors with PRU - Part 5: It Works
  • Sign in to reply

Top Comments

  • Jan Cumps
    Jan Cumps over 6 years ago in reply to shabaz +3
    The PI peoples managed to abstract part of it with the configuration program. However they implemented the multiplexing in the background, for the user it is as simple as opening the utility and enabling…
  • shabaz
    shabaz over 6 years ago in reply to Jan Cumps +3
    Hi Jan, The Pi enablement of SPI/I2C is super-straightforward, I agree. It's such a shame the BBB makes it harder than it needs to be. Pi is miles ahead in ease of use for beginners for GPIO generally…
  • Jan Cumps
    Jan Cumps over 6 years ago +3
    Documentation for @self: jkridner 's recent blog on overlays: https://beagleboard.org/blog/2018-01-17-building-a-device-tree-overlay-for-your-new-pocketcape-design
  • clem57
    clem57 over 6 years ago in reply to shabaz

    shabaz I think might be because the BBB folks expect us to be programmers rather than typical end users. The Pi folks think the other way around.image

     

    Clem

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 6 years ago

    Documentation for @self: jkridner's recent blog on overlays: https://beagleboard.org/blog/2018-01-17-building-a-device-tree-overlay-for-your-new-pocketcape-design

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 6 years ago in reply to Jan Cumps

    Hi Jan,

     

    The Pi enablement of SPI/I2C is super-straightforward, I agree. It's such a shame the BBB makes it harder than it needs to be. Pi is miles ahead in ease of use for beginners for GPIO generally, although it has its own issues and other bits of silliness though. Still, even other giant tech companies show incompetence occasionally..

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 6 years ago in reply to shabaz

    The PI peoples managed to abstract part of it with the configuration program.

    However they implemented the multiplexing in the background, for the user it is as simple as opening the utility and enabling SPI.

     

    It's great that things evolve, but the overlay management in BB

    (with the automated overlay control via an on-cape EEPROM that wasn't implemented half of the time, even missing on some capes designed by the BB team themselves, and that seems to not have settled yet)

    is something that makes adapting to the BB an order of magnitude more difficult.

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 6 years ago

    Hi Jan,

     

    Excellent work documenting all these features.

    depends on the Linux flavour (and changing in the future

    Sometimes I think it's deliberate intent to make things as difficult as possible, to not do things right the first time, and then break things in future.

    (Not just BBB, Pi has all sorts of these things too).

    The ugly .dtbo file names should have been resolved years ago too, with (say) symbolic links.. no reason for them to still have that -00A0 in the file name!

     

    It's great you're documenting all this, since I trust this over all the older BBB blog posts, most of which have issues now due to changes.

    • Cancel
    • Vote Up +2 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube