userland, conceptually similar to what i2c(8) provides for i2c devices. Submitted by: Bob Frazier Differential Revision: https://reviews.freebsd.org/D15029
198 lines
5.8 KiB
Groff
198 lines
5.8 KiB
Groff
.\" Copyright (c) 2018 by S.F.T. Inc.
|
|
.\"
|
|
.\" Redistribution and use in source and binary forms, with or without
|
|
.\" modification, are permitted provided that the following conditions
|
|
.\" are met:
|
|
.\" 1. Redistributions of source code must retain the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer.
|
|
.\" 2. Redistributions in binary form must reproduce the above copyright
|
|
.\" notice, this list of conditions and the following disclaimer in the
|
|
.\" documentation and/or other materials provided with the distribution.
|
|
.\"
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
.\" SUCH DAMAGE.
|
|
.\"
|
|
.\" $FreeBSD$
|
|
.\"
|
|
.Dd "15 April 2018"
|
|
.Dt spi 8
|
|
.Os
|
|
.Sh NAME
|
|
.Nm spi
|
|
.Nd communicate on SPI bus with slave devices
|
|
.Sh SYNOPSIS
|
|
.Nm
|
|
.Op Fl f Ar device
|
|
.Op Fl d Ar r|w|rw
|
|
.Op Fl m Ar mode
|
|
.Op Fl s Ar max-speed
|
|
.Op Fl c Ar count
|
|
.Op Fl C Ar cmd_bytes
|
|
.Op Fl A
|
|
.Op Fl b
|
|
.Op Fl L
|
|
.Op Fl v
|
|
.Nm
|
|
.Op Fl i
|
|
.Op Fl f Ar device
|
|
.Op Fl v
|
|
.Nm
|
|
.Op Fl h
|
|
.Sh DESCRIPTION
|
|
The
|
|
.Nm
|
|
utility can be used to perform raw data transfers
|
|
.Pq read, write, or simultaneous read/write
|
|
with devices on the SPI bus, via the
|
|
.Xr spigen 4
|
|
device.
|
|
.Pp
|
|
Each
|
|
.Xr spigen 4
|
|
device is associated with a specific
|
|
.Sq chip select
|
|
.Pq cs
|
|
pin on the spibus, and therefore needs to be specified.
|
|
If no device name is specified on the command line,
|
|
.Nm
|
|
assumes
|
|
.Sq spigen0.0 .
|
|
.Pp
|
|
For more information on the spigen device, see
|
|
.Xr spigen 4 .
|
|
.Pp
|
|
The options are as follows:
|
|
.Bl -tag -width ".Fl f Ar device"
|
|
.It Fl A
|
|
Specifies ASCII mode.
|
|
Both read and write data is input and output as
|
|
2-character hexadecimal values, optionally separated by white space,
|
|
such as 00 01 02 etc.
|
|
When combined with the
|
|
.Sq -b
|
|
flag, the data on stdin remains a sequence of ASCII hexadecimal
|
|
byte values, but the output reverts to binary mode.
|
|
.It Fl b
|
|
Binary
|
|
.Pq output
|
|
mode.
|
|
Only has an effect when
|
|
.Sq -A
|
|
has been specified.
|
|
Reverts the output back to binary
|
|
.Pq rather than ASCII ,
|
|
while leaving the input format as-is.
|
|
Use in combination with
|
|
.Sq -A
|
|
to allow using something like
|
|
.Sq echo
|
|
to pass hexadecimal values to the SPI device, but output the received data
|
|
on stdout as binary.
|
|
.It Fl C Ar command bytes
|
|
Sends one or more
|
|
.Sq command
|
|
bytes, skipping any bytes read-in during the transfer.
|
|
The byte values should be specified as a quoted parameter, similar to the
|
|
format for data on stdin for
|
|
.Sq -A ,
|
|
that is, 2 character hexadecimal values, optionally separated by white space.
|
|
An SPI device will typically require that a command be sent, followed by
|
|
bytes of data.
|
|
You can use this option to send the command without receiving any data bytes
|
|
during the command sequence.
|
|
.It Fl c Ar count
|
|
The total number of bytes to transfer as a decimal integer.
|
|
If a write or a read/write transaction is being performed, and fewer than
|
|
this number of bytes are read in from stdin, the remaining bytes will be
|
|
sent with a value of
|
|
.Sq 0 .
|
|
If the length can be determined from the input file size, you can use a
|
|
.Sq count
|
|
value of
|
|
.Sq -1
|
|
to base the transfer on the input file's size.
|
|
.It Fl d Ar r|w|rw
|
|
Transfer direction: Use
|
|
.Sq r
|
|
for read,
|
|
.Sq w for write, and
|
|
.Sq rw
|
|
for simultaneous read and write.
|
|
.It Fl f Ar device
|
|
SPI device to use
|
|
.Pq default is /dev/spigen0 .
|
|
.It Fl h
|
|
Print help text to stderr, explaining the command line options.
|
|
.It Fl i
|
|
Displays information about the SPI device to stderr.
|
|
Whenever this flag is specified, no data is read or written, and the mode
|
|
and clock speed are not changed.
|
|
.It Fl L
|
|
LSB bit order.
|
|
The default is MSB, i.e., the highest order bit is
|
|
transmitted first.
|
|
Specifying -L caused the LSB to be transmitted and read first.
|
|
.It Fl m Ar 0 - 3
|
|
SPI mode, 0 through 3.
|
|
This defines the clock phase and timing with respect to reading and writing
|
|
data, as per the SPI specification.
|
|
.It Fl s Ar speed
|
|
Specify the maximum speed, in Hz, for the SPI clock.
|
|
The bus will operate at its highest available speed which does not
|
|
exceed this maximum.
|
|
.It Fl v
|
|
Specifies Verbose mode.
|
|
Diagnostics and information are written to stderr.
|
|
You can specify
|
|
.Sq -v
|
|
more than once to increase verbosity.
|
|
.El
|
|
.Sh EXAMPLES
|
|
Here are a few examples of using the spi utility:
|
|
.Bl -bullet
|
|
.It
|
|
Get information about the default SPI device
|
|
.Pp
|
|
spi -i
|
|
.It
|
|
Set the maximum clock speed to 200Khz and the mode to 3 on spigen0.1, but do
|
|
not transmit nor receive any data
|
|
.Pp
|
|
spi -f spigen0.1 -s 200000 -m 3
|
|
.It
|
|
Send a command sequence consisting of 2 bytes, and read 2 additional bytes
|
|
from the SPI device, using the current mode and speed on the default device
|
|
.Pp
|
|
spi -d r -C "00 01" -c 2
|
|
.It
|
|
Transmit a byte value of 5, and receive 2 bytes, displaying their values as
|
|
2-byte ASCII hexadecimal, with mode 2, and a maximum clock speed of 500khz.
|
|
.Pp
|
|
echo "05" | spi -A -d rw -m 2 -s 500000 -c 2
|
|
.It
|
|
Send a binary file, and output the SPI result through
|
|
.Sq od
|
|
as hexadecimal bytes, using the current maximum clock speed and SPI mode.
|
|
.Pp
|
|
spi -d rw -c -1 <input_file.bin | od -An -t x1
|
|
.It
|
|
Send 2 bytes of data, receive a total of 4 bytes, and output the SPI result
|
|
as binary data, piped through
|
|
.Sq od ,
|
|
displaying it as two hexadecimal unsigned short integer values.
|
|
.Pp
|
|
echo "00 01" | spi -A -b -d rw -c 4 | od -t x2
|
|
.El
|
|
.Pp
|
|
.Sh SEE ALSO
|
|
.Xr spigen 4
|