Mbed 5.x Ethernet sample (feature-lwip) does not compile, but works on ARM mbed online compiler

Hi, I’m having trouble compiling Ethernet sample program at [1] which depends on mbed latest Network Socket API when using PlatformIO IDE. Everything works fine (compiles and runs) when using the ARM mbed online compiler. I’m using following boards;

NXP LPC1768
STM32 NUCLEO-F767ZI

Please use the link at the bottom to refer to the source code.

Compile error:

In file included from src/main.cpp:2:0:
/home/akila/.platformio/packages/framework-mbed/features/unsupported/net/eth/EthernetInterface/EthernetInterface.h:24:2: error: #error The Ethernet Interface library is not supported on this target
; #error The Ethernet Interface library is not supported on this target

platformio.ini
[env:nucleo_f767zi]
build_flags = -Wall -DMBED_CONF_LWIP_IPV4_ENABLED -DMBED_CONF_LWIP_IP_VER_PREF=4
platform = ststm32
board = nucleo_f767zi
framework = mbed
; lib_ignore = mbed-net ; does not work even when enabled
; lib_ldf_mode = deep+ ; does not work even when enabled

$ pio --version
PlatformIO, version 3.4.0b10

$ pio update
Updating tool-scons @ 3.20501.2 [Up-to-date]
Updating tool-unity @ 1.20302.1 [Up-to-date]
Updating pysite-pioplus @ 0.3.0 [Up-to-date]
Updating tool-pioplus @ 0.8.14 [Up-to-date]

Platform Manager
; ================
Platform NXP LPC
; --------
Updating nxplpc @ 2.1.1 [Up-to-date]
Updating framework-mbed @ 3.142.0 [Up-to-date]
Updating toolchain-gccarmnoneeabi @ 1.40804.0 [Up-to-date]

Platform ST STM32
; --------
Updating ststm32 @ 2.1.0 [Up-to-date]
Updating tool-stm32duino @ 1.0.0 [Up-to-date]
Updating framework-mbed @ 3.142.0 [Up-to-date]
Updating toolchain-gccarmnoneeabi @ 1.40804.0 [Up-to-date]
Updating tool-stlink @ 1.10301.0 [Up-to-date]

It seems a similar issue is reported in [2]. I noticed that mbed builder script (mbed.py under builder-framework-mbed) [3] is still trying to include mbed old networking module (features/unsupported/net) but there is no option to include the latest feature-lwip module. I tried tweaking mbed.py script to include features/FEATURE_LWIP/lwip-interface and features/netsocket modules and managed to get it compiled. However, it fails to create an Ethernet connection after uploading the program.

[1] Network socket - API references and tutorials | Mbed OS 6 Documentation
[2] stm32 nucleo f207zg: Sample code fails to compile, but compiles in ARM mbed online compiler · Issue #36 · platformio/platform-ststm32 · GitHub

Appreciate if anyone could shed some light into this.

Thanks.

[3] https://github.com/platformio/builder-framework-mbed/blob/develop/mbed.py#L341

Sorry, but in the moment only mbed os2 is supported by PlatformIO. I hope the support of mbed os5 will follow soon.

This works in latest PIO mbed-framework release.

That are very good news.

I seem to have the same problem. Everything is up to date as far as I can determine, but the Ethernet sample will not compile. I’m quite new to this so some help would be appreciated.

build output from pio:

[08/19/17 16:50:37] Processing disco_f769ni (platform: ststm32; board: disco_f769ni; framework: mbed)

PackageManager: Installing toolchain-gccarmnoneeabi @ >=1.60301.0
Downloading…
Unpacking…
Verbose mode can be enabled via -v, --verbose option
Collected 22 compatible libraries
Looking for dependencies…
Library Dependency Graph
|--
| |--
| |--
| |--
Linking .pioenvs\disco_f769ni\firmware.elf

.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_arch_mbox_fetch': lwip_sys_arch.c:(.text.sys_arch_mbox_fetch+0x22): undefined reference toosEventFlagsWait’
lwip_sys_arch.c:(.text.sys_arch_mbox_fetch+0x2e): undefined reference to osKernelLock' lwip_sys_arch.c:(.text.sys_arch_mbox_fetch+0x54): undefined reference toosEventFlagsSet’
lwip_sys_arch.c:(.text.sys_arch_mbox_fetch+0x68): undefined reference to osEventFlagsClear' lwip_sys_arch.c:(.text.sys_arch_mbox_fetch+0x6e): undefined reference toosKernelRestoreLock’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_arch_mbox_tryfetch': lwip_sys_arch.c:(.text.sys_arch_mbox_tryfetch+0xe): undefined reference toosEventFlagsWait’
lwip_sys_arch.c:(.text.sys_arch_mbox_tryfetch+0x1a): undefined reference to osKernelLock' lwip_sys_arch.c:(.text.sys_arch_mbox_tryfetch+0x40): undefined reference toosEventFlagsSet’
lwip_sys_arch.c:(.text.sys_arch_mbox_tryfetch+0x54): undefined reference to osEventFlagsClear' lwip_sys_arch.c:(.text.sys_arch_mbox_tryfetch+0x5a): undefined reference toosKernelRestoreLock’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_sem_new': lwip_sys_arch.c:(.text.sys_sem_new+0x20): undefined reference toosSemaphoreNew’

.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_arch_sem_wait': lwip_sys_arch.c:(.text.sys_arch_sem_wait+0x18): undefined reference toosSemaphoreAcquire’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_sem_signal': lwip_sys_arch.c:(.text.sys_sem_signal+0x4): undefined reference toosSemaphoreRelease’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_mutex_new': lwip_sys_arch.c:(.text.sys_mutex_new+0x1c): undefined reference toosMutexNew’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_mutex_lock': lwip_sys_arch.c:(.text.sys_mutex_lock+0x8): undefined reference toosMutexAcquire’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_mutex_unlock': lwip_sys_arch.c:(.text.sys_mutex_unlock+0x4): undefined reference toosMutexRelease’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_init': lwip_sys_arch.c:(.text.sys_init+0x14): undefined reference toosMutexNew’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_arch_protect': lwip_sys_arch.c:(.text.sys_arch_protect+0xa): undefined reference toosMutexAcquire’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_arch_unprotect': lwip_sys_arch.c:(.text.sys_arch_unprotect+0x6): undefined reference toosMutexRelease’
.pioenvs/disco_f769ni/lib/FEATURE_LWIP/lwip-interface/lwip-sys/arch/lwip_sys_arch.o: In function sys_thread_new': lwip_sys_arch.c:(.text.sys_thread_new+0x72): undefined reference toosThreadNew’
collect2.exe: error: ld returned 1 exit status
*** [.pioenvs\disco_f769ni\firmware.elf] Error 1
[ERROR] Took 32.67 seconds

strange thing I noticed that it starts with installing a new compiler packages, but when i run the update packages command this get uninstalled again… output:

Platform ST STM32

Updating ststm32 @ 3.3.0 [Up-to-date]
Updating framework-mbed @ 4.146.0 [Up-to-date]
Updating tool-openocd @ 1.1000.3 [Up-to-date]
Updating toolchain-gccarmnoneeabi @ 1.40804.0 [Skip]
Uninstalling toolchain-gccarmnoneeabi @ 1.60301.0: [OK]

Platform Teensy

Updating teensy @ 2.3.0 [Up-to-date]
Updating toolchain-atmelavr @ 1.40902.0 [Up-to-date]
Updating framework-arduinoteensy @ 1.136.0 [Up-to-date]
Updating tool-teensy @ 1.21.0 [Up-to-date]
Updating framework-mbed @ 4.146.0 [Up-to-date]
Updating toolchain-gccarmnoneeabi @ 1.40804.0 [Up-to-date]

you can see the library manager uninstalls the newer toolchain, but when i press build it gets installed again.

Can somebody tell me what I’m missing here?

It looks like rtos is missing.

You need to enable RTOS by passing some build arguments in platformio.ini

Try this,

build_flags = -Wall -lc -DPIO_FRAMEWORK_MBED_RTOS_PRESENT

Thanks for the replies! It now compiles fine.

Only thing I’m still curious about is: why it was necessary to add the rtos flag. In my day job I get spoiled with managed and scripting languages, so when I have to get back to c/c++ I can read and understand most of it, but I keep being surprised by the amount of what I would call “configuration” that needs to be done to get things compiling. If the rtos is needed why did the ethernet/lwip feature not pull it in automatically? Would that be a platformio/mbed bug or a lack of knowledge on my part.

I think PIO authors have intentionally left RTOS to be enabled by explicitly passing a build_arg. This is probably because RTOS features are not needed unless you are developing a real-time application and it takes up some resources from the MCU. But I get your point, PIO should be able to detect whether “rtos.h” has been included and automatically handle those dependencies.

Have a look to http://docs.platformio.org/en/latest/frameworks/mbed.html#configuration
This gives a backward compatibility to mbed 2.