Enable SPI 1.0 and 1.1 with device tre overlays on BeagleBone
2014-04-13 15:30
731 查看
For most people the above image means absolutely nothing, but for that one guy that has been searching for two days straight with no luck and finally arrives here, he has never ever seen anything more beautiful. To that guy: Dude, you are in safe hands. I’ll guide you through it : )
With Linux Kernel 3.8.x, the use of device tree overlays are used for enabling and configuring drivers. This post gives an example of how to enable Both the channels of SPI1 on a BeagleBone. Note that a kernel should be compatible with both an Angstrom file system or any other suitable file system like Debian, although this one has been developed with Ubuntu 12.04.
To get some background info on this topic have a look at Enable PWM on BeagleBone with DT overlays and Adding BeagleBone cape support to a kernel with Device Tree in Ubuntu.
Mux the pins
In the first fragment, the pins must be muxed. Note that at the time of this writing, only the mode (the first three bits) and not the mux is working so the configuration must be done by the driver. The SPI driver fixes this.
bone_replicape_spi1_pins: pinmux_replicape_spi1_pins { pinctrl-single,pins = < 0x190 0x13 /* P9_31 = mcasp0_aclkx.spi1_sclk , OUTPUT_PULLUP | MODE3 */ 0x194 0x33 /* P9_29 = mcasp0_fsx.spi1_d0 , INPUT_PULLUP | MODE3 */ 0x198 0x13 /* P9_30 = mcasp0_axr0.spi1_d1 , OUTPUT_PULLUP | MODE3 */ 0x19c 0x13 /* P9_28 = mcasp0_ahclkr.spi1_cs0 , OUTPUT_PULLUP | MODE3 */ 0x164 0x12 /* P9_42 = GPIO0_7 = eCAP0_in_PWM0_out.gpio0[7] , OUTPUT_PULLUP | MODE2 */ >; };
Enable the driver
To enable the driver, you must override the status of the spi1 or spi2 (or both) targets.
fragment@1 { target = <&spi1>; __overlay__ { #address-cells = <1>; #size-cells = <0>; status = "okay"; pinctrl-names = "default"; pinctrl-0 = <&bone_replicape_spi1_pins>; cs-gpios = <&gpio4 17 0>, <&gpio1 7 0>; stepper_control{ #address-cells = <1>; #size-cells = <0>; compatible = "spidev"; reg = <0>; spi-max-frequency = <16000000>; spi-cpha; // Stepper control has mode 1 (CPOL = 0, CPHA = 1) }; stepper_current{ #address-cells = <1>; #size-cells = <0>; compatible = "spidev"; reg = <1>; spi-max-frequency = <16000000>; // Stepper current has mode 0 (CPOL = 0, CPHA = 0) }; }; };
Status mus be “okay” here to override the default “disabled” in am33xxdtsi.
There are also a couple of more things to consider.
Pincontrol-names – “The list of names to assign states” from the documentation.
pincontrol-pins refrences the cell in the pinmux fragment.
cs-gpios – This refers to the pins used for Chip Selects. Since there are two channels,
(SPI1.0 and SPI1.1) activated, these must be defined. The arguments in the brackets refer to
GPIO bank, but there is a gotcha: If the pin is called GPIO3_17 in the datasheet, it becomes
<&GPIO4 17 ?> in the device tree, so one higher for the bank nr. The last number is the flags to send to the GPIO controller.
Output is 0, input is 1.
Look in the kernel documentation on GPIO for more info:
https://www.kernel.org/doc/Documentation/gpio.txt
Enable the SPIDEV
The next two nodes are the two next SPI channels. Call them whatever. To use the spidev user interface (the one that makes /dev/spi1.* show up), specify compatible = “spidev”.
If you have an SPI display or similar, there are drivers for that as well. Look in the folder
KERNEL/fimrware/capes/
and look at the cape overlay for Koen Kooi’s HEXY robot, it has an SPI display from Adafruit:
http://www.youtube.com/watch?v=iH5OPj-Yybc (Getting a very good framerate on an SPI display, I might add..)
The variable “reg” refers to which Chip Select to use.
Max frequency is just that, guess.
There are also options for CPHA, CPOL,
Acronyms
McSPI – Multi channel Serial Peripheral Interface
CS – chip select
Files involved
McSPI – KERNEL/drivers/spi/spi-omap2-mcspi.c
spidev – KERNEL/drivers/spi/spidev.c
spi – KERNEL/drivers/spi/spi.c
相关文章推荐
- How to debug SceneLib with Eclipse and How to install SceneLib 1.0 on Ubuntu 10.04
- Howto Enable and Use A2DP Sink on Ubuntu Linux with Bluez
- OOM when allocating tensor with shape[96,3,299,299] and type float on /job:localhost/replica:0/task:0/device:GPU:0
- Enable JMX on tomcat and debug with eclipse(linux)
- Notes On <Agile Web Application Development with Yii 1.1 and PHP5> - 01
- Enable 360-wifi2 on BeagleBone Black
- Running OpenBTS with the Nuand bladeRF on Ubuntu (The Definitive and Step by Step Guide)
- 获取MySQL加密密码并验证用户输入(登录界面),retrieve hashpwd from mysql and compare with input password on login
- Automated GUI Testing on MeeGo and QML with Squish
- Create Snazzy Web Charts and Graphics On the Fly with the .NET Framework
- Choose a destination with a supported architecture in order to run on this device
- iPhone SDK 3/4 App will not run on a iPhone 2.x device even with deployment target set to 2.0!
- Safe! Repel Attacks on Your Code with the Visual Studio 2005 Safe C and C++ Libraries
- Summary on Structured Data and their algorithms with OOL perspective
- How To Write, Deploy, and Interact with Ethereum Smart Contracts on a Private Blockchain
- Testing C-State Settings and Performance with the Oracle Database on Linux
- hands on machine learning with sklearn and tensorflow 附录B 翻译与整理(1)概要
- Choose a destination with a supported architecture in order to run on this device.
- Enable Theme and Plugin Editor on WordPress MU
- HTTP Live Streaming with a Webcam on Linux using VLC and a Segmenter