https://elinux.org/api.php?action=feedcontributions&user=EricBloch&feedformat=atomeLinux.org - User contributions [en]2024-03-28T11:21:41ZUser contributionsMediaWiki 1.31.0https://elinux.org/index.php?title=BeagleBoard/SPI&diff=20204BeagleBoard/SPI2010-04-30T23:27:47Z<p>EricBloch: Fixed links to markmail.</p>
<hr />
<div>== Background ==<br />
<br />
''Serial Perhiperal Interface'' (also known under the names of Microwire or<br />
four-wire) is a general-purpose digital I/O interface used by many ICs<br />
including sensors, converters, audio codecs, and various types of memory. An<br />
SPI bus consists of at least three pins: a clock, a slave-input/master-output<br />
(SIMO) pin, a slave-output/master-input (SOMI) pin, and zero or more chip-select(CS) pins.<br />
<br />
The OMAP3 has four McSPI controllers, each capable of driving an SPI interface<br />
at up to 48 MHz. Each of these controllers has a finite number of chip select<br />
lines. Of these four, only SPI3 and SPI4 are brought out on the BeagleBoard.<br />
* McSPI1: 4 channels<br />
* McSPI2: 2 channels<br />
* McSPI3: 3 channels (2 CS brought out)<br />
* McSPI4: 1 channel (1 CS brought out)<br />
<br />
Below is a description of the steps necessary to use SPI on BeagleBoard. If you<br />
are particularly impatient, you can start with one of the patches found in the<br />
Kernel Patches section.<br />
<br />
== Configuring Pinmux ==<br />
These devices are fully supported by the Linux kernel's mcspi driver. That<br />
being said, one will need to make some minor modifications to the BeagleBoard's<br />
board file (arch/arm/mach-omap2/board-omap3beagle.c) in order to use them.<br />
<br />
First, the pin multiplexer needs to be configured to expose the McSPI signals.<br />
As of BeagleBoard rev.C4, the following SPI signals are available on the<br />
Beagle's 28-pin expansion header; the SPI signals are available in pinmux mode<br />
1, while mode 0 names are also given for reference.<br />
<br />
{|<br />
!colspan='4'|McSPI 3<br />
|-<br />
!Header Pin<br />
!Mode 0<br />
!Mode 1 (SPI)<br />
!Pinmux configuration<br />
|-<br />
| 21 || MMC2_CLKO || McSPI3_CLK || OMAP_PIN_INPUT (*)<br />
|-<br />
| 17 || MMC2_DAT0 || McSPI3_SOMI || OMAP_PIN_INPUT<br />
|-<br />
| 19 || MMC2_CMD || McSPI3_SIMO || OMAP_PIN_OUTPUT<br />
|-<br />
| 11 || MMC2_DAT3 || McSPI3_CS0 || OMAP_PIN_OUTPUT<br />
|-<br />
| 13 || MMC2_DAT2 || McSPI3_CS1 || OMAP_PIN_OUTPUT<br />
|-<br />
!colspan='4'|McSPI 4<br />
|-<br />
!Header Pin<br />
!Mode 0<br />
!Mode 1 (SPI)<br />
!Pinmux configuration<br />
|-<br />
| 20 || BcBSP1_CLKR|| McSPI4_CLK || OMAP_PIN_INPUT (*)<br />
|-<br />
| 18 || McBSP1_DR || McSPI4_SOMI || OMAP_PIN_INPUT<br />
|-<br />
| 12 || McBSP1_DX || McSPI4_SIMO || OMAP_PIN_OUTPUT<br />
|-<br />
| 16 || McBSP1_FSX || McSPI4_CS0 || OMAP_PIN_OUTPUT<br />
|} <br />
<br />
(*) ''' Important: ''' The CLK pins must be put in input mode for the chip to<br />
correctly register input on SOMI. Failure to set CLK as an input will result in<br />
all reads producing zeros.<br />
<br />
== Configuring spi_board_info ==<br />
In addition to the pin multiplexer, one must also tell the kernel a bit about<br />
the SPI controller itself. This is done in the board file using an<br />
spi_board_info struct. For example, to configure McSPI3.0, one might use the<br />
following,<br />
<pre><br />
static struct spi_board_info beagle_mcspi_board_info = {<br />
.modalias = "spidev",<br />
.max_speed_hz = 48000000, //48 Mbps<br />
.bus_num = 3,<br />
.chip_select = 0, <br />
.mode = SPI_MODE_1,<br />
};<br />
</pre><br />
<br />
One would then register this with the SPI subsystem during board initialization (i.e. omap3_beagle_init()), with the following,<br />
<pre><br />
spi_register_board_info(beagle_mcspi_board_info,<br />
ARRAY_SIZE(beagle_mcspi_board_info));<br />
</pre><br />
<br />
== Patches ==<br />
This [[BeagleBoard/SPIPatch-2.6.32|patch]] was developed against 2.6.32 and exposes through spidev all<br />
of the McSPI controllers and chip selects brought out on the BeagleBoard.<br />
<br />
== Discussion ==<br />
Here are some mailing list threads of various peoples' experiences getting SPI running on the Beagle:<br />
<br />
* [http://groups.google.com/group/beagleboard/browse_thread/thread/42988f0e14db0f01/816397901ec999c4|MCSPI3 working, both ways]<br />
* [http://groups.google.com/group/beagleboard/browse_thread/thread/c72b69ed45d74403/39094d6bf4f457ad|MCSPI TX works fine, but RX all zeros]<br />
* [http://groups.google.com/group/beagleboard/browse_thread/thread/d6a4e0703033cada|SPI testing]<br />
* [http://groups.google.com/group/beagleboard/browse_thread/thread/320ceba30172fba5/9db5bcf44392d4a0?show_docid=9db5bcf44392d4a0|SPI Troubles]<br />
* [http://markmail.org/message/ktm4e2qytiv4tcm3 |SPI with Beagleboard (for a newbie in Linux)]<br />
* [http://markmail.org/thread/oyrfigv37df26223 |McSPI with REV C]</div>EricBloch