Configuring SPI
This chapter describes how to configure the SPI configuration file, spi.conf. The chapter includes rules for editing the file sections and their parameters.
Configuring the spi.conf file
You can edit the SPI configuration file, spi.conf, to match the SPI bus and devices layout of your target. The default file path is /etc/system/config/spi/spi.conf. You can use this file (or one similar) by specifying the file path as the parameter to the SPI driver -c command line option.
The file contains specific configuration sections.
Each section describes the parameters which can be set.
Each section starts with a [<section type>]
declaration.
All parameters after the [<section type>]
declaration belong to the declared section,
up to the next [<section type>]
declaration (or end-of-file).
The []
character sequence should not appear
in any non-commented section elsewhere in the file.
For the purpose of documentation,
this file includes all parameters along with their default values,
but commented out with '#
'.
When editing, retain the known default value
by copying the line and changing the value.
All comments follow a '#
' until the end-of-line.
White space is ignored unless otherwise stated.
Rules for the config file
- Only alphanumeric characters are allowed for section name.
- Only alphanumeric characters and '_' are allowed for parameter name.
- Must have at least one
bus
section in each config file. - Must have at least one
dev
section under eachbus
. - In each
bus
section, all the mandatory parameters must be set. - In each
bus
section,bus
number andbus
name cannot duplicate. - In each
dev
section, all the mandatory parameters must be set. - Under the same parent bus,
dev
number anddev
name cannot duplicate. - In each
dev
section, theparent_busno
has to be an existingbusno
in previous bus sections.
Configuration sections
Section | Description |
---|---|
globals |
Specifies a SPI global configuration. |
bus |
Specifies a SPI bus configuration. |
dev |
Specifies a SPI device configuration. |
Configure globals section
The globals
section specifies
the configuration to apply globally to SPI.
Parameters:
The following parameters are configurable under the globals
section:
Parameter | Description | Type | Possible values (if applicable) |
---|---|---|---|
verbose | SPI driver and io-spi
debuggers print verbosity.
The -v command-line option of the
spi-XXX driver overrides the
verbose value in the config file.
|
Integer |
Example:
globals
section:
[globals]
verbose=5
Configure bus section
The bus
section specifies
the configuration to apply to a SPI bus.
Parameters:
bus
section:
Parameter | Description | Mandatory | Type | Possible values (if applicable) |
---|---|---|---|---|
busno | Bus number | Yes | Integer | |
name | Bus name | Yes | String | See Configuring the spi.conf file. |
base | Bus base address | Yes | Hexadecimal | 0x00000000 - 0xFFFFFFFF . |
irq | Bus IRQ (interrupt request) number. | Yes | Integer | |
input_clock | bus input clock | Yes | Integer | Unit Hz |
bs | Board or controller specific parameters | No | String | Default NULL |
dma_init_opts | DMA initialization options | No | String | Default NULL . |
dma_attach_opts | DMA attach options | No | String | Default NULL . |
dma_thld | DMA threshold | No | Integer | Default 0 . |
Example:
bus
section:
[bus]
busno=0
name=spi0
base=0xfe204000
irq=150
input_clock=500000000
bs=rpanic=48,tpanic=16
dma_attach_opts=num_cbs=256,range_min=0,range_max=14,typed_mem=sysram&below1G
Configure dev section
The dev
section specifies the configuration
to apply to a device connected to the same SPI bus.
dev
section has to be after its parent
bus
section and has to provide its
parent_busno.
Otherwise, the dev
section won't be added to device list.
Parameters:
dev
section:
Parameter | Description | Mandatory | Type | Possible values (if applicable) |
---|---|---|---|---|
parent_busno | Parent bus number of the device | Yes | Integer | |
devno | Device number | Yes | Integer | |
name | Device name | Yes | String | See Configuring the spi.conf file. |
clock_rate | Bus speed for the device | Yes | Integer | Unit Hz |
cpha | SPI CPHA | No | Integer | Options are: 0 or 1 .
Default 0 . |
cpol | SPI CPOL | No | Integer | Options are: 0 or 1 .
Default 0 . |
bit_order | SPI bit order | No | String | Options are: MSB or LSB .
Default MSB . Case insensitive. |
word_width | SPI transfer word width in bits | No | Integer | Options are: 8 , 16 , or
32 . Default 8 . |
idle_insert | SPI idle insertion support | No | Integer | Options are: 0 or 1 .
Default 0 . |
Example:
dev
section:
[dev]
parent_busno=0
devno=0
name=dev0
clock_rate=5000000
cpha=1
word_width=32
Example of spi.conf
globals
section
and two bus
sections,
spi0 and spi3.
Bus spi0 has two dev
sections,
while spi3 has one dev
section.
Notice how each of the dev
sections come after its parent
bus
section, indicated by the
parent_busno of each dev
sections.
############################# S E C T I O N ##################################
# Section globals
[globals]
verbose=5
############################# S E C T I O N ##################################
# Section bus
[bus]
busno=0
name=spi0
base=0xfe204000
irq=150
input_clock=500000000
bs=rpanic=48,tpanic=16
dma_attach_opts=num_cbs=256,range_min=0,range_max=14,typed_mem=sysram&below1G
############################# S E C T I O N ##################################
# Section dev
[dev]
parent_busno=0
devno=0
name=dev0
clock_rate=5000000
cpha=1
############################# S E C T I O N ##################################
# Section dev
[dev]
parent_busno=0
devno=1
name=dev1
clock_rate=5000000
cpol=1
############################# S E C T I O N ##################################
# Section bus
[bus]
busno=3
name=spi3
base=0xfe204600
irq=151
input_clock=500000000
############################# S E C T I O N ##################################
# Section dev
[dev]
parent_busno=3
devno=0
name=dev0
clock_rate=5000000
word_width=32