Disable all traces of LWIP?

We have a simple sideboard to our main board. It talks to the main board through serial and does not have any ethernet interface and thus all traces of LWIP should be disabled and all the precious memory freed. I can not seem to find any configuration option to disable it entirely. These are the options I’ve tried in my mbed_app.json file:

    "target_overrides": {
        "*": {
            "target.components_add": [],
            "target.components_remove": ["LWIP"],
            "target.features_remove": ["LWIP"],
            "target.network-default-interface-type": "null",
            "lwip.ethernet-enabled": false,
            "lwip.tcp-enabled": false,
            "lwip.ipv4-enabled": false,
            "lwip.ipv6-enabled": false,
            "lwip.l3ip-enabled": false,
            "lwip.ppp-enabled": false,
            "lwip.ppp-ipv4-enabled": false,
            "lwip.ppp-ipv6-enabled": false,
            "lwip.raw-socket-enabled": false,
            "target.xip-enable": false,
            "lwip.debug-enabled": false,
            "lwip.udp-socket-max": false,
            "lwip.socket-max": false,
            "nsapi.socket-stats-enabled": false,
            "nsapi.default-stack": "",
            "nsapi.present": 0,

They seem to do something, as both IPv4 and 6 are disabled, but that causes the following compilation error:

> mbed compile
[mbed] Working path "/..." (program)
Building project airfi-iob (LPC1768, GCC_ARM)
Scan: iob
Using ROM regions bootloader, application in this build.
  Region bootloader: size 0x20000, offset 0x0
  Region application: size 0x60000, offset 0x20000
Compile [ 21.3%]: lwip_random.c
[Error] lwipopts.h@34,2: #error "Either IPv4 or IPv6 must be enabled."
[ERROR] In file included from ./mbed-os/connectivity/lwipstack/lwip/src/include/lwip/opt.h:51,
                 from ./mbed-os/connectivity/lwipstack/lwip-sys/lwip_random.c:18:
./mbed-os/connectivity/lwipstack/include/lwipstack/lwipopts.h:34:2: error: #error "Either IPv4 or IPv6 must be enabled."
   34 | #error "Either IPv4 or IPv6 must be enabled."
      |  ^~~~~

[mbed] ERROR: "/opt/homebrew/opt/python@3.9/bin/python3.9" returned error.
       Code: 1
       Path: "/..."
       Command: "/opt/homebrew/opt/python@3.9/bin/python3.9 -u /.../mbed-os/tools/make.py -t GCC_ARM -m LPC1768 --source . --build ./BUILD/LPC1768/GCC_ARM"
       Tip: You could retry the last command with "-v" flag for verbose output
---

Most of the config options are pure guesswork based on random forum posts and some are taken from BUILD/.../mbed-os/mbed-config.h. I can’t seem to find a documented list of these configuration options anywhere and any googling for how to fix this and/or totally disable LWIP/Ethernet have turned up nothing useful. The best resource so far seems to be:

https://os.mbed.com/docs/mbed-os/v6.16/apis/connectivity-options-and-config.html#selecting-the-default-network-interface

It states:

Name: target.network-default-interface-type
    Description: Default network interface type. Typical options: null, ETHERNET, WIFI, CELLULAR, MESH
    Defined by: target:Target
    No value set

But null does not seem to do anything. Is it thus impossible to compile without a networking stack? I could of course go in and just remove all traces of LWIP from the clone mbed-os repository, but that seems like such a brutal approach.

Hello,

When you want configure a part of MbedOS then you should look for files in every root directory of specific API under name mbed_lib.json or file with configuration of all targets under name targets.json. In the section “device_has” you can see Ethernet and Emac, so your configuration in your mbed_app.json should contain

"target.device_has_remove": ["EMAC","ETHERNET" ]

However, that should save only compilation time because generally applies “all unused code is discarded”. This means that these APIs are compiled, but if your code does not call any part of these APIs then it is not part of your final binary file because there were no reason to link it.

BR, Jan

Unfortunately that particular value has no effect at all. Same compilation error. Just to be clear, I’m looking at mbed-os/connectivity/lwipstack/mbed_lib.json. The mbed-os/targets/targets.json has for the LP1768 target:

        "device_has": [
            "RTC",
            "USTICKER",
            "ANALOGIN",
            "ANALOGOUT",
            "CAN",
            "DEBUG_AWARENESS",
            "EMAC",
            "ETHERNET",
...

So apparently the compilation is a bit intertwined and includes LWIP stuff even though it’s supposedly disabled/removed, there’s a bug in the build system or I’m holding this thing totally wrong. Just giving up and letting IPv4 be enabled gives:

Compile [ 26.9%]: lwip_init.c
[Error] lwip_init.c@108,2: #error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h"
[ERROR] ./mbed-os/connectivity/lwipstack/lwip/src/core/lwip_init.c:108:2: error: #error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h"
  108 | #error "If you want to use UDP, you have to define MEMP_NUM_UDP_PCB>=1 in your lwipopts.h"

which leads me to believe that target.device_has_remove does not do the right thing here.

What I want to avoid is having the stack reserve any memory if at all possible. Preferably move the RAM reserved in the memory map for Ethernet back to generic application data. Our main board is an LPC1768 based thing, and with Ethernet enabled it takes up 32kB of the available 64kB. It has not been fun to squeeze a lot of functionality into 32kB (including MBed itself).

I do not know at which stage in the compilation/linking that reservation is made and I’m not sure trusting the linker would do it.

For full view let me ask.

  • What a build tool do you use?
  • MbedOS version?

BR, Jan

I think removing the features as JohnnyK suggested is the right way, and remove all the lwip modifications from mbed_app.json. lwip is validating the settings, so it will generate warnings and errors.

But you will not get more BSS/heap memory. There is a fixed linker script, and this reserves 16 k for USB and 16 k for ethernet. I don’t know if the older mbed-os has a split heap option for this target, that would be also necessary for the split heap. The RAM in LPC176x is not contiguous, so it could be only usable for globals vars, e.g. large arrays.

I actually JUST merged a patch to Mbed CE that enables reclaiming that extra 32k! If you do not actually use Ethernet in your application, you will have access to about 48k of heap memory (with the remaining ~16k taken up by Mbed).

See here for more info about the memory map of this target.