Monthly Archives: August 2018

Linkit Smart 7688 OpenWRT 18.06 and I2C

The I2C bus is a bus is used to interface with small sensor devices in a system. Recently I needed to collect data from an MCP3424 ADC using the Linkit Smart 7688. The Linkit ships with the OpenWRT CC 15.05 firmware which now is 3+ years old, so I wanted to use a more updated system. Lucky for me, OpenWRT just released 18.06 this month, the first release where OpenWRT and LEDE re-aligned. I installed the 18.06 firmware on the Linkit, however the default build doesn’t have the I2C drivers. Here are the steps to get the I2C bus working on OpenWRT 18.06 on the Linkit Smart 7688.

opkg update
opkg install kmod-i2c-code kmod-i2c-mt7628
lsmod (Ensure the new modules are is loaded)
ls /dev/ (List the devices in /dev)

After running the ‘ls /dev/’ command you should see the i2c-0 device listed. This device file controls the hardware connected to the SCL and SDA pins. Use the fopen, ioctl commands in C to control the port. WARNING: The Linkit I2C driver appears to always respond with a valid return integer. This is different than other drivers, which will respond with success for an ACK message and failure integers for a NACK message. Take a look at the elinux info on I2C here:

LinkIt Smart 7688 Toolchain with OpenWRT

My last post was about how to get the LinkIt Smart 7688 embedded Linux module running and updating the firmware. This post in the series is going to explain the next step in the embedded development sequence, getting a cross compiler GCC toolchain working for the target to start developing software in C and C++.

A cross compiling toolchain is a crucial piece in any embedded development effort. While the LinkIt has programming languages built in such as python, lua, and node, many times system programmers need a native C/C++ toolchain to program low level fast systems. Many embedded platforms, such as the RaspberryPi, come with a toolchain already built and running on the system. This is handy for quick development but you are limited to compiling on the target processor, in this case 580MHz which can be a slow and painful process. A cross compiler is a compiler that runs on a PC and generates binary programs that run on a different machine. The LinkIt is a MIPS processor, so we need a compiler that runs on a typical PC (Most likely x86_64) and generates programs that run on MIPS.

The OpenWRT SDK Toolchain

OpenWRT’s build system is based on Buildroot, a set of tools for generating embedded Linux systems. The Buildroot system downloads all the packages needed for a system, compiles them for the target and builds an image. To compile the packages Buildroot downloads and makes a cross compiler toolchain which we can use for our system! OpenWRT does a great job of putting all the toolchain pieces together in an SDK when the image is built. Because the LinkIt is based on the ramips target of the 15.01 Chaos Calmer, the SDK is available on the build root servers. You can find the packages here: . On a 64bit Linux system, simply download the OpenWrt-SDK-15.05.1-ramips-mt7688_gcc-4.8-linaro_uClibc- file and decompress it. Windows cross compilers do exist or can be built but are outside of the scope of this post.

The OpenWRT SDK contains the GCC compiler, plus all the other tools needed to link and package binary files. The SDK also contains all the libraries required to link a Linux application such as the C library (LibC), pthreads, librt, etc. You will find the tools in the following locations in the bz2 package:

  • GCC Compiler: staging_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-
  • GCC libraries (RFS): staging_dir/target-mipsel_24kec+dsp_uClibc-

Using the Toolchain

Lets make a ‘hello world’ application for the LinkIt with the OpenWRT SDK toolchain. Create a test file:

int main(int argc, char ** argv)
printf(“Hello world\n”);
return 0;

Now compile the test program with the toolchain from the SDK:

<PATHTOBIN>/mipsel-openwrt-linux-gcc -c test.c -o test.bin

There should be no errors or warnings when you do the compile, and the output will be test.bin, an application that will only run on the LinkIt. The compiler also wanted the STAGING_DIR environment variable set with ‘export STAGING_DIR=<PATHTOSTAGINGDIR>’. You can confirm that the binary is for MIPS with the ‘file’ command:

file test.bin

Simply copy the binary file to the Linkit /root/ directory and run with ./test.bin. If your Linkit is connected to the network you can copy using scp.

scp test.bin root@<IP_ADDRESS>:/root/

Running the binary with ./test.bin from the /root/ directory and you should see the “Hello world” output.