uIP TCP/IP Protocol Stack Demonstration
Contributed By Electronic Products
2011-03-03
The popular open source uIP TCP/IP stack is widely used in embedded designs. This demo provides both hands on experience and insights into its use.
This article demonstrates the features and capabilities of the RX62N Renesas Ethernet connectivity target devices with the open source uIP TCP/IP protocol stack. It assumes some experience with Ethernet, TCP/IP, and HTML. For more introductory material on these subjects please see the references at the end of this article.
The uIP TCP/IP stack demonstration project provides an example of Ethernet connectivity and a sample web server application that controls LEDs on the Renesas Starter Kit (RSK) boards.
Overview
The procedure below provides step by step instructions for how to setup the demonstration project and run it.
Setup
Set up a demonstration environment as shown in Figure 1. In this setup, a router is used as a DHCP server and a PC as a web client. Several RSK boards can be connected to the multiport router. Use straight RJ-45 Ethernet cables to make the connections. Depending on the RSK board used there may be other settings to be configured before running the demonstration project. These may include instructions for connecting a debugger to the RSK board. Please refer to the Quick Start Guide (QSG) of the RSK board for more information.
Figure 1: Demonstration setup.
Figure 2: Test setup.
The demonstration project by default is configured to run in little endian mode. Please make sure RSK board is configured for the same endian mode. Refer to your QSG how to change endian mode of operation.
For a simpler setup, an RSK board can be directly connected to a PC. In this setup, the router is not used and the demonstration project is designed to fall back to a static IP address if a DHCP server is not found in about ten seconds. In this case, the RSK board assumes the default IP address of 192.168.1.10.
Figure 2 shows a more detailed test setup environment as an alternative. In this setup all devices are on the same collision domain and all network activity can be monitored and analyzed on the PC. If this setup is used, make sure the center connectivity device is a true hub rather than a switch. The router can be disconnected and connected back to the network independent of the connections between the PC and the RSK boards. This allows monitoring of RSK board behavior with or without a DHCP server on the network.
Figure 3: Router network configuration.
Configure the IP address of the router to 192.168.1.1. This is usually the default IP address for most home or office routers. Configure the DHCP start IP address to 192.168.1.100 with two maximum DHCP users. A snapshot of the router configuration is shown in Figure 3.
Configure the Ethernet port of the PC with a static IP address of 192.168.1.2. Internet Protocol (TCP/IP) properties of the PC are shown in Figure 4. Make sure that this Ethernet port is not used to access a corporate network or a workgroup. If there is not a spare Ethernet port available, it is recommended to use an USB to an Ethernet adaptor. Please follow the adaptor manufacturer manual for installation instructions.
Figure 4: PC network configuration.
Sample project directory structure
Figure 5 shows the demonstration project directory structure. The \src folder contains the source code and has four subfolders: bsp, driver uip, and user-app. The \src\bsp and \src\driver folders have Renesas board specific source code and the Ethernet drivers for the RSK board. The uIP stack is in the \src\uip folder.
The open source uIP TCP\IP stack comes with its own documentation. It is in the \src\uip\doc folder. The main.c file is in \src\uip\uip and the example web pages are in src\uip\apps\webserver\httpd-fs folders.
The demonstration project includes a simple user application that controls the LEDs on the RSK board. This application is in the \src\user-application folder.
Figure 5: Directory structure of uIP demonstration project.
What to do with the demo
The demonstration project displays “uIP Demo” on the RSK board LCD on power up. The IP address used is displayed on the LCD. The RSK board either receives its IP address from a DHCP server or uses its default setting of 192.168.1.10. For the test setup in this article, the DHCP server can assign IP addresses of 192.168.1.100 and 192.168.1.101. Make sure the Ethernet cables are connected and devices are powered up if no IP address is displayed after ten seconds. Some of the possible LCD settings are shown in Figure 6.
Figure 6: LCD settings.
The router’s status page can also be used to find which IP address is assigned to the RSK board as shown in Figure 7. Another way is simply to ping IP addresses and use the IP address with the reply. Ping messages can be generated by the following DOS Shell commands:
| C:\>ping | 192.168.1.10 | |
| C:\>ping | 192.168.1.100 | |
| C:\>ping | 192.168.1.101 |
Figure 7: DHCP client information
Launch a web browser and use the IP address of the RSK board in the URL field. After a successful connection, the user will see the welcome page shown in Figure 8. This is also the front page. Note that the Renesas logo is linked to http://am.renesas.com/. By activating this link the user can easily access the Renesas Electronics America internet site.
All other pages can be accessed by links provided in the top banner. The file statistics page shows the number of times a specific page is accessed. The network statistics page displays the number of IP, ICMP, and TCP packet reception and transmission information. The network connections page shows the current status of established TCP connections within the uIP stack. These pages are dynamic and recreated every time they are accessed.
Two custom pages are created and included within the demonstration project. First is the RSK board specific page. In this case it is an RX62N custom page. The demonstration project is personalized for different target devices and target specific images are shown on this page. This is to show that creating custom web pages can be easily achieved and integrated with the uIP TCP/IP stack. The next section describes step by step instructions for creating a new web page.
The second custom page is the simple user application that controls the LEDs on the RSK board. One of the LEDs on the RSK board is used to indicate system timer activity. The other three are used by the LED control web page. From this web page, the user can turn the LEDs on and off on the RSK board. The reset button selects the off setting for all LEDs.
Steps to create a new web page
A new web page can be easily created and added to the demonstration project by following the following steps. With a little HTML language knowledge, the user can create custom web page applications. All the tools and information needed are provided with the demonstration project and in this article.
- Write a new web page application. See the led.shtml example in src\uip\apps\webserver\httpd-fs.
- Copy it to src\uip\apps\webserver\httpd-fs directory.
- Run makefsdata.exe from src\uip\apps\webserver directory to generate the new fttpd-fsdat.c file.
- Rebuild the project.
The makefsdata.exe is a Renesas add-on program created from makefsdata Perl script. This executable is included into the demonstration project located in apps\webserver\ directory to make it easier for the user to generate the httpd-fsdata.c file without the need to find and install a Perl interpreter.
More on uIP TCP/IP stack
uIP TCP/IP stack was originally developed by Adam Dunkels of the Networked Embedded Systems Group at the Swedish Institute of Computer Science. uIP TCP/IP stack includes some higher layer example applications such as web server, web client, Trivial File Transfer Protocol (TFTP), and DNS hostname server.
uIP TCP/IP stack does not require a real-time operating system. However, there are versions of it ported to an open source FreeRTOS operating system and are available on the Internet. It is also ported to several other Renesas MCU devices. Sample code can be downloaded from the uIP web site.
Usage considerations with uIP TCP/IP stack
One consideration when using a uIP TCP/IP stack is that it supports only one TCP segment in transit. If uIP TCP/IP stack is used with a TCP receiver using a delayed acknowledgment algorithm, throughput performance can be poor. You can modify TCP acknowledgment behavior of your PC if you experience this condition with your default PC setup.
More information can be found at http://support.microsoft.com/kb/328890. This situation is also discussed in the uIP TCP/IP reference manual.
Another consideration is that the uIP TCP/IP stack supports one TCP and one UDP application at a given time. In this demonstration project, the HTTP web server application uses TCP and DHCP client runs on UDP. An application multiplexer layer based on connection port number can be added to the uIP TCP/IP stack to support multiple TCP or UDP applications.
More on DHCP
Dynamic Host Configuration Protocol (DHCP) is a protocol used by networked devices to obtain IP addresses and other parameters such as default gateway, subnet mask, and an IP address of the Domain Name Server (DNS) from a DHCP server. The protocol is defined by RFC 2131. DHCP eases the management of the above tasks and ensures that all IP addresses on the network are unique and unused IP addresses are returned back to the IP address poll for reassignment for other devices joining the network.
The demonstration project makes use of the dynamic mode of DHCP. In dynamic mode, a client is provided with an IP address and time duration in which this IP address is valid. This time duration is called lease time.
DHCP operation
There are four main messages exchanged between a DHCP client and a DHCP server during dynamic IP address assignment. They are shown in Table 1.
|
Table 1: DHCP messages.
How to use DHCP client
There are certain things to consider while using a DHCP client. The most important consideration is to ensure that each device on the network has a unique MAC address. DHCP servers assign IP addresses based on client MAC addresses. For end customer production devices the MAC address can be purchased from IEEE.
Another consideration is how to know what IP address is assigned to a device. One way to find this information is to query the DHCP server through its management interface. This will show the IP addresses and which MAC addresses are assigned to them.
Debugging a system with a DHCP server can be tricky. Here are some recommendations. First, use of a network analyzer is a great help. Wireshark has been used throughout the development of this project. It is a PC-based network analyzer software. For more information on Wireshark, see http://www.wireshark.org.
Second, the IP address of the PC Ethernet port used by the network analyzer must be on the same network and subnet with the DHCP server and its clients, e.g. the Renesas target board(s). This can be achieved by assigning a static IP address to the PC Ethernet port that is outside the IP addresses that can be given out by the DHCP server, but still making sure that network and subnet requirements are met.
For example, in Figure 3 the DHCP server is configured with a start IP address of 192.168.1.100. Figure 4 shows that the PC Ethernet port is configured to use the192.168.1.2 and it is outside the range of the IP addresses that can be given to its clients by the server.
References
- Group Hardware Manuals for the Renesas device on the RSK board.
- The uIP Embedded TCP/IP Stack, The uIP 1.0 Reference Manual, June 2006, Adam Dunkels, Swedish Institute of Computer Science
- IEEE 802.3 Ethernet, IEEE Standards Association, http://standards.ieee.org/getieee802/802.3.html
- HTTP – Hypertext Transfer Protocol. World Wide Web Consortium, http://www.w3.org/Protocols
- RFC 2131 Dynamic Host Configuration Protocol, IETF, http://www.ietf.org/rfc/rfc2131.txt
- RFC 2132 DHCP Options and BOOTP Vendor Extensions, IETF, http://www.ietf.org/rfc/rfc2132.txt
Website and Support
- Renesas Electronics Website: http://www.renesas.com/
- Inquiries: http://www.renesas.com/inquiry
Disclaimer: The opinions, beliefs, and viewpoints expressed by the various authors and/or forum participants on this website do not necessarily reflect the opinions, beliefs, and viewpoints of DigiKey or official policies of DigiKey.

