5 years, 12 months ago.

EthernetInterface errors while compiling with FRDM-K64F

Hello, I have tried a basic code for EthernetInterface from your cookbooks to start with ethernet communication with FRDM-K64F.

Ethernet

#include "mbed.h"
#include "EthernetInterface.h"

// Network interface
EthernetInterface net;

// Socket demo
int main() {
    // Set static IP
    net.set_network("172.16.23.240", "255.255.255.0", "172.16.23.1");

    // Bring up the ethernet interface
    printf("Ethernet socket example\n");
    net.connect();

    // Show the network address
    const char *ip = net.get_ip_address();
    printf("IP address is: %s\n", ip ? ip : "No IP");

    printf("MAC address is: %s\n", net.get_mac_address());

    // Open a socket on the network interface, and create a TCP connection to mbed.org
    TCPSocket socket;
    socket.open(&net);
    socket.connect("developer.mbed.org", 80);

    // Send a simple http request
    char sbuffer[] = "GET / HTTP/1.1\r\nHost: developer.mbed.org\r\n\r\n";
    int scount = socket.send(sbuffer, sizeof sbuffer);
    printf("sent %d [%.*s]\n", scount, strstr(sbuffer, "\r\n")-sbuffer, sbuffer);

    // Recieve a simple http response and print out the response line
    char rbuffer[64];
    int rcount = socket.recv(rbuffer, sizeof rbuffer);
    printf("recv %d [%.*s]\n", rcount, strstr(rbuffer, "\r\n")-rbuffer, rbuffer);

    // Close the socket to return its memory and bring down the network interface
    socket.close();

    // Bring down the ethernet interface
    net.disconnect();
    printf("Done\n");
}

However a few compile errors occured:

Error: Identifier "socklen_t" is undefined in "EthernetInterface/Socket/Socket.h", Line: 66, Col: 59 Error: Incomplete type is not allowed in "EthernetInterface/Socket/Socket.h", Line: 101, Col: 21 Error: Incomplete type is not allowed in "EthernetInterface/Socket/Endpoint.h", Line: 59, Col: 25 Error: Identifier "SOCK_STREAM" is undefined in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 30, Col: 22 Error: Incomplete type is not allowed in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 33, Col: 25 Error: Identifier "AF_INET" is undefined in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 36, Col: 29 Error: Identifier "htons" is undefined in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 37, Col: 27 Error: Identifier "INADDR_ANY" is undefined in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 38, Col: 34 Error: Identifier "lwip_bind" is undefined in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 40, Col: 10 Error: Identifier "lwip_listen" is undefined in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 52, Col: 10 Error: Identifier "socklen_t" is undefined in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 70, Col: 6 Error: Identifier "lwip_accept" is undefined in "EthernetInterface/Socket/TCPSocketServer.cpp", Line: 71, Col: 15

No matter what code I use, this one or any template for FRDM-K64F with EthernetInterface, this compile errors appear.

I am using newest mbed-os ( 5.8.3 ) and newest EthernetInterface (rev. 54) including sub libraries.

Yes I did checked this thread: https://os.mbed.com/questions/5225/EthernetInterface-produces-compile-error/

Any suggestions?

Thank you.

Patrik Maraczek

2 Answers

5 years, 12 months ago.

Hi Patrik,

Perhaps something has gone wrong migrating an old project. Can you follow these steps using Mbed CLI and let us know how they work:

$ mbed new ethernet_test
$ cd ethernet_test
(place your source file into the ethernet_test folder)
$ mbed ls
ethernet_test ( revision in the current branch)
`- mbed-os (#c05d72c3c005, tags: latest, mbed-os-5.8.3)
$ mbed compile -m k64f -t arm

You should see this output:

Building project ethernet_test (K64F, ARM)
Scan: .
Scan: env
Scan: mbed
...
Compile [ 99.5%]: fsl_common.c
Compile [ 99.8%]: patrik.cpp
Compile [100.0%]: test_env.cpp
Link: ethernet_test
Elf2Bin: ethernet_test
+------------------+--------+-------+-------+
| Module           |  .text | .data |  .bss |
+------------------+--------+-------+-------+
| [lib]\c_w.l      |  13717 |    16 |   576 |
| [lib]\cpprt_w.l  |     42 |     0 |     0 |
| [lib]\fz_wm.l    |     18 |     0 |     0 |
| [lib]\m_wm.l     |     48 |     0 |     0 |
| anon$$obj.o      |     32 |     0 |  1024 |
| mbed-os\drivers  |    165 |     0 |     0 |
| mbed-os\features |  52204 |   447 | 45827 |
| mbed-os\hal      |   1612 |     8 |    64 |
| mbed-os\platform |   2548 |    89 |   412 |
| mbed-os\rtos     |  17477 |  2310 |  4592 |
| mbed-os\targets  |  12216 |   104 |   324 |
| patrik.o         |    492 |     0 |    76 |
| Subtotals        | 100571 |  2974 | 52895 |
+------------------+--------+-------+-------+
Total Static RAM memory (data + bss): 55869 bytes
Total Flash memory (text + data): 103545 bytes

Image: .\BUILD\k64f\arm\ethernet_test.bin

-Ralph, Team Mbed

What do you mean with source file? The example i used above? Including EthernetInterface library?

posted by Patrik Maraczek 04 May 2018

I see his output with the example above without library:

C:\Users\Michal\ethernet_test>mbed ls
ethernet_test (None)
`- mbed-os (c05d72c3c005)

C:\Users\Michal\ethernet_test>mbed compile -m k64f -t arm
usage: make.py [-h] [-m MCU] [-t TOOLCHAIN] [--color] [--cflags CFLAGS]
               [--asmflags ASMFLAGS] [--ldflags LDFLAGS] [-c]
               [--profile PROFILE] [--app-config APP_CONFIG] [-p PROGRAM]
               [-n PROGRAM] [-j JOBS] [-v] [--silent] [-D MACROS]
               [-S [{matrix,toolchains,targets}]] [-f GENERAL_FILTER_REGEX]
               [--stats-depth STATS_DEPTH] [--automated] [--host HOST_TEST]
               [--extra EXTRA] [--peripherals PERIPHERALS]
               [--dep DEPENDENCIES] [--source SOURCE_DIR]
               [--duration DURATION] [--build BUILD_DIR] [-N ARTIFACT_NAME]
               [-d DISK] [-s SERIAL] [-b BAUD] [-L] [--rpc] [--usb] [--dsp]
               [--testlib] [--build-data BUILD_DATA] [-l LINKER_SCRIPT]
make.py: error: Could not find executable for ARM.
Currently set search path: No path set
[mbed] ERROR: "C:\Python27\python.exe" returned error code 2.
[mbed] ERROR: Command "C:\Python27\python.exe -u C:\Users\Michal\ethernet_test\mbed-os\tools\make.py -t arm -m k64f --source . --build .\BUILD\k64f\arm" in "C:\Users\Michal\ethernet_test"
---

I have never used Mbed CLI, there might be errors in settings.

posted by Patrik Maraczek 04 May 2018

Ok. I finally get it work using gcc_arm and source code from the example. And i got the same output result as yours:

Compile [ 99.8%]: fsl_common.c
Compile [100.0%]: test_env.cpp
Link: ethernet_test
Elf2Bin: ethernet_test
+------------------+--------+-------+-------+
| Module           |  .text | .data |  .bss |
+------------------+--------+-------+-------+
| [fill]           |    215 |     8 |  2237 |
| [lib]\c.a        |  43529 |  2472 |    89 |
| [lib]\gcc.a      |   3336 |     0 |     0 |
| [lib]\misc       |    204 |     4 |    28 |
| [lib]\nosys.a    |     32 |     0 |     0 |
| main.o           |    574 |     0 |    76 |
| mbed-os\drivers  |     98 |     0 |     0 |
| mbed-os\features |  46077 |   172 | 46072 |
| mbed-os\hal      |   1573 |     4 |    68 |
| mbed-os\platform |   1891 |   260 |    21 |
| mbed-os\rtos     |  13593 |   168 |  6073 |
| mbed-os\targets  |  11121 |    12 |   384 |
| Subtotals        | 122243 |  3100 | 55048 |
+------------------+--------+-------+-------+
Total Static RAM memory (data + bss): 58148 bytes
Total Flash memory (text + data): 125343 bytes

Image: .\BUILD\k64f\gcc_arm\ethernet_test.bin

Any suggestions what to do next?

(Sorry for the previous confused comments. Somehow cannot edit them or delete.)

posted by Patrik Maraczek 04 May 2018

Now that you have the project building you can add the "-f" option to have it flashed to the target for testing:

$ mbed compile -m k64f -t arm -f

A good tutorial on the CLI is available here and the official readme is on the project page: https://os.mbed.com/docs/v5.8/tutorials/quick-start-offline.html https://github.com/ARMmbed/mbed-cli

posted by Ralph Fulchiero 07 May 2018

Flashing works, however, I am afraid I misunderstood your first answer. I used source code without ethernetinterface library. Now when compiling with library, fllowing errors appears using CLI:

.....
Scan: FEATURE_STORAGE
Compile [  0.2%]: Endpoint.cpp
[Warning] ip_addr.h@213,23: C++11 requires a space between string literal and macro [-Wc++11-compat]
[Warning] ip_addr.h@213,31: C++11 requires a space between string literal and macro [-Wc++11-compat]
[Warning] ip_addr.h@213,40: C++11 requires a space between string literal and macro [-Wc++11-compat]
[Warning] ip_addr.h@213,49: C++11 requires a space between string literal and macro [-Wc++11-compat]
[Error] _timeval.h@52,8: redefinition of 'struct timeval'
[ERROR] In file included from ./EthernetInterface/lwip/include/lwip/sockets.h:43:0,
                 from ./EthernetInterface/Socket/Socket.h:21,
                 from .\EthernetInterface\Socket\Endpoint.cpp:18:
./EthernetInterface/lwip/include/ipv4/lwip/ip_addr.h:213:23: warning: C++11 requires a space between string literal and macro [-Wc++11-compat]
   LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,             \
                       ^
./EthernetInterface/lwip/include/ipv4/lwip/ip_addr.h:213:31: warning: C++11 requires a space between string literal and macro [-Wc++11-compat]
   LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,             \
                               ^
./EthernetInterface/lwip/include/ipv4/lwip/ip_addr.h:213:40: warning: C++11 requires a space between string literal and macro [-Wc++11-compat]
   LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,             \
                                        ^
./EthernetInterface/lwip/include/ipv4/lwip/ip_addr.h:213:49: warning: C++11 requires a space between string literal and macro [-Wc++11-compat]
   LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F,             \
 .....
 .....    

Errors are pointing to the EthernetInterface library, like it does using mbed online compiling.

Any suggestions?

Thank you

posted by Patrik Maraczek 10 May 2018
5 years, 11 months ago.