Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/spi/spi.8
.Dd "15 April 2018" | |||||
ian: This needs a copyright block at the top.
And a .Dd line. | |||||
.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 | |||||
Done Inline ActionsI think this is usually done as: The .Nm utility can be use to perform raw data transfers (read, write, rpokala: I think this is usually done as:
```
The
.Nm
utility can be use to perform raw data transfers… | |||||
Done Inline Actionsthanks for all of this, I'm not that good at man pages, and although the markup 'works' it may not be the way you'd want it in the base distro. So I'll look over all of this and update it accordingly. Still learning how to use THIS system too, so if there is an easy way to 'patch the patch'... bobf_mrp3.com: thanks for all of this, I'm not that good at man pages, and although the markup 'works' it may… | |||||
.Pq read, write, or simultaneous read/write | |||||
Done Inline Actionsor simultaneous read/write) with devices on the SPI bus, via the .Xr spigen 4 device. rpokala: ```
or simultaneous read/write) with devices on the SPI bus, via the
.Xr spigen 4
device.
``` | |||||
with devices on the SPI bus, via the | |||||
.Xr spigen 4 | |||||
Done Inline ActionsA .Xr spigen 4 device is associated with a specific .Sq chip select .Pq cs pin on the rpokala: ```
A
.Xr spigen 4
device is associated with a specific
.Sq chip select
.Pq cs
pin on the
``` | |||||
Done Inline Actionskept 'An' rather than 'A' [seems to read better]. bobf_mrp3.com: kept 'An' rather than 'A' [seems to read better]. | |||||
device. | |||||
.Pp | |||||
Done Inline Actionsspecified on the command line, .Nm assumes .Sq spigen0 . rpokala: ```
specified on the command line,
.Nm
assumes
.Sq spigen0 .
``` | |||||
An | |||||
.Xr spigen 4 | |||||
Done Inline ActionsFor more information on the spigen device, see .Xr spigen 4 . rpokala: ```
For more information on the spigen device, see
.Xr spigen 4 .
``` | |||||
device is associated with a specific | |||||
.Sq chip select | |||||
.Pq cs | |||||
Done Inline ActionsThe longest option is "-f device", so this should be .Bl -tag -width ".Fl f Ar device" rpokala: The longest option is "-f device", so this should be
```
.Bl -tag -width ".Fl f Ar device"
``` | |||||
pin on the spibus, and therefore needs to be specified. | |||||
If no device name is specified on the command line, | |||||
Done Inline ActionsHex numbers are not digits; perhaps "2-character", or "8-bit"? rpokala: Hex numbers are not digits; perhaps "2-character", or "8-bit"? | |||||
.Nm | |||||
assumes | |||||
.Sq spigen0 . | |||||
.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. | |||||
If the device has been configured for a lower speed, or cannot transmit at | |||||
the specified speed, the lower value will be used. | |||||
.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 spigen1, but do | |||||
not transmit nor receive any data | |||||
.Pp | |||||
spi -f spigen1 -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 |
This needs a copyright block at the top.
And a .Dd line.