Android Accessory Development Kit Beagle

Fundamentals of Beaglebone as Android Accessory

Beaglebone runs the Android accessory protocol (generic) and accessory application specific software. We use the TI's Starterware for Beaglebone as the base software and have developed & integrated the android accessory protocol and a sample application. We have also developed a dummy app (apk) for Android that runs on phone or tablet that interacts with Beaglebone application to control the peripherals on

Ads by Google
Functionally, Beaglebone is connected to Android powered (phone / tablet) device over USB, the Beaglebone operates USB in host mode (powers the bus and enumerates devices) and the Android-powered device acts as the USB device. Beaglebone runs the Android USB accessory protocol with application software, detects & enumerates the Android-powered device (phone/tablet) and starts the sample application (beaglebone side) that waits for commands from Android device (running sample accessory apk) to control/monitor the Beaglebone peripherals.

Why use TI's StarterWare software package as a base software v/s Linux or u-boot ?

- For Linux, we have to develop a all new USB class for Android accessory and a custom application that talks to peripheral Linux drivers. The implementation is not complex, we have plans to develop this in future.
- u-boot has limited support for AM335x peripherals and we found USB Host protocol lack few features to implement the accessory protocol.
TI's starterware is free to use and distribute, comes with pre-integrated libraries with APIs to access every peripheral on AM335x processor, very easy to use with lots of examples, direct support from TI. For more details please refer to StarterWare getting started guide and user guide

Android Accessory over Bluetooth (TBD)

The current implementation is based on USB, this will be extended to work over Bluetooth. We are waiting for the beaglebone Bluetooth cape availability.

Ads by Google

Android Accessory over Google Cloud messaging

Beaglebone can be communicate to Android phone using Google Cloud messaging service, there is an interesting implementation from our community member. Refer to this project for more details.

Out of Box Demo

This section gives the instructions to quickly prepare an SD Card with pre-built binaries of beaglebone accessory software and to experience Beaglebone as Android accessory over USB.

Getting Pre-built Images

To successfully experience beaglebone as an Android accessory we need
  • Beaglebone Starterware binary (with integrated Android accessory protocol and Accessory application) - BeagleBoneAcc.tar.gz
  • A sample Android application (.apk) to be installed on any Android phone or Tablet. - TI-ADKDemo.tar.gz

Prepartion of SD card

Connect a Micro SD card via a USB card reader on an Ubuntu Machine
From a command terminal, type the below commands,
   #> tar -xzvf BeagleBoneAcc.tar.gz
   #> cd BeagleBoneAcc
   #> sudo ./ /dev/sd
The above step prepares the bootable SD Card with Starterware image, which can be used to boot beaglebone as an Android accessory.

Ads by Google

Install Accessory Application

Follow the below steps to install the example Android application on Android phone or tablet (version 4.0.3 or above)
  • The apk is located in TI-ADKDemo/bin/TI-ADKDemo.apk
  • Install this application on Android4.0.3 powered device.
  • The phone can be connected to a Windows or Linux PC and the application can be transferred/installed through ADB over USB. This step should be known to developer as it's a standard method to download/install any Android custom apk on phones/tablets.

Experience Beaglebone as Android accessory

After preparing the SD card for Beaglebone and installing apk on phone, please follow the steps below:
  • Insert the SD card into Beaglebone
  • Connect the power cable and power ON the board
  • Let the phone/tablet be in on state with accessory app running
  • Connect Beaglebone USB host port to mini/Micro-B USB port of the Android device (phone/tablet).
  • Control the LEDs on Beaglebone through the buttons displayed on the Android accessory UI on phone.
  • The phone displays a timer that is synced from RTC running on beaglebone.
This app is just an example to prove beaglebone communication with phone/tablet using Android accessory protocol. Both, the apk on phone and the application on beaglebone can be modified for any type of accessory. The Android accessory protocol need not be changed.

Building Sources

The procedure to download the sources, installing the toolchain and compiling the sources to generate the final images (like pre-built images) is described below

Getting the Toolchain

  • Download CodeSourcery tool chain for ARM for Linux LINK
  • Install toolchain on Linux Host machine (ubuntu 10.04 or above)
  •    #> chmod 777 arm-2009q1-161-arm-none-eabi.bin
       #> ./arm-2009q1-161-arm-none-eabi.bin
  • Set PATH environment variable contain the path of the compiler/tool chain.
   #> export PATH=$PATH:/opt/tools/CodeSourcery/Sourcery_G++_Lite/bin
  • Point LIB_PATH shell environment variable to the Code Sourcery installation
Note: /opt/tools/ is the path selected while installing the toolchain. If you are installing toolchain path at some other location, please set PATH and LIB_PATH variable appropriately.

Getting Source code

As mentioned above, we use TI's StarterWare software package to develop Beaglbone Android accessory.
  • Download StartWare Linux Installer package from HERE
  • Install StarterWare package
  •    #> /AM335X_StarterWare_02_00_00_07_Setup.bin
  • Download the Beaglebone Accessory patch to StarterWare from HERE
  • Apply the patch
  •     #> cd 
        #> patch -p1< /adk_patch/0001-Add-beaglebone-Accessory-support.patch

Compile the Source Code

Building The Bootloader

Use below commands to build the StarterWare bootloader, this will generate boot_ti.bin image at /binary/armv7a/gcc/am335x/beaglebone/bootloader/Release
   #> cd /build/armv7a/gcc/am335x/beaglebone/bootloader
   #> make

NOTE: Rename "boot_ti.bin" to MLO.

   #> mv /binary/armv7a/gcc/am335x/beaglebone/bootloader/Release/boot_ti.bin /binary/armv7a/gcc/am335x/beaglebone/bootloader/Release/MLO

Building StarterWare Android Accessory Application

Use below command to build the sample Beaglebone accessory application for StarterWare. This will generate an application usb_acc_ti.bin binary at /binary/armv7a/gcc/am335x/beaglebone/usb_acc/Release/usb_acc_ti.bin
   #> cd /build/armv7a/gcc/am335x/beaglebone/usb_acc
   #> make

NOTE: Rename Application "usb_acc_ti.bin" to "app".

   #> mv /binary/armv7a/gcc/am335x/beaglebone/usb_acc/Release/usb_acc_ti.bin /binary/armv7a/gcc/am335x/beaglebone/usb_acc/Release/app

Prepare the bootable SD/MMC card

Copy compiled images and script to image folder and populate SD/MMC card as follows.
   #> mkdir ~/image
   #> cd ~/image
   #> cp /binary/armv7a/gcc/am335x/beaglebone/bootloader/Release/MLO .
   #> cp /binary/armv7a/gcc/am335x/beaglebone/usb_acc/Release/app .
   #> cp /BeagleBoneAcc/ .
   #> sudo ./ /dev/sd
Above steps will create a bootable SD/MMC card which should be similar to pre-built images and can be used to bootup beaglebone.
Follow the steps mentioned above in the Out of the box demo section to boot the board and to use the beaglebone as an Android accessory.

Customizing software to develop new accessory

The software stack contains the
  • TI's StarterWare Package (Downloaded from TI's site)
  • USB class driver for Android accessory (Newly Implemented)
    • Implemented using the StarterWare's USB stack which adheres to the Android open accessory standard. The detailed design of StarterWare USB stack is provided HERE
    • Sample Accessory application (Newly Implemented)
    • Uses StarterWare libraries to control the hardware and interact with Android Phone/Tablet
The block diagram of Beaglebone USB accessory software is as shown below.

NOTE: To develop a new accessory, one has to modify only the StarterWare application and the phone side apk. The USB class driver remains unchanged.

Host Controller driver

The USB host controller driver handles the discovery and enumeration of any USB device. The USB host controller driver only performs enumeration and relies on the host accessory class driver to perform any other communications with Android device. Most of the code used to enumerate devices is run in interrupt context and is contained in the enumeration handler. In order to complete the enumeration process, the host controller driver also requires that the application periodically call the USBHCDMain() function.
The application has to register a USB accessory class with host controller driver using USBHCDRegisterDrivers() call so that enumeration events can be passed to it.
Please refer to StarterWare USB documentation for more details about StarterWare USB.

USB Accessory Class Driver

The USB Accessory class driver provides an interface to detect and set up communication with an Android accessory powered device (phone/tablet). In general, an accessory class driver carries following steps.
  1. Determine the device's accessory mode support
  2. Attempt to start the device in accessory mode if needed
  3. Establish communication with the device if it supports the Android accessory protocol
  4. Provides accessory read and write APIs to communicate with Android accessory powered device.
Application has to call USBACCOpen() to register a callback. The Accessory class driver will call this registered callback to notify whether
  1. USB Accessory device is connected
  2. Unknown device is connected
  3. Device is disconnected.
Once Device connected (USB_EVENT_CONNECTED) event is received, application can read and write to accessory device using AccessoryRead() and AccessoryWrite() calls

Accessory Application

Below block diagram demonstrate the Beaglebone accessory application code flow.

The application must register a USB accessory class driver by calling USBHCDRegisterDrivers() and call USBACCOpen to register a callback. The callback will get invoked by accessory class driver to indicate whether
  1. Android accessory mode device is connected (USB_EVENT_CONNECTED)
  2. Unknown device is connected (UNKNOWN_DEVICE_EVENT)
  3. Device is disconnected (USB_EVENT_DISCONNECTED).
Once the device connected event is received, accessory can communicate with the application running on Android powered device using custom communication protocol.
The example application executes the following sequence:
  1. Configure and enable the interrupts
  2. Enable the USB clocking
  3. Register the accessory host class driver
  4. Open an instance of the accessory class driver
  5. Initialize the power configuration
  6. Initialize the host controller
  7. Initializes user LED GPIO
  8. Enables RTC
  9. Periodically calls USBHCDMain() function to complete USB re-enumeration process
  10. Sends RTC time data to Android Accessory powered device, receives LED control information and configure LEDs.

To customize accessory application on Beaglebone

Directory structure

  • Place the application code in "/examples/beaglebone/"
  • Place the makefile and linker script in "/build/armv7a/gcc/am335x/beaglebone/" directory.
  • Follow below command to build the customized application
  • #> cd /build/armv7a/gcc/am335x/beaglebone/
    #> make
Note: Refer of makefile and linker script present in "/build/armv7a/gcc/am335x/beaglebone/usb_acc" directory.
  • Generated binaries will be placed in folder "/binary/armv7a/gcc/am335x/beaglebone/

Example accessory application snippet

Following code snippet gives a rough idea on how to develop a new accessory application using StarterWare package.
  • Declare structure to use host accessory class driver
 static tUSBHostClassDriver const * const g_ppHostClassDrivers[] =
  • Declare global variables to store accessory instance value and device connection state
 static unsigned int g_ulACCInstance;
 static unsigned int eUSBState;
  • Implement a callback function so that application can be informed when an Android accessory powered device is connected and disconnected.
 unsigned int ACCCallback(unsigned int ulEvent)
         case USB_EVENT_CONNECTED:
             eUSBState = STATE_ACC_INIT;

             eUSBState = STATE_NO_DEVICE;

             eUSBState = STATE_UNKNOWN_DEVICE;
  • Implement a main loop that runs the application
 int main(void)
     /*configure arm interrupt controller to generate usb interrupt */
     /*Register the host class driver*/
     USBHCDRegisterDrivers(USB_INSTANCE, g_ppHostClassDrivers, 1);
     /* Open an instance of the accessory driver and register a callback*/
     g_ulACCInstance = USBACCOpen(USB_INSTANCE, ACCCallback);


    /* Initialize the host controller stack */  
     USBHTimeOut->Value.slNonEP0= 1;

    /*Do other necessary initialization specific to your application*/
     /* Call the main loop for the Host controller driver */
     USBHCDMain(USB_INSTANCE, g_ulACCInstance);
     /* Implement main loop for the application */
            /* This state is entered when android accessory powered device is first detected */
             case STATE_ACC_INIT:
                 /* Do necessary initialization */            
             case STATE_ACC_CONNECTED:
                    /* Do accessory read and write operations.
                     * Implement your custom accessory communication protocol to 
                     * communicate with Android application
                     * running on Android accessory powered device.
             case STATE_NO_DEVICE:

        /* Periodically call the main loop for the Host controller driver */
         USBHCDMain(USB_INSTANCE, g_ulACCInstance);

To customize accessory application on Android Device (Phone/Tablet)

Please refer to Google USB accessory API guide and TI Accessory Demo Android application code to write your own accessory application that can interact with the Beaglebone.


Configuring Beaglebone to get serial console

Serial console is provided via MiniB USB connection between the BeagleBone and the Host PC. The below instructions guides the user to download the necessary drivers and configure the host to get the console over USB

On Windows Host PC

NOTE: The USB to console driver BONE_DRV.exe for 32-bit Windows PC or BONE_D64.exe for 64-bit Windows PC can be downloaded and installed on the host PC, unfortunately we haven't tried this directly.
The FTDI driver for Windows XP can be downloded from HERE
Follow the below steps to install the FTDI driver on Windows XP machine
  • Extract the contents and edit the ftdibus.inf file
  • Replace the section between
  • [FtdiHw] 
with the following content
  • Replace the section between
DriversDisk="FTDI USB Drivers Disk" 
SvcDesc="USB Serial Converter Driver" 
with the following content
USB\VID_0403&amp;PID_A6D0.DeviceDesc="USB Serial Converter"
USB\VID_0403&amp;PID_A6D0&amp;MI_00.DeviceDesc="USB Serial Converter A"
USB\VID_0403&amp;PID_A6D0&amp;MI_01.DeviceDesc="USB Serial Converter B"
USB\VID_0403&amp;PID_A6D0&amp;MI_00.DeviceDesc="USB Serial Converter A"
USB\VID_0403&amp;PID_A6D0&amp;MI_01.DeviceDesc="USB Serial Converter B"
USB\VID_0403&amp;PID_A6D0&amp;MI_02.DeviceDesc="USB Serial Converter C"
USB\VID_0403&amp;PID_A6D0&amp;MI_03.DeviceDesc="USB Serial Converter D"
USB\VID_0403&amp;PID_A6D0DeviceDesc="USB Serial Converter"
  • Follow the steps listed below to setup the console
    • Boot the board
    • Connect Mini B USB cable between board and Windows PC.
    • If it's proceeding as planned, Windows should tell you it found a new hardware and asks you to install the driver. Install driver that was downloaded as described in the above step
    • Answer "No, not this time" to the question about running Windows Update to search for software.
    • Choose "Install the hardware that I manually select from a list (Advanced)" this is the 2nd option, then click "Next"
    • Select "Show All Devices", then click "Next"
    • You are going to see a grayed-out text box with "(Retrieving a list of all devices)", click the "Have Disk..." button
    • Browse" to your driver folder (c:\...\driver). It will be looking of a .inf file so select "ftdibus.inf" and click "Open" then "OK".
    • Select "USB Serial Port" then click the "Next" button.
    • A warning will appear, answer "Yes" but read the warning anyway.
    • Click the "Close" when the wizard is completed.
    • Disconnect and reconnect Mini B USB cable from Board(probably reboot it as well).
    • Serial COM port will be listed on the Terminal Utility menu
    • Adjust the baudrate to 115200 to connect to the BeagleBone serial.

On Linux Host PC

To configure serial console output on ubuntu kindly follow the steps listed below:
#> sudo modprobe ftdi_sio vendor=0x0403 product=0xa6d0
#> minicom -D /dev/`dmesg | grep FTDI | grep "now attached to" | tail -n 1 | awk '{ print $NF }'` 
  • Make sure minicom's serial port setup is for 115200n8 with hardware flow control. The minicom configuration menu can be invoked by the command 'minicom -s' and selecting serial port setup - Serial Device (option A).
  • Run minicom with sudo, in case sufficient permission is not available for the USB serial node

Verifying Serial Connection

Once serial console setup is complete, confirm the configuration by following the steps given below
  • Push the small black reset button beside ethernet port on Beaglebone
  • If serial connection was configured properly, the sequence 'CCCC' should be observed on the serial console terminal. 

Ads by Google

Powering ON Beaglebone Accessory

Inster the populated Micro SD card into the slot on the BeagleBone. Press the reset button, the following text should appear on the console.
 StarterWareAM335x Boot Loader
 Copying application image from MMC/SD card to RAM
 Jumping to StarterWare Application...
The accessory application holds the control

No comments:

Post a Comment

Thank You , For Immediate Assistance Plz Put Email Copy to