A little side story in the project to control a stepper motor with the BeagleBone PRU.
How to enable SPI.
The 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.
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 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.