O que é o protocolo leve da Internet (LwIP)?

What is Lightweight Internet Protocol (LwIP)?

Connecting embedded microcontrollers to the Internet is a crucial task in modern applications. Embedded controllers, especially in consumer devices and wearables, now essentially require online ping. This is more important as devices are getting smarter. Connecting to the Internet is not only crucial but also a difficult task. The typical TCP/IP stack is too resource intensive to implement on bare metal. Microcontrollers can never implement the TCP/IP stack due to low memory, RAM, and computing power, so they require something lightweight to emulate the same functionality.

The Light-Weight Internet Protocol (LwIP) is a small, independent implementation of a suite of TCP/IP protocols for embedded systems. Originally developed by Adam Dunkels at the Swedish Institute of Computer Science (SICS), LwIP is a free and open-source TCP/IP stack now maintained in Savannah. Several renowned embedded system manufacturers have adopted LwIP, such as Texas Instruments, Altera Corporation, Xilinx, STMicroelectronics, Freescale, and Analog Devices, for their embedded device network drivers. The protocol is even used by Arduino Ethernet Shield and WiFi development boards like ESP32 and ESP8266 to implement network functions. Any hardware manufacturer can use the protocol with the operating system or network driver on their platform as an open protocol under the modified BSD license. The protocol can also be used in applications as long as the underlying operating system supports the LwIP port. The LwIP source is available as a Git repository.

LwIP allows you to implement a full TCP/IP stack on embedded systems while consuming minimal system resources and memory. The stack is even modified to fit Arduino libraries. The stack requires only 40kb of ROM/flash memory and consumes only tens of kilobytes of RAM during runtime. Even a custom API is available for the stack that does not require data copying.

What is LwIP capable of?
LwIP allows a complete TCP/IP stack in a space smaller than 40 kb. It can be used to implement the following network protocols in an embedded application.

Internet Protocol (IP) : LwIP allows the manipulation of IPv4 and IPv6 addresses and the forwarding of packets across multiple network interfaces (netifs). It can assign a static IP address to the network interface, obtain an IP address from the DHCP server, or choose an IP address from the local subnet. You can even assign an IP address to a network interface.

Internet Control Message Protocol (ICMP) : LwIP allows network maintenance and debugging via ICMP protocol. Supported protocols include Echo Reply/ping, Destination Unreachable, and Time Exceeded.

Neighbor Discovery (ND) : LwIP enables stateless neighbor discovery and address autoconfiguration for IPv6 in compliance with standards RFC 4861 (for neighbor discovery) and RFC 4862 (for address autoconfiguration).

Multicast Listener Discovery for IPv6 (MLD) : LwIP provides multicast listener discovery for IPv6 in compliance with the RFC 2710 standard. However, it does not support MLDv2.

User Datagram Protocol (UDP) : LwIP includes experimental UDP-lite extensions compliant with standards RFC 768 (UDP) as well as RFC 3828 (UDP lightweight).

Transmission Control Protocol (TCP) : LwIP enables TCP protocol compliant with RFC 793 (Transmission Control Protocol), RFC 1122 (Requirements for Internet Hosts), RFC 2001 (TCP Slow Start Algorithms, Congestion Avoidance, Fast Retransmission and Fast Recovery), RFC 2581 (TCP Congestion Control), RFC 3390 Standards (Increasing the TCP Initial Window).

Internet Group Management Protocol (IGMP) : LwIP enables management of multicast traffic that supports IGMP version 0, IGMP version 1, IGMP version 2, and IGMP version 3.

Address Resolution Protocol (ARP) : LwIP allows you to translate the hardware address into a network layer address for Ethernet.

Point-to-Point Protocol (PPP) : LwIP allows point-to-point protocol over Ethernet (PPPoE) and also over Serial (PPPoS).

LwIP can configure DHCP client, DNS client and SNMP client on one platform. Additionally, it allows you to configure a controller as an HTTP/HTTPS server, SMTP/SMTPS client, MQTT client, SNTP client, NetBIOS name server, TFTP server, or mDNS responder. Initially, LwIP was designed to run in single-threaded environments; Multi-threading support was added to it eventually. The functionality of its various modules, including api.h, sockets.h, sys.h, netbuf.h, pppapi.h, netifapi.h, and netdb.h can be safely executed on separate threads. This means you can run multiple protocols including IPv4/IPv6, PPP etc. simultaneously on the embedded controller. Network interfaces (IoT and networking) supported by LwIP include WiFi (IEEE 802.1D bridge), LPWAN ((6LoWPAN), Bluetooth (6LoWPAN over BLE), PPP interfaces, SLIP interfaces, and Zigbee (ZEP).

LwIP Applications
The LwIP stack helps you implement embedded networks. A common application of LwIP is the implementation of WiFi networks embedded in bare metal (microcontrollers). Popular WiFi development boards like ESP8266 and ESP32 utilize LwIP stack for wireless networking functionalities. Microcontroller platforms like Arduino use the stack to communicate via Ethernet.

Many developers find it easier to implement network functions on embedded Linux or RTOS. However, even micro-RTOs can be overkill for embedded WiFi applications. With a little network programming in the LwIP stack, complete TCP/IP applications can be developed on microcontroller platforms. These applications can run application layer protocols such as HTTP, TCP, and UDP on a small client such as a microcontroller.

For example, see how the ESP8266/ESP32 can be configured as a TCP client/server capable of loading or hosting an HTML page.

For many IoT use cases, running application layer protocols on a microcontroller can be a win-win situation compared to relying on protocols like MQTT or CoAP, which are only capable of sending latent messages over the Internet. The LwIP stack allows you to configure a microcontroller as an HTTP client, HTTP server, MQTT client, MDNS, SMTP client, SNTP, NetBIOS responder, Iperf server, SNMP agent and TFTP server. If an embedded network application does not require scaling or deal with network security issues or time constraints, the LwIP stack may be the best option. Still, a developer must take care of the expectations of the intended embedded application and choose wisely whether the LwIP stack is sufficient or whether the underlying Linux/BSD networking stack is adequate. Most embedded network developers find the LwIP stack comfortable to use as they are already familiar with the TCP/IP suite and 802.11 PHY.

LwIP has a lot to offer in the embedded networking space that major embedded manufacturers have adopted for their Ethernet and WiFi drivers. LwIP is a networking stack in operating systems like ReactOS and Genode. In some Linux/Unix-based operating systems, the stack is used to implement network servers.

For popular embedded platforms like Arduino and ESP8266/ESP32, LwIP is available through the BSD sockets API. Thus, electronics enthusiasts can integrate LwIP features into an embedded application by accessing the API module such as the socket module. Many real-time operating systems (RTOS) rely on the LwIP stack to implement network functions.

Embedded designers can find LwIP-based device drivers already available for many platforms. Otherwise, they are free to utilize the LwIP stack within an operating system or network driver to implement embedded networking on a specific platform. If a platform runs an operating system containing an LwIP stack, developers can directly utilize the stack in application code.

LwIP stack implementation
The LwIP stack is available through three types of application programming interfaces – raw APIs, inline-style APIs, and BSD-style socket APIs. Raw APIs are low-level, non-thread-safe APIs that can be used to integrate LwIP at the operating system or kernel level. These APIs allow you to make callbacks optimized for maximum performance with minimum space. Inline-style APIs provide blocking functions that can be called on TCP/IP threads. BSD-style socket APIs provide thread-safe functions that are called on non-TCP/IP threads. Copyless APIs do not burden the underlying platform (controller).

For microcontroller platforms like Arduino and ESP, you can find the LwIP stack already implemented in some libraries. Platform-specific libraries can implement the stack intrinsically or as an explicit LwIP driver. Some embedded firmware, such as MicroPython, also uses and supports the LwIP stack.

LwIP with Arduino
The Ethernet library for the Arduino platform is based on the LwIP stack. The library can work with Arduino Ethernet Shield, Arduino Ethernet Shield 2, Leonardo Ethernet and W5100/W5200/W5500 based network cards. To explicitly use the LwIP stack on Arduino for network functions, a LwIP source modified according to the Arduino libraries is also available. An STM32 Ethernet library for Arduino is also based on the LwIP stack and follows the Arduino Ethernet API. It can be used to program Ethernet applications on STM32-based boards. Some other Arduino libraries based on the LwIP stack include the following.

lwIP: a port of the LWIP library for Arduino.
ESP8266-ping: Used to send and receive ping messages on ESP8266.
QNEthernet: lwIP-based Ethernet library for Teensy 4.1.
AsyncWebServer_Ethernet: Asynchronous HTTP and WebSocket server library for ESP8266.
InqPortal: Used for full IoT server on ESP8266.
RTT-Ethernet: used to connect STM32 boards with Ethernet.

LwIP with ESP8266 and ESP32
The LwIP stack is available for ESP-IDF as a BSD socket API. The API can be used to configure ESP8266/ESP32 as a TCP client, TCP server, UDP client, UDP server, UDP multicast and HTTP ESP client. Some Arduino libraries are also available for ESP8266 (mentioned above), which are based on the LwIP stack. These libraries can configure the ESP8266 for Ethernet or as an IoT server.

LwIP Device Drivers
Professional embedded system developers can now find LwIP device drivers for various platforms. Drivers are available for CS8900A, MCF5223X, STM32F107xx, STM32F217, Altera NIOS II TSE, TI Stellaris LM3S, ARM Cortex-M3 FM3 MB9BD10S/T, MB9B610S/T, MB9B210S/T, TI RM48xx/RM46xx/TMS570xxx/RM57xx/TMS570LC xx, Analog Devices Microcontrollers Blackfin 526/527/536/537, TI C674x, ARM Cortex-M(3), STM32F4x7 and PIC32MX795H512L. A generic LwIP link layer driver is also available for Ethernet chips. If a platform requires integration of the LwIP stack into the Linux/BSD kernel or a network driver, developers can refer to the LwIP platform developer manual. To integrate the LwIP stack into an application, the LwIP Application Developers Handbook is the available guide.

LwIP in real-time operating systems
Many real-time operating systems such as FreeRTOS, RTLinux, QP, mbed, eCos, and eCos Pro include an LwIP port along with a BSD-derived networking stack. A Micromonitor/uMon boot monitor also uses a LwIP stack as a complement.

Conteúdo Relacionado

How to Troubleshoot Common ESP32-CAM Problems
ESP32-CAM is a compact camera module that combines the...
What is the role of automotive sensors in modern vehicles?
A network of sensors is embedded in every vehicle,...
How to choose an e-bike controller
The motor controller is one of the most important...
A guide to USB standards from 1.0 to USB4
A evolução dos padrões USB foi fundamental para moldar...
Schurter aprimora série de seletores de tensão com revestimento prateado
A SCHURTER anuncia um aprimoramento para sua conhecida série...
A interface serial PCI fornece conectividade confiável em ambientes extremos
A Sealevel Systems anuncia o lançamento da Interface Serial...
STMicroelectronics expande portfólio de conversão de energia com diodos Trench Schottky de 100 V
A STMicroelectronics introduziu Diodos retificadores Schottky de trincheira de...
O que são Sistemas Globais de Navegação por Satélite (GNSS) e como são usados?
Determinar uma localização precisa é necessário em várias indústrias...
O conversor GaN de 50 W da STMicroelectronics permite projetos de energia de alta eficiência
O novo VIPerGaN50 da STMicroelectronics simplifica a construção de...
Samsung e Red Hat farão parceria em software de memória de próxima geração
A Samsung Electronics, fornecedora de tecnologia de memória avançada,...
Primeiro MPU single-core com interface de câmera MIPI CSI-2 e áudio
O mercado embarcado tem uma necessidade de soluções de...
A influência de diferentes enrolamentos de armadura CC no desempenho
O impacto dos enrolamentos da armadura CC no desempenho...
Fluency decoding in induction motor for better performance
You have probably come across the term ' drag...
Understanding Support Insulators in Electrical Systems
You probably have a support insulator if you've noticed...
Explore Stay Insulator – safety, installation and maintenance
You've probably seen stand an insulator sit on power...
More safety and efficiency with the shackle isolator
You've probably seen shackle insulators enthroned on electricity poles,...
Back to blog

Leave a comment

Please note, comments need to be approved before they are published.