An overview of Lightweight Internet Protocol

1. Introduction to Transmission Control Protocol/Internet Protocol (TCP/IP)
2. Introduction to Lightweight Internet Protocol (LwIP)
3. Example of implementing LWIP for microcontrollers
4. Conclusion

1. Introduction to Transmission Control Protocol/Internet Protocol (TCP/IP)

The TCP/IP (Transmission Control Protocol/Internet Protocol) is a widely used network protocol globally. It plays a crucial role in connecting and transmitting data between devices on the Internet and other computer networks. This report will introduce TCP/IP, provide an  overview of how it operates, and explain its significance in modern networking.

TCP/IP Model
TCP/IP Model

The TCP/IP model is a fundamental framework for network communication, consisting of four distinct layers. These layers are designed to handle various aspects of data transmission and routing.

  1. Network Interface Layer (Link Layer): This is the lowest layer, responsible for physical data transmission over the network medium. It deals with hardware-level protocols and addresses, such as Ethernet or Wi-Fi, and ensures the actual bits are transmitted correctly.
  2. Internet Layer: The Internet layer manages logical addressing and routing of data packets. It is primarily responsible for taking data from the network interface layer and delivering it to the correct destination using IP addresses.
  3. Transport Layer: The transport layer focuses on end-to-end communication between devices on different networks. It manages protocols like TCP (Transmission Control Protocol) for reliable, connection-oriented communication, and UDP (User Datagram Protocol) for lightweight, connectionless communication.
  4. Application Layer: The top layer, the application layer, deals with user-level processes and applications. It includes various protocols like HTTP for web browsing, FTP for file transfer, and SMTP for email. This layer enables user-level interaction with network services.

In the context of TCP/IP, two critical components are worth mentioning: sockets and LwIP. These components are pivotal because sockets provide the means for applications to engage in network communication, while LwIP offers a streamlined and efficient way to implement TCP/IP on resource-constrained systems, making it vital for developing network-connected applications in such environments.

  • Sockets are software endpoints for network communication. They allow applications to send and receive data over a network, whether locally or across the internet. Sockets provide a standard API (Application Programming Interface) for programming network communication, making it easier for developers to create networked applications. Sockets can be used with various transport layer protocols like TCP and UDP, enabling developers to choose the appropriate protocol for their specific requirements.
    Client-Server Communication through socket
  • Regarding LwIP, We will provide further details about it in section 2.

2. Introduction to Lightweight Internet Protocol (LwIP)

LwIP (Lightweight IP) is a lightweight and efficient TCP/IP library specifically designed for resource-constrained systems, particularly microcontrollers. This library simplifies the integration of network functionality into embedded devices by providing essential components of the TCP/IP protocol suite. Notably, LwIP excels in optimizing resource usage, making it suitable for applications demanding reliable network connectivity and high performance on resource-limited devices. With support for both IPv4 and IPv6, LwIP emerges as a powerful tool for developing networked applications on embedded platforms.

Benefits of LwIP:

  • Lightweight and Efficient: LwIP stands out for its lightweight and efficient design, meticulously crafted to function seamlessly on systems with limited system resources like RAM and ROM. This attribute is of paramount importance, especially when dealing with resource-constrained devices where conserving memory and storage is critical, such as STM32 Microcontroller. LwIP’s ability to operate efficiently in such environments makes it a top choice for developers working on embedded systems..
  • Optimized for Microcontrollers: The library is optimized for integration into embedded systems with low clock speeds and limited memory resources, making it well-suited for microcontrollers. This specialized optimization renders LwIP exceptionally well-suited for deployment on microcontrollers, where conserving both processing power and memory is of utmost importance. As a result, LwIP excels in providing network capabilities to microcontroller-based applications without overwhelming their limited hardware resources.
  • IPv4 and IPv6 Support: LwIP offers comprehensive support for both IPv4 and IPv6, enhancing flexibility in connecting to various network types.
  • Complete Network Protocols: LwIP encompasses a full suite of network protocols, including IP (Internet Protocol), TCP (Transmission Control Protocol), UDP (User Datagram Protocol), ICMP (Internet Control Message Protocol), ARP (Address Resolution Protocol), and more. Additionally, it supports DHCP (Dynamic Host Configuration Protocol) for dynamic host configuration, PPP (Point-to-Point Protocol) for point-to-point communication, and AutoIP for automatic IP address assignment.
  • Multinetwork and Multiconnection Communication: LwIP not only relates closely to the TCP/IP protocol stack but also provides support for operating system abstraction, memory management, buffering, network-related functionalities, and checksum calculations. These capabilities contribute to its versatility in managing complex networking tasks.

3. Example of implementing LWIP for microcontrollers

Integrating LWIP (Lightweight IP) into microcontrollers, especially widely-used platforms like the STM32 series, plays a pivotal role in embedded systems development. LWIP stands out as an efficient and space-conscious TCP/IP stack meticulously crafted for devices with limited resources. Achieving a seamless LWIP integration into a microcontroller calls for a methodical and structured approach. In the following, we’ll elucidate the step-by-step procedure for this undertaking:

  • In this example, we are utilizing a microcontroller board that supports Ethernet-related features, specifically the STM32F429ZIT6 Nucleo Board. The parameters that characterize the Ethernet feature of the STM32 board: IC network transfer KMS-1102NL as the Ethernet chip . We are employing STM32 board to emulate the client and utilizing software written in Python or Hercules Terminal software for simulating the server.
STM32F429ZIT6 Nucleo Board
  • Simultaneously, it is necessary to prepare an Ethernet cable and a router to assign IP addresses to the server and the board. Use the Ethernet cable to connect a port on the router to the Ethernet port on the board. Here are images showcasing how to establish connections between the router and the board. For the server, since we are using software on a computer for simulation, there is no need to establish a physical Ethernet connection between the router and the server. Instead, we can utilize Wi-Fi to connect to the router and obtain an IP address
Example to check server’s IP address
Hardware connection between router and microcontroller board
  • Writing a Driver for Physical Layer Ethernet: Choose a suitable PHY Ethernet and write a driver for it. Ensure the driver includes basic functions like register the I/O interfaces for communicating with the PHY, initialize the PHY, send and receive data on the same Ethernet port, stop and return the PHY to its initial state. Make sure the driver functions properly with the chosen PHY Ethernet.
    The example below consists of several functions that perform fundamental operations for the PHY Ethernet – LAN8742. You can use this as a reference.

    int32_t LAN8742_RegisterBusIO(lan8742_Object_t *pObj, lan8742_IOCtx_t *ioctx);

    int32_t LAN8742_Init(lan8742_Object_t *pObj);

    int32_t LAN8742_DeInit(lan8742_Object_t *pObj);

    int32_t LAN8742_DisablePowerDownMode(lan8742_Object_t *pObj);

    int32_t LAN8742_EnablePowerDownMode(lan8742_Object_t *pObj);

    int32_t LAN8742_StartAutoNego(lan8742_Object_t *pObj);

    int32_t LAN8742_GetLinkState(lan8742_Object_t *pObj);

    int32_t LAN8742_SetLinkState(lan8742_Object_t *pObj, uint32_t LinkState);

    int32_t LAN8742_EnableLoopbackMode(lan8742_Object_t *pObj);

    int32_t LAN8742_DisableLoopbackMode(lan8742_Object_t *pObj);

    int32_t LAN8742_EnableIT(lan8742_Object_t *pObj, uint32_t Interrupt);

    int32_t LAN8742_DisableIT(lan8742_Object_t *pObj, uint32_t Interrupt);

    int32_t LAN8742_ClearIT(lan8742_Object_t *pObj, uint32_t Interrupt);

    int32_t LAN8742_GetITStatus(lan8742_Object_t *pObj, uint32_t Interrupt);

  • Integrating the LwIP Library: Download the LwIP Library from this link into your project. The folder library structure that needs to be imported is as follows:
    LwIP Library structure

     

    Here, we will have two basic ways to use this library: Direct Function Calls from TCP and UDP Modules and Using LwIP APIs. For this example, we use Socket API – one in three types of APIs are offered by LwIP stack.

  • LwIP Usage: In this example, we will use Socket API and the FreeRTOS library to simulate the functionality of a client. This client will perform the following actions: create a socket, connect the socket to a socket server, send a message to the server, and receive a message from the server. Please note that you must adjust the server’s IP address and port, which are defined in the client’s source code. The block diagram of the example is depicted below:
    Example Block Diagram
  • For the server, we can simulate it using software like Hercules or by running a Python application, as previously mentioned. The simulation results for the server and client are illustrated as follows:
    Client send and receive message
    Simulating the server by Hercules
    Simulating the server by Python

4. Conclusion

LwIP plays a pivotal role in embedded systems, offering a lightweight and efficient TCP/IP stack tailored for resource-constrained devices. It’s irreplaceable due to its optimization for embedded platforms, conserving precious system resources like RAM and CPU cycles. LwIP’s open-source nature and adaptability make it a fundamental tool for embedded developers worldwide, simplifying networked application development while preserving resource constraints. In essence, it’s indispensable for efficient network communication in embedded systems.
The source code for this example is in this repo. If you encounter any issues, don’t hesitate to contact us at [email protected]

Leave a Reply

Your email address will not be published. Required fields are marked *