When you go with your laptop to a public place and you don't have a wi-fi connection available you can connect your cellphone in the USB port of your computer, turn on the USB tethering feature of your smartphone and you get full acess to the internet using your carrier data plan. The USB tethering uses the the RNDIS protocol and is easy to implement on a laptop.
But how to connect a Kinetis to the internet using a cellphone?
I'm sharing the the first version of the implementation I made of the RNDIS protocol.It's based in the KSDK 1.3 + MQX + LwIP and it can be used for reference in other projects. It's only a first release and I plan some additional implementation, bugfixes and support for other Kinetis boards in the near future but it already can be useful in some projects. Initially it only supports FRDM-K22F and FRDM-K64F but it can be implemented in any MCU with USB controller and enough FLASH. It's a low-cost and simple way to connect your MCU to the internet when you don't have a Ethernet cable available or an Wi-fi connection or a 4G module available in your board.
Introduction
This project implements the RNDIS protocol on the top of the USB Host Stack and in the bottom of the LwIP (TCP/IP stack). When a cellphone is connected to a freedom board, it acts as a USB device and the Freedom board acts as a host.


* Software implementation


* Cellphone connected to a FRDM-K64F providing internet connection to the board
The user can design his own software in the top of the TCP/IP stack (LwIP) like if it's connected through an ethernet cable.
Demonstration
To run the demo you will need the KDS 1.3 (www.nxp.com/kds).
To load all the projects needed to your project you have to extract the .zip file and in KDS go to File -> Import, Project of Projects -> Existing Project Sets, and browse to the *.wsd file present in the folder:
USB_RNDIS\KSDK_1.3.0\examples\[your board]\demo_apps\lwip\usb_tethering_demo\usb_tethering_demo_mqx\kds
It will import all the needed project in to your workspaces so you will be able to build all the projects and flash it into your board.
With the application flashed, open a Serial terminal with 115200kbps, 8N1 for the CDC interface of OpenSDA.When the board starts, it will display:


Connect your cellphone in to the USB of the MCU. After connect the phone turn on the USB tethering feature and wait some seconds:


The Freedom Board will be connected to the internet. As an example, this demo connects to an HTTP server in the internet, download to MCU some data (Lastest news from an newspaper website) and displays it through the Serial connection.


You can modify this demo for your own application, using the TCP/IP and UDP/IP provided by the LwIP.
Typical Aplications
- Low-cost temporary internet connectivity to the MCU.
- Remote updat (i.e.: bootloader through USB downloading the new firmware direct from the web)
- Remote control
- Remote diagnostics
Known Issues and Limitations:
- This first version was only full implemented for FRDM-K22F and FRDM-K64F. I can implement for other boards through requests.
- It was tested on Android Phones (Samsung Galaxy, Motorola G, Motorola X). I don't have a iPhone to test yet.
- Some cellphones need additional current to detect that is attached to a host.A external power is needed in this situation.For FRDM-K64F I suggest to use the J27 footprint to provide 5V and short the diode D13.
- Not all the RNDIS messages was implemented yet, only the most fundamental ones.
- There's a flash size limitation due the size of the TCP/IP stacks ( that requires a considerably space of flash). It can adapted in the future for stacks with smaller footprint.
- Only support KDS 3.0 at this time. And it only supports MQX at this time.
Let me know if you have any question. Hope it can be useful!
1- With the application flashed, open a Serial terminal with 115200kbps, 8N1 for the CDC interface of OpenSDA.When the board starts, it will display: