7 years, 8 months ago.

How to use available libraries from within mbed-os?

I have pulled down a fresh copy of mbed-os by using the mbed-cli tool.

    $ mbed new mbed-os-test
    [mbed] Creating new program "mbed-os-test" (git)
    [mbed] Adding library "mbed-os" from "https://github.com/ARMmbed/mbed-os" at latest revision in the current branch
    [mbed] Updating reference "mbed-os" -> "https://github.com/ARMmbed/mbed-os/#dda7f7d77abd4330b05e686ce3bbe58230eb7876"

Ultimately I am working to enable uVisor on my NXP FRDM-K64F device, but for now I am only using the QuickStart tutorial to get a simple example working without enabling the uVisor.

So, as suggested in the link above, I make a source directory in the newly created clone of mbed-os:

    $ mkdir mbed-os-test/mbed-os/source

I copy in the basic main.cpp and compile. It works. However, when I try and create a problem using some of the library routines - specifically EthernetInterface.

Replacing my simple main.cpp from the uVisor example with the more complicated one (using EthernetInterface) from the above link:

    #include "mbed.h"
    #include "EthernetInterface.h"
     
    int main() {
        EthernetInterface eth;
        eth.init(); //Use DHCP
        eth.connect();
        printf("IP Address is %s\n", eth.getIPAddress());
        
        TCPSocketConnection sock;
        sock.connect("mbed.org", 80);
        
        char http_cmd[] = "GET /media/uploads/mbed_official/hello.txt HTTP/1.0\n\n";
        sock.send_all(http_cmd, sizeof(http_cmd)-1);
        
        char buffer[300];
        int ret;
        while (true) {
            ret = sock.receive(buffer, sizeof(buffer)-1);
            if (ret <= 0)
                break;
            buffer[ret] = '\0';
            printf("Received %d chars from server:\n%s\n", ret, buffer);
        }
          
        sock.close();
        
        eth.disconnect();
        
        while(1) {}
    }

Compiling with:

mbed compile -m K64F -t GCC_ARM

I am met with compilation errors stating that the EthernetInterface class does not have members that I am trying to invoke.

    ../../mbed-os/source/main.cpp: In function 'int main()':
    ../../mbed-os/source/main.cpp:34:9: error: 'class EthernetInterface' has no member named 'init'
         eth.init(); //Use DHCP
             ^
    ../../mbed-os/source/main.cpp:36:38: error: 'class EthernetInterface' has no member named 'getIPAddress'
         printf("IP Address is %s\n", eth.getIPAddress());
                                          ^
    ../../mbed-os/source/main.cpp:38:5: error: 'TCPSocketConnection' was not declared in this scope
         TCPSocketConnection sock;
         ^
    ../../mbed-os/source/main.cpp:39:5: error: 'sock' was not declared in this scope
         sock.connect("mbed.org", 80);
         ^

When, of course, the EthernetInterface class does have such members. I think the problem is related to the mbed utilities not compiling against the correct source code because it seems to find the header. If I add a source= option to the mbed compilation I am met with other errors regarding things that EthernetInterface.cpp includes.

$ mbed compile -m K64F -t GCC_ARM --source=../libraries/net/eth/EthernetInterface/
[ERROR] In file included from ../libraries/net/eth/EthernetInterface/EthernetInterface.cpp:19:0:
../libraries/net/eth/EthernetInterface/EthernetInterface.h:27:18: fatal error: rtos.h: No such file or directory

...

The files are certainly contained with mbed-os, I am just not sure how to actually use them.

    $ find . -name EthernetInterface.cpp
    ./libraries/net/eth/EthernetInterface/EthernetInterface.cpp
    ./features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.cpp

tl;dr; How can we use the library utilities included in mbed-os?

2 Answers

7 years, 7 months ago.

Same problem..!

7 years, 7 months ago.

Apparently you got two different versions of the Ethernet interface in your project.

One from https://developer.mbed.org/handbook/Ethernet-Interface and the other from mbed-os. What you could do is to remove the one which doesn't come with the OS or ignore one or the other.

It is easy to ignore path with mbed-cli:

  • First create a file named .mbedignore at the root of your project.
  • Every line correspond to a path to ignore when mbed-cli build your project.

For instance, if you want to ignore every file in the libraries folder, add the following line to this file:

.mbedignore

libraries/*

You can add several path to ignore, it should help you, as a workaround.

Thanks for the reply. As it turns out, there are actually two implementations of EthernetInterface/LwIP within mbed-os.

$ find . -name "EthernetInterface.cpp"
./libraries/net/eth/EthernetInterface/EthernetInterface.cpp
./features/net/FEATURE_IPV4/lwip-interface/EthernetInterface.cpp

The one that gets compiled/linked against is in mbed-os/features/ rather than mbed-os/libraries/.

On Github:

https://github.com/ARMmbed/mbed-os/tree/master/features/net/FEATURE_IPV4/lwip-interface

https://github.com/ARMmbed/mbed-os/tree/master/libraries/net/eth

posted by Branden Sherrell 31 Aug 2016

This is a bit strange, the library folder is supposed to be ignored:

https://github.com/ARMmbed/mbed-os/blob/master/libraries/.mbedignore

What is your version of mbed-cli ?

posted by Vincent (pan-) Coubard 31 Aug 2016

You are correct, it is being ignored. The main problem here is that the implementation in "features" has a lot less functionality than the code in "libraries". My initial confusion was rooted in the fact that the EthernetInterface API documentation lists class methods that are not available in the "features" version of the EthernetInterface code, while the "libraries" version does have it. For instance, the "init" method is documented (see below) as an exported API function, but you get a compilation error because it is implemented in the "libraries" source tree while we compile/link against the "features" source tree.

https://developer.mbed.org/handbook/Ethernet-Interface

If "libraries" is ignored, why is it present at all? It seems to provide more functionality than is available in the other implementations.

It seems we are caught in a time period where older libraries are still being ported over to mbed-os.

posted by Branden Sherrell 31 Aug 2016

mbed os 2 and mbed os 5 share the same common base.

The libraries folder was here for mbed os 2 development and test. In the link you've just post, it is a explicitly indicated that it is the legacy networking libraries and the link to the library up to date is provided: https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/network_sockets/

If you miss any feature, please post and issue in our issue tracker: https://github.com/ARMmbed/mbed-os/issues

posted by Vincent (pan-) Coubard 31 Aug 2016

This is what I finally concluded. I seemed to have missed the large notice on that page when I first looked last week.

Although it may not be related to your work specifically, there seems to be a critical bug between uVisor and the EthernetInterface/LwIP/Hal implementations such that the Ethernet hardware becomes unusable once uVisor has been enabled. I posted an issue on the mbed-os and uVisor github pages to track this problem. I am unsure who has the responsibility to address these bugs.

https://github.com/ARMmbed/uvisor/issues/315

posted by Branden Sherrell 31 Aug 2016

For your issue, I believe @merriac on Github is taking care of it.

posted by Vincent (pan-) Coubard 31 Aug 2016