Difference between revisions of "SBCX-TN-001: Android Things and SPI bus"

From DAVE Developer's Wiki
Jump to: navigation, search
(Testbed)
Line 21: Line 21:
  
 
==Testbed==
 
==Testbed==
TBD
+
As stated in the introduction, the solution has been tested on a platform running Android 4.4.3. From the software standpoint, this platform is a good example of an implementation where significant changes have been done to use Android on an industrial embedded device. Some of these changes modify the Android security model. In many cases, this is acceptable because the overall security of the product is not compromised (for instance, many devices used for industrial applications are not connected to the Internet and the physical access is granted to authorized personell only).
 +
 
 +
The following is a not exhaustive list of the changes with respect to the standard/typical Android configuration used on mobile devices:
 +
*As the non-volatile storage device is a NAND flash, UBIFS file system has been used
 +
*There is only one partition
 +
*The file system is read/write; as such, the <code>system</code> directory is writeable as well
 +
*A serial console is available on a UART port; <code>root</code> login is allowed on this console
 +
*U-Boot has been used as bootloader.
 +
  
 
Development have been performed on the following platform:
 
Development have been performed on the following platform:
Line 78: Line 86:
 
|48
 
|48
 
|}
 
|}
 +
 
==Implementation==
 
==Implementation==
  

Revision as of 11:07, 10 April 2018

Info Box
SBC-AXEL-02.png Applies to SBC AXEL

History[edit | edit source]

Version Date Notes
1.0.0 April 2018 First public release

Introduction[edit | edit source]

When using Android for embedded platforms, software developers have to face several challenges. Most of them are due to the fact that Android was designed originally to run on mobile devices which meet specific hardware requirements. As such, the APIs to access the hardware interfaces from the application layer are defined accordingly.

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 Android Things project.

This Technical Note describes the implementation of the APIs related to the SPI bus to access the SPI bus TBD of the SBCX platform. The solution was tested with Android 4.4.3.

Testbed[edit | edit source]

As stated in the introduction, the solution has been tested on a platform running Android 4.4.3. From the software standpoint, this platform is a good example of an implementation where significant changes have been done to use Android on an industrial embedded device. Some of these changes modify the Android security model. In many cases, this is acceptable because the overall security of the product is not compromised (for instance, many devices used for industrial applications are not connected to the Internet and the physical access is granted to authorized personell only).

The following is a not exhaustive list of the changes with respect to the standard/typical Android configuration used on mobile devices:

  • As the non-volatile storage device is a NAND flash, UBIFS file system has been used
  • There is only one partition
  • The file system is read/write; as such, the system directory is writeable as well
  • A serial console is available on a UART port; root login is allowed on this console
  • U-Boot has been used as bootloader.


Development have been performed on the following platform:

  • CPU: based on NXP/Freescale i.MX6 Dual core
  • SOM: Axel lite
  • carrier board: SBC-AXEL
  • Android Version: 4.4.3 (Jelly Bean)
  • LCD adapter: TI-DF 1.0.0-CS102015
  • Nor Spi memory: M25P40 datasheet

Wiring[edit | edit source]

Nor Name Onepiece Pin
1 S# SPI4_SS0_R 10
2 DQ1 SPI4_MOSI_R 6
3 W# 3v3 48
4 Vss GND 2
5 DQ0 SPI4_MOSI_R 8
6 C SPI4_SCLK_R 4
7 HOLD# 3v3 48
8 Vcc 3v3 48

Implementation[edit | edit source]

TBD

Managing the device connection[edit | edit source]

In order to open a connection to a particular SPI slave, you need to know the unique name of the bus. Boot the developer board and run the following commands from the serial console

root@sbcx:/ # ls /dev/spi*
/dev/spidev32765.0
root@sbcx:/ #

Is important to note that the above method is the only method available in order to retrieve the spi device name and getSpiBusList() is not implemented within the library.

Once you know the target name, the api of the library eu.dave.spi_dev follow the Android things nomenclature


public class HomeActivity extends Activity {
    // SPI Device Name
    private static final String SPI_DEVICE_NAME = "/dev/spidev32765.0";

    private SpiDevice mDevice;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mDevice = new SpiDevice(SPI_DEVICE_NAME);
        // Attempt to access the SPI device
        try {
           mDevice.Open();
        } catch (IOException e) {
             Log.w("Error", "Unable to access SPI device" + e.getMessage());
        }
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

        if (mDevice != null) {
            try {
                mDevice.Close();
                mDevice = null;
            } catch (IOException e) {
                Log.w("Error","Unable to close SPI device" + e.getMessage());
            }
        }
    }
}

Configuring clock and data modes[edit | edit source]

Configuration method are identical to the Andriod Things api ref.

public void configureSpiDevice(SpiDevice device) throws IOException {
    // Low clock, leading edge transfer
    device.setMode(SpiDevice.MODE0);

    device.setFrequency(500000);     // 16MHz
    device.setBitsPerWord(8);          // 8 BPW
    device.setBitJustification(false); // MSB first
}

Transferring data[edit | edit source]

Is important to note that async I/O are not supported in userspace at this time ref, furthermore LSB mode is not supported by the i.MX6 processor ref.

To communicate with the device the following methods are available

  • void WriteByte(byte symbol) For transfer a byte without reading the response from the device.
  • void WriteBuffer(byte[] data, int len) For transfer a buffer to the device without processing the response.
  • void Transfer(byte[] tx_data, byte[] rx_data, int len) For transfer a buffer smaller than the length of the receiving one.
  • void Transfer(byte[] tx_data, byte[] rx_data) For transfer and read a buffer with the same length.
  • void Transfer(byte symbol, byte[] rx_data, int len) For transfer a byte and read a buffer of length len.
public void sendCommand(SpiDevice device, byte[] buffer) throws IOException {
    byte[] response = new byte[buffer.length];
    device.Transfer(buffer, response, buffer.length);
    ...
}