Welcome to the Moto Mods page on element14. Here you can find things such as our latest news, training videos, and product details. Additionally, you can engage with us in our forums.
Index of the Moto Mods Developer project:
Moto Mods Developer Part 1 - Getting Started - Virtual Machine Setup and Linux Install
Moto Mods Developer Part 2 - Getting Started - SDK Setup & Android Studio Install
Moto Mods Developer Part 3 - Firmware Setup
Moto Mods Developer Part 4 - Getting Started - Make Build-Folder, add Utility and OS files
Moto Mods Developer Part 5 - Flashing Firmware with MDK Utility
Moto Mods Developer Part 6 - Blinking an LED on the Moto Mods Perfboard
Moto Mods Developer Part 7 - Modifying the C file for the perfboard LED
Moto Mods Developer Part 8 - Configure Nuttx
Moto Mods Developer Part 9 - Updating the Hardware Manifests file
Moto Mods Developer Part 10 - Cont’d Configure and Compile Nuttx
Moto Mods Developer Part 11 - Load newly created Nuttx Firmware onto Reference Board
Moto Mods Developer Part 12 - Soldering the Test Points to use the perfboard
Moto Mods Developer Part 13 - Making custom App to control the Firmware
Switch to the new target, this will configure the defconfig in the blinky folder when we launch the Nuttx config tool. At the beginning we created the blinky folder.
$ cd $BUILD_TOP/nuttx/nuttx/tools
$ ./configure.sh hdk/muc/blinky
Enter the commands
In the Nuttx configuration we have to set up a few things to get the communication between the STM32 micro to work. First we turn on “Vendor Raw Support”. Navigate to each from the top menu and check
Device Drivers --->
[*] Greybus support --->
[*] Vendor Raw Support
System Type --->
STM32 Peripheral Support --->
[*] TIM6
Board Selection --->
Select target board (Motorola HDK MuC) --->
[*] Blinky LED Mods Raw support
Back. Scroll Down
After checking “Blinky LED Mods Raw support”. Exit
Next we will copy the “hdk-powered.mnfs” Hardware Manifest file and name it to “hdk-blinky.mnfs” Then configure it.
Enter the commands above.
Cabe
Index of the Moto Mods Developer project:
Moto Mods Developer Part 1 - Getting Started - Virtual Machine Setup and Linux Install
Moto Mods Developer Part 2 - Getting Started - SDK Setup & Android Studio Install
Moto Mods Developer Part 3 - Firmware Setup
Moto Mods Developer Part 4 - Getting Started - Make Build-Folder, add Utility and OS files
Moto Mods Developer Part 5 - Flashing Firmware with MDK Utility
Moto Mods Developer Part 6 - Blinking an LED on the Moto Mods Perfboard
Moto Mods Developer Part 7 - Modifying the C file for the perfboard LED
Moto Mods Developer Part 8 - Configure Nuttx
Moto Mods Developer Part 9 - Updating the Hardware Manifests file
Moto Mods Developer Part 10 - Cont’d Configure and Compile Nuttx
Moto Mods Developer Part 11 - Load newly created Nuttx Firmware onto Reference Board
Moto Mods Developer Part 12 - Soldering the Test Points to use the perfboard
Moto Mods Developer Part 13 - Making custom App to control the Firmware
Modifying the C file for the perfboard LED
The C file uses a receiver function that listens for data from an Android application using the Raw protocol.
This function we will leave the same.
{gallery} Modifying C File for PerfBoard |
---|
C Programming: Change the variable “GPIO_MODS_LED_DRV_3” at 4 places in the file to drive our GPIO pin named “GPIO_MODS_DEMO_ENABLE” |
C Programming: Change the variable “GPIO_MODS_LED_DRV_3” at 4 places in the file to drive our GPIO pin named “GPIO_MODS_DEMO_ENABLE” |
C Programming: Change the variable “GPIO_MODS_LED_DRV_3” at 4 places in the file to drive our GPIO pin named “GPIO_MODS_DEMO_ENABLE” |
C Programming: : Change the variable “GPIO_MODS_LED_DRV_3” at 4 places in the file to drive our GPIO pin named “GPIO_MODS_DEMO_ENABLE” |
C Programming: : I’ve made the blink faster by changing the “BLINKY_PERIOD” from 1000 to 500. Pin variable |
C Programming: : I’ve made the blink faster by changing the “BLINKY_PERIOD” from 1000 to 500. Pin variable |
C Programming: : The original file used this pin, so we will comment it out |
C Programming: : Now that we have changed the C file for our use with PG10. Hit Save, in the window. |
Index of the Moto Mods Developer project:
Moto Mods Developer Part 1 - Getting Started - Virtual Machine Setup and Linux Install
Moto Mods Developer Part 2 - Getting Started - SDK Setup & Android Studio Install
Moto Mods Developer Part 3 - Firmware Setup
Moto Mods Developer Part 4 - Getting Started - Make Build-Folder, add Utility and OS files
Moto Mods Developer Part 5 - Flashing Firmware with MDK Utility
Moto Mods Developer Part 6 - Blinking an LED on the Moto Mods Perfboard
Moto Mods Developer Part 7 - Modifying the C file for the perfboard LED
Moto Mods Developer Part 8 - Configure Nuttx
Moto Mods Developer Part 9 - Updating the Hardware Manifests file
Moto Mods Developer Part 10 - Cont’d Configure and Compile Nuttx
Moto Mods Developer Part 11 - Load newly created Nuttx Firmware onto Reference Board
Moto Mods Developer Part 12 - Soldering the Test Points to use the perfboard
Moto Mods Developer Part 13 - Making custom App to control the Firmware
After the tools are all setup, there is a file structure in Linux that we build the target firmware with. We will be modifying Motorola’s “Hello World” example to blink an LED. This example modifies the C file that runs the built in LED on the Reference Moto Mod when the switch in MDK utility is turned ON. Motorola give us a few configurations as an example of using Nuttx. First we need to copy and example configuration to a new folder, this is so we have a folder for our project with the “blinky” configuration.
We will create a new target for build called “blinky”
$ cd $BUILD_TOP/nuttx/nuttx/configs/hdk/muc
$ mkdir blinky
$ cp base_powered/* blinky/
The folder is created
We will configure these files later, next we have to modify the stm32_modsraw_blinky.c file to blink the right pin on the Moto Mods perfboard. We can also adjust the blink timing by modifying some #defines. The file is located in our project folder ./nuttx/nuttx/configs/hdk/muc/src
Before we edit the C file. We should create a backup of the original, copy the file to the same folder and it should automatically save it as “stm32_modsraw_blinky (copy).c”
Open the original “stm32_modsraw_blinky.c”. Inside the C file, we can see which header files are used for this file. What we want to do is modify this file so that we can activate a pin on the perfboard, turn it on and off with the timing setup. First we have to make sure the pin is setup properly. Located in the ./nuttx/nuttx/configs/hdk/muc/include folder is a header file that defines the variable pin names for the board, called mods.h
Already located in “stm32_modsraw_blinky.c” is a pin named “GPIO_MODS_DEMO_ENABLE” this is used as an example in the code. It is assigned to GPIO pin PG10. We will use this as the blinky pin. The unmodified C file blinks the “GPIO_MODS_LED_DRV_3” pin which is the pin that drives the built-in LED on the Reference Moto Mod as pictured below:
PG10 is a general GPIO pin that is open for our use. This is according to the STM32 Micro pinout chart provided by Motorola, shown below.
BLINKY CODE::::
/* * Copyright (c) 2016 Motorola Mobility, LLC. * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright notice, * this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived from this * software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <errno.h> #include <debug.h> #include <stdlib.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <arch/board/mods.h> #include <nuttx/arch.h> #include <nuttx/device.h> #include <nuttx/device_raw.h> #include <nuttx/power/pm.h> #include "stm32_tim.h" #define BLINKY_ACTIVITY 10 #define BLINKY_TIM 6 #define BLINKY_TIM_FREQ 1000 #define BLINKY_PERIOD 1000 #define LED_ON 0 #define LED_OFF 1 static struct stm32_tim_dev_s *tim_dev; static int blinky_timer_handler(int irq, FAR void *context) { uint8_t new_val; pm_activity(BLINKY_ACTIVITY); STM32_TIM_ACKINT(tim_dev, 0); new_val = gpio_get_value(GPIO_MODS_LED_DRV_3) ^ 1; gpio_set_value(GPIO_MODS_LED_DRV_3, new_val); llvdbg("new_val=%d\n", new_val); return 0; } static void blinky_timer_start(void) { gpio_set_value(GPIO_MODS_DEMO_ENABLE, 1); if (!tim_dev) { dbg("BLINKY\n"); tim_dev = stm32_tim_init(BLINKY_TIM); DEBUGASSERT(tim_dev); STM32_TIM_SETPERIOD(tim_dev, BLINKY_PERIOD); STM32_TIM_SETCLOCK(tim_dev, BLINKY_TIM_FREQ); STM32_TIM_SETMODE(tim_dev, STM32_TIM_MODE_PULSE); STM32_TIM_SETISR(tim_dev, blinky_timer_handler, 0); STM32_TIM_ENABLEINT(tim_dev, 0); } else { dbg("ignore\n"); } } static void blinky_timer_stop(void) { gpio_set_value(GPIO_MODS_DEMO_ENABLE, 0); if (tim_dev) { dbg("STOP\n"); STM32_TIM_DISABLEINT(tim_dev, 0); stm32_tim_deinit(tim_dev); tim_dev = NULL; gpio_set_value(GPIO_MODS_LED_DRV_3, LED_OFF); } else { dbg("ignore\n"); } } static int blinky_recv(struct device *dev, uint32_t len, uint8_t data[]) { if (len == 0) return -EINVAL; if (data[0] == 0 || data[0] == '0') blinky_timer_stop(); else blinky_timer_start(); return 0; } static int blinky_register_callback(struct device *dev, raw_send_callback callback) { /* Nothing to do */ return 0; } static int blinky_unregister_callback(struct device *dev) { /* Nothing to do */ return 0; } static int blinky_probe(struct device *dev) { gpio_direction_out(GPIO_MODS_LED_DRV_3, LED_OFF); gpio_direction_out(GPIO_MODS_DEMO_ENABLE, 0); return 0; } static struct device_raw_type_ops blinky_type_ops = { .recv = blinky_recv, .register_callback = blinky_register_callback, .unregister_callback = blinky_unregister_callback, }; static struct device_driver_ops blinky_driver_ops = { .probe = blinky_probe, .type_ops = &blinky_type_ops, }; struct device_driver mods_raw_blinky_driver = { .type = DEVICE_TYPE_RAW_HW, .name = "mods_raw_blinky", .desc = "Blinky LED Raw Interface", .ops = &blinky_driver_ops, };
Index of the Moto Mods Developer project:
Moto Mods Developer Part 1 - Getting Started - Virtual Machine Setup and Linux Install
Moto Mods Developer Part 2 - Getting Started - SDK Setup & Android Studio Install
Moto Mods Developer Part 3 - Firmware Setup
Moto Mods Developer Part 4 - Getting Started - Make Build-Folder, add Utility and OS files
Moto Mods Developer Part 5 - Flashing Firmware with MDK Utility
Moto Mods Developer Part 6 - Blinking an LED on the Moto Mods Perfboard
Moto Mods Developer Part 7 - Modifying the C file for the perfboard LED
Moto Mods Developer Part 8 - Configure Nuttx
Moto Mods Developer Part 9 - Updating the Hardware Manifests file
Moto Mods Developer Part 10 - Cont’d Configure and Compile Nuttx
Moto Mods Developer Part 11 - Load newly created Nuttx Firmware onto Reference Board
Moto Mods Developer Part 12 - Soldering the Test Points to use the perfboard
Moto Mods Developer Part 13 - Making custom App to control the Firmware
Flashing Firmware with MDK Utility
Flashing the firmware can be done in two ways, using the MDK Utility Android App (APK) which can be downloaded from the MotorolaMobilityLLC github repository or the Google Play Store. Or you can use OpenOCD to flash bootloader and firmware. We will use the Android app method.
In order to flash using the MDK Utility on the Motorola Z Droid. We need to check some parameters in our configuration. Enter:
$ cd ./nuttx/nuttx
$ make menuconfig
Once executed, a text based menu system in the terminal will pop up showing you the config menu. Navigate to the “Device Drivers” menu and make sure the parameters below are checked. Leave all other settings how they are, when finished, exit.
Device Drivers -->
Greybus support (GREYBUS [=y])
[*] Mods Protocol
[*] Support APK update of firmware
Now back in the terminal, we need to compile the bootloader, enter
$ cd /home/username/MotoModsFirmware/muc-loader
$ ./configure hdk/developer
$ make
This will create a file called ‘defconfig’, in the ./MotoModsFirmware/muc-loader/configs/hdk/developer directory. We need to check this file for a similar parameter.
CONFIG_GREYBUS_MODS_SUPPORT_VENDOR_UPDATES=y
Open the file using the explorer or terminal and the last parameter should be ‘y’. As highlighted below:
Close file, and plug in phone. We will transfer the generated firmware executable file to the phone so that the MDK Utility can flash it to the MuC. This can be also done but loading it onto an SD card and plugging that into the phone.
The device will show in the file explorer
Make sure the phone is in File Transfer Mode (MTP)
Navigate to ./MotoModsFirmware/nuttx/nuttx, where the output files were generated. We will ‘Copy To…’ the “nuttx.tftf” file to the phone. Lets save it in the /Downloads directory
Hit Select
Now that the .tftf file is on the phone we are ready to flash using the MDK Utility
On the phone, open your MDK Utility app
In the Mode section, make sure you are in “Developer mode” for firmware flashing. If not, hit “SET MODE” and select, “Developer Mode”.
Click “SELECT FILES” and navigate to the ‘./Download’ folder we saved the .tftf file on the phone.
Select “nuttx.tftf” and hit “PERFORM UPDATE”
Click Continue
Now the firmware is flashed, you can see that the firmware is a Blinky program that tests the built-in LED on the Reference Moto Mod. The LED is located above the personality card slot. You can toggle the “MDK LED Light” switch to turn on or off the blink. The light should illuminate for 1 second ON and 1 second OFF. You can Eject/unmount and unplug the phone.
Ta-da!
Index of the Moto Mods Developer project:
Moto Mods Developer Part 1 - Getting Started - Virtual Machine Setup and Linux Install
Moto Mods Developer Part 2 - Getting Started - SDK Setup & Android Studio Install
Moto Mods Developer Part 3 - Firmware Setup
Moto Mods Developer Part 4 - Getting Started - Make Build-Folder, add Utility and OS files
Moto Mods Developer Part 5 - Flashing Firmware with MDK Utility
Moto Mods Developer Part 6 - Blinking an LED on the Moto Mods Perfboard
Moto Mods Developer Part 7 - Modifying the C file for the perfboard LED
Moto Mods Developer Part 8 - Configure Nuttx
Moto Mods Developer Part 9 - Updating the Hardware Manifests file
Moto Mods Developer Part 10 - Cont’d Configure and Compile Nuttx
Moto Mods Developer Part 11 - Load newly created Nuttx Firmware onto Reference Board
Moto Mods Developer Part 12 - Soldering the Test Points to use the perfboard
Moto Mods Developer Part 13 - Making custom App to control the Firmware
Be sure to go over the first parts of this series before working on this one.
Now that we have the utilities setup for flashing and Debugging the firmware, we need to build and compile the firmware for the MuC. The Firmware runs Nuttx OS which is an RTOS with STMicro STM32L476 support.
Make Build Folder, Add utility and OS files
Make directory called “MotoModsFirmware” with ownership to store build files:
$ mkdir /home/username/MotoModsFirmware
Download the Source code into your directory. We need to give our username ownership of the clone folders so we can access them.
$ cd ./MotoModsFirmware/
$ export BUILD_TOP=`pwd`
$ git clone https://github.com/MotorolaMobilityLLC/nuttx
$ git clone https://github.com/MotorolaMobilityLLC/manifesto
$ git clone https://github.com/MotorolaMobilityLLC/muc-loader
$ git clone https://github.com/MotorolaMobilityLLC/bootrom-tools
$ git clone https://github.com/MotorolaMobilityLLC/mdkutility
Build kconfig-mconf, Nuttx uses the same configuration editor that is used to build the Linux Kernel.
$ cd /home/<username>/MotoModsFirmware/nuttx/misc/tools/kconfig-frontends
$ ./configure --enable-mconf --disable-nconf --disable-gconf --disable-qconf
$ make
$ sudo make install
$ sudo ldconfig
$ cd /home/<username>/MotoModsFirmware
$ export PATH=$PATH:/home/<username>/MotoModsFirmware/manifesto:/home/<username>/Moto
ModsFirmware/bootrom-tools
$ cd ./nuttx/nuttx
$ make distclean
$ cd ./tools
$ ./configure.sh hdk/muc/base_unpowered
At this point the configs/hdk/muc/base_unpowered/defconfig will be copied to ./MotoModsFirmware/nuttx/nuttx/.config and the setenv.sh and Make.defs file from that same directory will be copied up to ./MotoModsFirmware/nuttx/nuttx.
$ cd ./nuttx/nuttx
$ make
The firmware output is located in the nuttx.bin, nuttx.hex and nuttx.tftf files in the /MotoModsFirmware/nuttx/nuttx Directory. We will use these later.
Have a story tip? Message me at: cabe(at)element14(dot)com
Index of the Moto Mods Developer project:
Moto Mods Developer Part 1 - Getting Started - Virtual Machine Setup and Linux Install
Moto Mods Developer Part 2 - Getting Started - SDK Setup & Android Studio Install
Moto Mods Developer Part 3 - Firmware Setup
Moto Mods Developer Part 4 - Getting Started - Make Build-Folder, add Utility and OS files
Moto Mods Developer Part 5 - Flashing Firmware with MDK Utility
Moto Mods Developer Part 6 - Blinking an LED on the Moto Mods Perfboard
Moto Mods Developer Part 7 - Modifying the C file for the perfboard LED
Moto Mods Developer Part 8 - Configure Nuttx
Moto Mods Developer Part 9 - Updating the Hardware Manifests file
Moto Mods Developer Part 10 - Cont’d Configure and Compile Nuttx
Moto Mods Developer Part 11 - Load newly created Nuttx Firmware onto Reference Board
Moto Mods Developer Part 12 - Soldering the Test Points to use the perfboard
Moto Mods Developer Part 13 - Making custom App to control the Firmware
Be sure to see Part 1 of the Moto Mod Developer series, click this link.
Then see Part 2 after this link.
A wrong move means bigtime headaches. Follow it exactly. Then come on back here.
In order to build and compile the firmware we need to setup Ubuntu for USB/FTDI Libraries, OpenOCD, and GDB. Then install each utility, respectively.
Setup Ubuntu for Firmware building
In Ubuntu terminal type,
$ sudo apt-get install -y git gperf flex bison libncurses5-dev gcc-arm-none-eabi python-pip
$ sudo pip install pyelftools
This will install Ubuntu's package management system used for building the flashing and debugging tools.
Install USB, FTDI libraries, and OpenOCD for USB JTAG emulation
This tool allows us to flash the firmware to MuC and debug it with GDB. This is using the USB C cable plugged into USB C slot #1 on the side of the Reference Moto Mod, which is used for programming/debugging.
$ sudo apt-get install -y libusb-1.0-0-dev libftdi-dev libtool autoconf texinfo
$ git clone https://github.com/MotorolaMobilityLLC/openocd
$ cd openocd
$ git submodule init
$ git submodule update
$ ./bootstrap
$ ./configure --prefix=/usr/local
$ make
$ sudo make install
$ cd -
Note: If you are using Ubuntu 16.10 or later, you will need to install gcc-5 (sudo apt install gcc-5) and add "CC=gcc-5" to the above ./configure statement. This is only required for OpenOCD.
This will install libUSB and libftdi.
libUSB is a C library that provides generic access to USB devices
libftdi is an open source library used to talk to FTDI devices
Since OpenOCD uses the USB, we need to grant permissions to your linux username so it can use the FTDI. Enter the commands below in terminal:
$ id -u -n
$ sudo -s
# echo 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="0403", MODE="0666", OWNER="<user name>"' >> /etc/udev/rules.d/20-ftdi.rules
# udevadm control --reload
# exit
Install GDB for low-level Debugging
The MDK provides utilities for using GDB, we will install with the commands below:
$ sudo apt-get install -y libexpat1-dev zlib1g-dev guile-2.0-dev python2.7-dev
$ wget http://ftp.gnu.org/gnu/gdb/gdb-7.11.tar.gz
$ tar -zxf gdb-7.11.tar.gz
$ cd gdb-7.11
$ ./configure --prefix=/usr/local --program-prefix=arm-none-eabi- --target=arm-none-eabi --with-python --with-guile
$ make
$ sudo make install
Index of the Moto Mods Developer project:
Moto Mods Developer Part 1 - Getting Started - Virtual Machine Setup and Linux Install
Moto Mods Developer Part 2 - Getting Started - SDK Setup & Android Studio Install
Moto Mods Developer Part 3 - Firmware Setup
Moto Mods Developer Part 4 - Getting Started - Make Build-Folder, add Utility and OS files
Moto Mods Developer Part 5 - Flashing Firmware with MDK Utility
Moto Mods Developer Part 6 - Blinking an LED on the Moto Mods Perfboard
Moto Mods Developer Part 7 - Modifying the C file for the perfboard LED
Moto Mods Developer Part 8 - Configure Nuttx
Moto Mods Developer Part 9 - Updating the Hardware Manifests file
Moto Mods Developer Part 10 - Cont’d Configure and Compile Nuttx
Moto Mods Developer Part 11 - Load newly created Nuttx Firmware onto Reference Board
Moto Mods Developer Part 12 - Soldering the Test Points to use the perfboard
Moto Mods Developer Part 13 - Making custom App to control the Firmware
Believe me, developing on the Moto Mod platform is not for the faint of heart. Be sure to see Part 1 of the Moto Mod Developer series, click this link. A wrong move means bigtime headaches. Follow it exactly. Then come on back here.
Part 2
Install JDK and Android Studio
This tutorial will show you how to Install JDK, Android Studio, and the Moto Mods SDK on Ubuntu 16.04
Android Studio requires the Java Development Kit (JDK) so we will install that first. In terminal, type “sudo apt-add-repository ppa:webupd8team/java”. Follow the terminal commands shown
Once the installer is done, type “javac -version” and “java -version” to check if the JDK was installed.
Now that JDK is installed, we can now install Android Studio in Ubuntu VM, open firefox and download Android Studio
Save the file and extract it
Create a folder called Apps in the /home/<username> directory. Move the extracted folder in the /home/<username>/Apps, using right click->Move To...
In terminal, navigate to the directory and execute “./studio.sh”. Shown above. If you get a permissions error then, Navigate to Android Studio’s directory bin folder, give yourself permission for the .sh file and execute it
This is a new copy, Select the second option
Android Studio will launch
The Android Studio Welcome will show, click Next
Choose Standard Installation
Click Next
Hit Finish
Android Studio is now installed
Setup Moto Mods Project in Android Studio
Start a new Android Studio Project and configure your application name
Set Android API version to 6.0 (API level 23), Moto Mods only supports API level 23+ (Android 6.0+). It does not support earlier versions of Android.
It will install API23: Android 6.0 SDK
Create an empty activity
For beginning Moto Mods Development we will start with a Blinky application
Click Finish
Finally, the Android Studio Blinky application is setup, ready for development.
Install Moto Mods SDK
Now that Android Studio is installed and a project is created we need to add the Moto Mods SDK to the newly created project so that we can make API calls to the Reference Moto Mod
Download the Mod Mods SDK Library. Provided at: https://developer.motorola.com/build/tools/setup-environment
Save the ZIP file.
In your downloads folder, Right click on the “ModLib-01.00.000.zip” and hit “Extract Here”
Once the ZIP is extracted, Right click and “Move To….”
Navigate to ‘/home/<username>’ and hit select
Once moved, open the “ModLib-01.00.000” folder and Move or Copy To…
Now we will put the SDK into our Android Studio Project. Move the .jar file into the /libs folder of our created project. ‘/home/<username>/AndroidStudioProjects/MotoModsDevelopment-Blinky/app/libs’
In the /res folder of /ModLib-01.00.000 there is a version.xml file that we need to move as well. Hit Move or Copy To...
Move or Copy “version.xml” to ‘/home/<username>/AndroidStudioProjects/MotoModsDevelopment-Blinky/app/src/main/res/values’
Shown below is how the “modlib-01.00.000.jar” and “version.xml” should look in the project explorer tree.
The SDK is now added to the project and we can start using it to develop.
Index of the Moto Mods Developer project:
Moto Mods Developer Part 1 - Getting Started - Virtual Machine Setup and Linux Install
Moto Mods Developer Part 2 - Getting Started - SDK Setup & Android Studio Install
Moto Mods Developer Part 3 - Firmware Setup
Moto Mods Developer Part 4 - Getting Started - Make Build-Folder, add Utility and OS files
Moto Mods Developer Part 5 - Flashing Firmware with MDK Utility
Moto Mods Developer Part 6 - Blinking an LED on the Moto Mods Perfboard
Moto Mods Developer Part 7 - Modifying the C file for the perfboard LED
Moto Mods Developer Part 8 - Configure Nuttx
Moto Mods Developer Part 9 - Updating the Hardware Manifests file
Moto Mods Developer Part 10 - Cont’d Configure and Compile Nuttx
Moto Mods Developer Part 11 - Load newly created Nuttx Firmware onto Reference Board
Moto Mods Developer Part 12 - Soldering the Test Points to use the perfboard
Moto Mods Developer Part 13 - Making custom App to control the Firmware
The Moto Mods expansion for the Moto Z phones is not for the average tinkerer.
I set out to do the "hello world" of hardware design, blink an LED. Once you can do that, sky's the limit.
So, let's start from the beginning, part 1, getting set up:
To setup everything you need to develop with Moto Mods i’ve split this setup tutorial into 2 articles. The first one showing you how to setup Android studio and the Moto Mods SDK in Linux, which requires the setup of a virtual machine if using any other OS. The second article, showing you how to install all the firmware tools you will need for development.
Two software tools are required for developing on Moto Mods platform: Android Studio 2.0+ and the Moto Mods SDK Library. Your application can be made on any Android Studio platform. Firmware development at this point requires Linux. To develop the firmware using windows, we will setup a Virtual Machine (VM) using VirtualBox and version 16.04 of Ubuntu.
A little background about what we're about to do. In order to develop with Moto Mods, we need to install and configure:
These tools are all provided from the github repository: https://github.com/MotorolaMobilityLLC
The Mod Mods MDK comes with a backplate pictured below that attaches to the back of the Moto Z Droid via magnets and pogo pins. This Adapter, they call a reference Moto Mod, pictured on the right, that attaches directly to the phone and has a slot and connector for prototyping with anyone of the personality cards. The Perforated Board is then plugged into the connector on the reference Moto Mod, then the cover over that, pictured on the left. The Reference Board is where we will load the firmware. Built in is an Cortex-M4 based STML476, it provides onboard control of the GPIO and various standard interfaces.
From Moto Mods Developer Website:
“The example Personality Cards require custom firmware on the Reference Moto Mod to run. Each Personality Card includes an onboard EEPROM queried by the MuC (STML476) bootloader on attach. If needed, the MuC bootloader will request the Moto Z to download and install the latest firmware needed for the attached personality card.
IMPORTANT:
When using the Perforated Board, or Pi HAT Adapter Board, don’t forget to create a custom bootloader for your MuC that includes your unique VID/PID, or the prototype VID 0x42. If you don’t you’ll end up overwriting your custom firmware with the default MuC firmware each time you boot!”
Install Ubuntu on a Virtual Machine
Download VirtualBox from the link above, since we are using Windows, download from the “Windows hosts” link
Once VirtualBox is installed, open VirtualBox Manager
Create a name for you Virtual Machine and select Linux as the Type of OS and the Version as Ubuntu (64-bit)
Hit Next, Ubuntu recommends at least 2 GB of Virtual RAM.
Ubuntu recommends at least 25GB of HD space and a minimum of 10GB but we are going to install programs so we don’t run out of space during the setup process. Ignore that 8GB
Create a Virtual HD, choose VDI (Virtual Disk Image)
Dynamically allocate the disk so you save space on your real drive.
I created a disk with 30GB of space.
Once you hit create, the VM is done being set up. We now have to install Linux on it, We do this the same as a fresh copy of Windows. Boot from disk, but it's a virtual disk image.
Go back to your browser... Since we are using 64-bit Windows, we will run 64-bit Ubuntu on our VM, download the “Ubuntu 16.04.2 LTS Desktop Image”. At this time, it will download an ISO file called “ubuntu-16.04.2-desktop-amd64.iso”
Back in your VM manager settings, Click on the Small CD symbol to the right of the Optical Drive: selection and in the dropdown select “Choose Virtual Optical Disk File...”
Open “ubuntu-16.04.2-desktop-amd64.iso”
It will load the ISO file into the VM IDE Storage Controller. Click Ok. This will allow us to boot from the Ubuntu disk image
.
Start the VM, and the GUI screen will pop up.
When the GUI pops up it will go to the Ubuntu install screen.
Hit “Install Ubuntu” and Continue, we don’t install updates because we are going to install all the tools and we want make sure versions stay the same.
Choose “Erase Disk and Install Ubuntu”, and hit “Install Now”
This will partition the VDI drive, Install Ubuntu on the “VirtualBox Disk Image” file that has the name Moto Mods Development.vdi ,and it is about 8GB in size. Click Continue.
Select English
Fill out fields and choose, “Log in automatically”, click continue
Ubuntu will Install….
After installation is complete, hit “Restart Now”
The VM will reboot and Ubuntu will show Desktop, Firefox and terminal are pre-installed. We will use these to install Android Studio, Moto Mods SDK, and the Firmware tools using installer code copied from the Moto Mods Developer website.
Launch Terminal from the search (Purple Ubuntu symbol button)
This details the steps to use the usb2 sample project with your Moto Mods Development Kit. Hat tip to Screen mirroring a Moto Z to HDMI, with the Moto Mod Development Kit (MDK) for the structure (and the great details).
The firmware used is the unmodified MDK-USB2 example. This is the usb2 project in nuttx/configs/muc.
$ export PATH=$PATH:$BUILD_TOP/manifesto:$BUILD_TOP/bootrom-tools
$ cd $BUILD_TOP/nuttx/nuttx
$ make distclean
$ cd $BUILD_TOP/nuttx/nuttx/tools
$ ./configure.sh hdk/muc/usb2
$ cd $BUILD_TOP/nuttx/nuttx
$ make
Name | MDK-USB2 |
VID | 0x00000042 |
PID | 0x00000001 |
Firmware | 0x00000001 |
Package Name | Default |
Note: USB 2.0 devices can also be used through the USB #2 (TypeC middle port on the MDK). You will need a TypeC OTG cable. When using the TypeC port for USB 2.0, set A4 to ON and all other dip switches OFF.
Really Note: The TypeC port does not auto-swap. If things should be working but aren't, try flipping the cable over.
After much messing around I've achieved my initial goal: getting the Moto Z to display on an HDTV.
I assert this firmware was built by me from Motorola sources. However I've not tested beyond a single trial, which seemed to work. It could brick your MDK, or your phone, or your TV, kill your dog and burn your house to the ground.
If you are in any way uncertain about this procedure, or the firmware then click Cancel.
Name | MDK-COMPUTE |
VID | 0x00000042 |
PID | 0x00000001 |
Firmware | 0x00000001 |
Package Name | Default |
It is the unmodified MDK COMPUTE example.
$ export PATH=$PATH:$BUILD_TOP/manifesto:$BUILD_TOP/bootrom-tools
$ cd $BUILD_TOP/nuttx/nuttx
$ make distclean
$ cd $BUILD_TOP/nuttx/nuttx/tools
$ ./configure.sh hdk/muc/compute
$ cd $BUILD_TOP/nuttx/nuttx
$ make