There’s a stack for that: FNET provides TCP/IP protocol

by Tom Thompson , TechOnline India - August 17, 2011

One popular request has been for a stand-alone TCP/IP stack suitable for embedded devices. Freescale does provide such a TCP/IP stack in its MQX real-time OS and its Linux-based Board Support Packages (BSPs).

One of the many hats I wear at Freescale is that of administrator for Freescale’s technical support forums. These are on-line boards where developers and designers can ask questions about our software tools and parts. Often the community of developers and designers that frequent these forums can provide answers for these questions.

Besides a place to seek help, the forums are also an ideal place to spot trends. One popular request has been for a stand-alone TCP/IP stack suitable for embedded devices. Freescale does provide such a TCP/IP stack in its MQX real-time OS and its Linux-based Board Support Packages (BSPs). However, a lot of embedded system products do not need a full-blown operating system:  yet they still need to connect to other devices. The network connection might allow a device to “phone home” the status of its operating health to a company server, or to enable tech support to “push” a new version of the firmware to devices already in the field.

Fortunately, Freescale does have an embedded TCP/IP protocol stack, called—not surprisingly—FNET. Importantly, it is a complete, stand-alone implementation. That is, the code is self-contained and does not require an operating system or other libraries in order to function. FNET is written primarily in C, with an emphasis on the code being both modular and portable. Small sections of the stack are written in assembly language to take advantage of processor-specific optimizations. Best of all, FNET is open source (under the dual GNU LGPL/GPLv3 license with the linking exception), which means that you can adapt the source for your particular embedded product design.

FNET is available for several ColdFire processors (the MCF5282, MCF52235, MCF52259, and MCF51CN128) and for a Kinetis processor, the MK60N512.


FNET overview

Figure 1 shows the basic organization of the software modules that comprise FNET. First there is the FNET TCP/IP protocol stack itself. On an Ethernet interface, it supports key portions of the Internet Protocol Suite, including UDP, TCP, IP, ICMP, and ARP. A loopback interface is also provided for diagnostic testing.

                   

Figure 1: The FNET stack and its service modules


You access and operate the FNET TCP/IP stack through a BSD-like non-blocking socket layer API. This allows you to port existing network software based on BSD sockets to FNET.

You access and operate the FNET TCP/IP stack through a BSD-like non-blocking socket layer API. This allows you to port existing network software based on BSD sockets to FNET.

The FNET source also provides a number of services packages that can add useful network capabilities to a device. The services include:

HTTP server —It supports HTTP 1.0 and 0.9, POST and GET requests, CGI and SSI execution
DHCP client—It obtains an IP address and other network characteristics for the device
Telnet server—Allows remote hosts to connect to the device and issue commands
TFTP client and server—Allows files to be transferred to and from the device
Shell service—Provides a command line interface that can be used to start the other FNET services, such the HTTP server
Flash driver—Lets you read and write to on-chip flash memory
ROM File system—Allows access to files using file I/O APIs similar to those found in ANSI C and POSIX
Serial driver—Implements standard I/O functions like printf(), putchar() and getchar() on the serial port of the device.

As the figure shows, six of the FNET services are managed through a polling mechanism. The application must invoke this mechanism periodically during its idle time so that these services can operate properly in the background. The flash driver, ROM file system, and serial driver operate independently of the polling mechanism.

The sum of its parts

 Beyond simple network connectivity, FNET really shows its stuff when you combine FNET services with its TCP/IP stack to construct useful network tasks. For example, using the TFTP server, ROM file system, and flash driver services, FNET can implement an Ethernet-based bootloader. This bootloader capability has been field tested, and it frequently serves as the bootloader for MQX RTOS applications. Besides downloading a firmware image into flash, the bootloader can also read flash and copy the image file to a remote server for diagnostic work or to make a backup copy.

The bootloader can be configured for several modes of operation. After the download completes, it can leave the device at the command shell prompt. Or, it can jump to the firmware’s entry point so that the device restarts with new firmware—something you would want the device to do for an in-the-field update. Alternatively, it can execute a command script that might perform some housekeeping functions or report status.

Although the Ethernet bootloader is probably one of the FNET stack’s often-used capabilities, the other services have been useful with embedded applications that require network connectivity. For example, one company uses FNET to not only distribute software updates to numerous devices, but to monitor their performance and provide information that supports back-office accounting operations. Another company uses FNET to control the robots in car-washing machines. FNET has also found use in the smart grid meters for a power company.

Building FNET

Because FNET is a self-contained stack, it is easy to incorporate FNET into an embedded application. You download the installer, add the code to your project, configure certain FNET header files, and build. However, the application must enable interrupts as FNET requires interrupts from the host processor’s Ethernet and timer modules. You can use Freescale’s own CodeWarrior Development Studio tools, or IAR Systems’ Embedded Workbench tools to build the FNET stack and its services.

Besides the source code and documentation, the installer also provides several example applications and some utility programs. The example applications consist of a bootloader, a TCP/UDP throughput benchmark application, and a shell application. The shell application allows you to issue commands that can start a Telnet session, a DHCP search, and an HTTP server complete with Web pages to display. The detailed FNET documentation explains, step-by-step, how to build and test the applications. The GUI file system generation utility allows you to graphically build directories of files that might consist, say, of Web content for the FNET HTTP server. This utility reads the chosen directory and its contents; then generates an image file that is readable by the FNET ROM file system.

As you can see, this is another case of software meeting silicon: FNET is a versatile, no-strings-attached open source solution for embedded devices that require network connectivity. FNET can be downloaded here.

About the author:

Tom Thompson is Proactive Support Engineer at Freescale Semiconductor. You can read other articles by him at The Embedded Beat.

About Author

Comments

blog comments powered by Disqus