Changes

Jump to: navigation, search

SBCX-TN-001: Android Things and SPI bus

1,308 bytes added, 11:35, 5 January 2021
no edit summary
{{InfoBoxTop}}
{{AppliesToSBCX}}
{{AppliesToSBC Axel TN}}
{{AppliesToAxel}}
{{AppliesToAxelLite}}
{{AppliesToAxelEsatta}}
{{AppliesToIoT}}
{{AppliesTo IoT TN}}
{{InfoBoxBottom}}
== History ==
These interfaces don't include the ones that are typically used in products addressing industrial applications: I2C bus, SPI bus, UARTs, etc. However, as Android popularity is growing outside the mobile world too, Google defined a set of additional APIs to standardize the access to these interfaces as well. These new APIs are part of the [https://developer.android.com/things/index.html Android Things project].
This Technical Note describes the implementation of the [https://developer.android.com/things/sdk/pio/spi.html APIs related to the SPI bus] to access the SPI bus TBD SPI4 of the SBCX platformin the form of a native library. The solution was tested with Android 4.4.3.
==Testbed==
* Android Version: 4.4.3 (Jelly Bean).
To verify the functionality of the SPI buslibrary, a simple device (serial [https://www.micron.com/~/media/documents/products/data-sheet/nor-flash/serial-nor/m25p/m25p40.pdf NOR flash memory]) has been connected to the expansion connector (J33). Specifically, the SPI4 bus has been used.To build the example application using the library, the following version [https://developer.android.com/studio/index.html Android Studio] has been used: <pre>Android Studio 3.1Build #AI-173.4670197, built on March 22, 2018JRE: 1.8.0_152-release-1024-b02 amd64JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.oAndroid SDK API 27</pre>
=== Wiring ===
The following table details [[File:SBCX-Android-4.4.3-SPI-hw.png|thumb|center|600px|Simplyfied diagram of the serial flash memory interfacing of ]]As depicted in the previous image, the serial flash memory ot has been connected to the SPI4 bus by using SBCX's expansion connector (J33). The following table details the signals that have been used.
{| class="wikitable"
!Nor
==Software implementation==
The following picture shows how the organization of the software layelayers.
[[File:SBCX-Android-4.4.3-SPI.png|thumb|center|600px|Software stack]]
To implement such solution, the following requirements must be met:
*The Linux kernel must support [https://www.kernel.org/doc/Documentation/spi/spidev spidev]
*The device file must have the permissions as shown in [[#Managing the device connection|this section]].*The device tree must be modified in order to instantiate the SPI bus to be accessed*The : it is enough to enable the <code>escpi4</code> peripheral into SBCX device file must instantiate TBDtree
<pre>
&ecspi4 {
status = "okay";
};
</pre>
=== Example project===An [[#Downloads|example project]] is provided to illustrate how to use the native library. It includes the library itself and a simple application which reads the device identification data of the flash memory (<code>READ IDENTIFICATION</code> command).[[File:Spi test.png|thumb|center|600px|Test application]]==== Managing the device connection ====
In order to open a connection to a particular SPI slave, you need to know the unique name of the bus. The get this name,
run the following command from the serial console:
</pre>
==== Configuring clock and data modes ====
Configuration method are identical to the Andriod Things api [https://developer.android.com/things/sdk/pio/spi.html#mode ref].
</pre>
==== Transferring data ====
Is important to note that async I/O are not supported in userspace at this time [https://www.kernel.org/doc/Documentation/spi/spidev ref], furthermore '''LSB''' mode is not supported by the i.MX6 processor [https://community.nxp.com/thread/388187 ref].
To communicate with the device the following methods are available
*<code> void WriteByte(byte symbol)</code> For : to transfer a byte without reading the response from the device.*<code> void WriteBuffer(byte[] data, int len)</code> For : to transfer a buffer to the device without processing the response.*<code> void Transfer(byte[] tx_data, byte[] rx_data, int len)</code> For : to transfer a buffer smaller than the length of the receiving one.*<code> void Transfer(byte[] tx_data, byte[] rx_data) </code> For : to transfer and read a buffer with the same length.*<code> void Transfer(byte symbol, byte[] rx_data, int len)</code> For : to transfer a byte and read a buffer of length ''len''.
<pre>
</pre>
 
==Downloads==
The library can be downloaded from example project is available for download at [http://mirror.dave.eu/axel/SBCX-TN-001 this link].
dave_user, Administrators
5,178
edits

Navigation menu