...
Anchor
...
Signal |
...
Description |
...
|
...
Slave select |
...
|
...
Clock |
...
|
...
Slave output (master input) |
...
|
...
Slave input (master output) |
...
Anchor
No specification exists for SPI, a condition which invites technological divergence. So though the simplicity of the interface limits variations between implementations, the required transfer unit length, shift direction, clock frequency and clock polarity and phase do vary from device to device. Take as an example Figure C Figure C-3 which gives the bit form of a basic command/response exchange on a typical serial flash. The command and response both divide into 8-bit chunks, the transfer unit for the device. Within these units, the data is transferred from most significant bit (MSB) to least significant bit (LSB), which is the slave’s shift direction. Though not evident from the diagram—the horizontal axis being labeled in clocks rather than time—the slave cannot operate at a frequency higher than 20-MHz. Finally, the clock signal prior to slave select activation is low (clock polarity or CPOL is 0), and data is latched on the rising clock edge (clock phase or CPHA is 0). Together, those are the aspects of SPI communication that may need to be configured: Anchor
...
If CPOL = 1, the clock is high when inactive.
...
...
If CPHA = 1, data is “changed” on the leading edge of the clock and “read” on the leading edge.
...
The most commonly-supported settings are {CPOL, CPHA} = {0, 0} and {1, 1}.
...
A BSP is required that abstracts a CPU’s SPI peripheral. The port includes one code file named according to the following rubric: Anchor
FS_DEV_<dev_name>_BSP.C
or FS_DEV_<dev_name>_SPI_BSP.c
Anchor
This file is generally placed with other BSP files in a directory named according to the following rubric: Anchor
\Micrium\Software\EvalBoards\<manufacturer>\<board_name>
Anchor
\<compiler>\BSP\
Several example ports are included in the µC/FS distribution in files named according to the following rubric: Anchor
\Micrium\Software\uC-FS\Examples\BSP\Dev\NAND\<manufacturer>\<cpu_name>
...
\Micrium\Software\uC-FS\Examples\BSP\Dev\NOR\<manufacturer>\<cpu_name>
...
\Micrium\Software\uC-FS\Examples\BSP\Dev\SD\SPI
\<manufacturer>\<cpu_name>
Anchor
Check all of these directories for ports for a CPU if porting any SPI device; the CPU may be been used with a different type of device, but the port should support another with none or few modifications. Each port must implement the functions to be placed into a FS_DEV_SPI_API
structure: Anchor
...
rowspan | 11 |
---|
...
...
Anchor
...
Function |
...
Description |
...
|
...
Open (initialize) hardware for SPI. |
...
...
|
...
Close (uninitialize) hardware for SPI. |
...
...
|
...
Acquire SPI bus lock. |
...
|
...
Release SPI bus lock. |
...
|
...
Read from SPI bus. |
...
...
|
...
Write to SPI bus. |
...
|
...
Enable device chip select. |
...
|
...
Disable device chip select |
...
|
...
Set SPI clock frequency |
...
Table C-4 SPI port functions
...
Anchor
The first argument of each of these port functions is the device unit number, an identifier unique to each driver/device type—after all, it is the number in the device name. For example, “sd:0:” and “nor:0:” both have unit number 1. If two SPI devices are located on the same SPI bus, either of two approaches can resolve unit number conflicts: Anchor
...