The Library Reference is configured at compile time using
CONFIG_*. The default configuration includes most
functionality, as most application wants that. If an application has
special requirements, for example memory constraints, it has to be
configured to remove unnecessaray functionality.
Highest priority first.
- Command line as
- A file named
config.hin the application root folder.
- The default configuration file, src/config_default.h.
All configuration variables are listed below. Their default values are defined in src/config_default.h.
The system configuration string contains a list of all configration varialbes and their values.
Assertions are used to check various conditions during the application execution. A typical usage is to validate function input arguments.
Include more debug information.
Debug file system command to list all DS18B20 sensors on the bus.
Debug file system command to append to a file.
Debug file system command to list all counters.
Debug file system command to set all counters to zero.
Debug file system command to list all registered file systems.
Debug file system command to list all registered file systems.
Debug file system command to list all parameters.
Debug file system command to read from a file.
Debug file system command to write to a file.
Debug file system command to read from a i2c bus.
Debug file system command to write to a i2c bus.
Debug file system command to list all log objects.
Debug file system command to create a log entry and print it. Mainly used for debugging.
Debug file system command to set the log mask of a log object.
Debug file system command to list all network interfaces.
Debug file system command to read the current value of a pin.
Debug file system command to set the mode of a pin.
Debug file system command to write a value to a pin.
Debug file system command to ping a host.
Debug file system command to list all settings.
Debug file system command to read the value of a setting.
Debug file system command to reset the settings to their original values.
Debug file system command to write a value to a setting.
Debug file system command to print the system configuration.
Debug file system command to print the system information.
Debug file system command to print the system uptime.
Debug file system command to list threads’ information.
Debug file system command to set the log mask of a thread.
Debug file system command to list all USB devices.
Debug file system command to list all USB devices connected to the USB host.
The maximum length of an absolute path in the file system.
Start the monitor thread to gather statistics of the scheulder.
Use a preemptive scheduler.
Profile the stack usage in runtime. It’s a cheap operation and is recommended to have enabled.
Size of the settings area. This size MUST have the same size as the settings generated by the settings.py script.
Maximum number of characters in a shell command.
Size of the shell history buffer.
Minimal shell functionality to minimize the code size of the shell module.
The shell prompt string.
SPIFFS is a flash file system applicable for boards that has a reasonably big modifiable flash.
Start the console device (UART/USB CDC) on system startup.
Console device index.
Console UART baudrate.
Console USB CDC control interface number.
Console USB CDC input endpoint.
Console USB CDC output endpoint.
Wait for the host to connect after starting the console.
Configure a default file system.
Configure a default file system start address.
Configure a default file system size.
Setup the ip stack and connect to all configured networks.
WiFi connect timeout is seconds.
SSID of the WiFi to connect to.
Password of the WiFi to connect to.
Start a shell thread communication over the console channels.
Shell thread priority.
Shell thread stack size in words.
Maximum number of bytes in the print output buffer.
System tick frequency in Hertz.
Calculate thread CPU usage.
Each thread has a list of environment variables associated with it. A typical example of an environment variable is “CWD” - Current Working Directory.
Threads are allowed to terminate.
USB device vendor id.
USB device product id.
config.h to fully configure lwIP and all of its modules. You
do not need to define every option that lwIP provides; if you do not
define an option, a default value will be used. Therefore, your
config.h provides a way to override much of the behavior of lwIP.
By default Simba overrides a few of the variables in src/inet/lwipopts.h.
Module support (Code size)¶
Enabling and disabling modules¶
You can tune your code size by only compiling the features you really need. The following is a list of what gets compiled in “out of the box” with lwIP.
- ARP (
- IP and fragmentation (
IP_FRAG) and reassembly (
- Raw IP PCB support (
- UDP (
LWIP_UDP) and UDP-Lite (
- TCP (
LWIP_TCP) – this is a big one!
- Statistics (
- DHCP (
- AUTOIP (
- SNMP (
- IGMP (
- PPP (
If you would like to change this, then you just need to set the
options listed below. For example, if you would like to disable UDP
and enable DHCP, the following
config.h file would do it:
/* Disable UDP */ #define LWIP_UDP 0 /* Enable DHCP */ #define LWIP_DHCP 1
Memory management (RAM usage)¶
In an embedded environment, memory pools make for fast and efficient memory allocation. lwIP provides a flexible way to manage memory pool sizes and organization.
lwIP reserves a fixed-size static chunk of memory in the data segment,
which is subdivided into the various pools that lwip uses for the
various data structures. For example, there is a pool just for struct
tcp_pcb’s, and another pool just for struct udp_pcb’s. Each pool can
be configured to hold a fixed number of data structures; this number
can be changed in the
config.h file by changing the various
MEMP_NUM_* values. For example,
MEMP_NUM_UDP_PCB control the maximum number of tcp_pcb and udp_pcb
structures that can be active in the system at any given time.
It is also possible to create custom memory pools in addition to the standard ones provided by lwIP.
Dynamic allocation: mem_malloc¶
lwIP uses a custom function mem_malloc for all dynamic allocation; therefore, it is easy to change how lwIP uses its RAM. There are three possibilities provided out-of-the-box:
- (default) lwIP’s custom heap-based mem_malloc. By default, lwIP
uses a statically-allocated chunk of memory like a heap for all
memory operations. Use
MEM_SIZEto change the size of the lwIP heap.
- C standard library malloc and free. If you wish to have lwIP use
the standard library functions provided by your
compiler/architecture, then define the option
- Memory pools. lwIP can also emulate dynamic allocation using custom
memory pools (see that chapter for more information). This involves
MEMP_USE_CUSTOM_POOLSand a new custom file
Understanding/changing memory usage¶
lwIP uses memory for:
code (depending on your system, may use ROM instead of RAM)
statically allocated variables (some initialized, some not initialized)
dynamically allocated memory
- memp pools
Unless you use a C library heap implementation (by defining
MEM_LIBC_MALLOC to 1), dynamically allocated memory must be statically
allocated somewhere. This means you reserve a specific amount of
memory for the heap or the memp pools from which the code dynamically
allocates memory at runtime.
The size of this heap and memp pools can be adjusted to save RAM:
There are 3 types of pbufs:
- REF/ROM, RAM and POOL.
PBUF_POOL_BUFSIZEonly refers to type POOL.
- RAM pbufs are allocated in the memory defined by
MEM_SIZE(this memory is not used much aside from RAM pbufs) - this is the heap and it is allocated as mem_memory.
- REF/ROM pbufs as well as pcbs and some other stuff is allocated from
dedicated pools per structure type. The amount of structures is
defined by the various
MEMP_NUM_defines. Together, this memory is allocated as memp_memory and it includes the pbuf POOL.
However, if you define
MEMP_MEM_MALLOC to 1 in your
every piece of dynamically allocated memory will come from the heap
(the size of which is defined by
MEM_SIZE). If you then even
MEM_LIBC_MALLOC to 1, too, lwIP doesn’t need extra memory
for dynamically allocated memory but only uses the C library heap
instead. However, you then have to make sure that this heap is big
enough to run your application.
To tweak the various
MEMP_NUM_ defines, define
LWIP_STATS_DISPLAY=1 and call stats_display() to see how
many entries of each pool are used (or have a look at the global