2016-08-22 40 views
1

我已通過使用mbed-cli工具拉下了mbed-os的新副本。如何使用mbed-os中的可用庫?

$ 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" 

最終我的工作我的恩智浦FRDM-K64F設備上啓用uVisor,但現在我只使用了QuickStart教程得到一個簡單的例子,而不啓用uVisor工作。

所以,在上面的鏈接的建議,我做一個source目錄mbed-OS的新創建的克隆:

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

我的基本main.cpp複製和編譯。有用。但是,當我嘗試使用一些庫例程創建問題時,特別是EthernetInterface。我會見了編譯

mbed compile -m K64F -t GCC_ARM

#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) {} 
} 

與編譯:

從uVisor例如具有更復雜的一個(使用EthernetInterface)從上面的鏈接更換我的簡單main.cpp錯誤指出EthernetInterface類沒有我試圖調用的成員。

../../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); 
    ^

當,當然,EthernetInterface類確實有這樣的成員。我認爲這個問題與mbed工具沒有針對正確的源代碼編譯有關,因爲它似乎找到了頭文件。如果我將一個--source=選項添加到mbed編譯中,我遇到了有關EthernetInterface.cpp包含的其他錯誤。

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 

這些文件肯定包含有mbed-OS,我只是不知道如何真正使用他們。

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

TL;博士 - 我們怎麼能反對libraries/給出的庫代碼鏈接?我可以通過直接包含文件直接包含頭文件,但相應的源似乎位於features/目錄中,而不是libraries/中的那個。

+1

這個問題說mbed操作系統,但你鏈接的文檔是mbed經典,這是不一樣的事情。 [我在這裏沒有看到任何'init()'成員](https://docs.mbed.com/docs/mbed-os-api/en/mbed-os-5.1.0/api/features_2net_2FEATURE__IPV4_2lwip-interface_2EthernetInterface_8h_source。 HTML)(也不在超類)。 – Notlikethat

+0

@Notlikethat,有什麼區別?在我最後的問題末尾的'find'命令中,有兩個結果:'libraries'中的第一個是與[文檔]相對應的源文件(https://developer.mbed.org/handbook/Ethernet-Interface ),而'features'中的後者與您在評論中鏈接的源相同。如果我在源文件中包含「EthernetInterface.h」,它似乎包含後者而不是前者(它具有更多的特性,如'init'等)。 – sherrellbc

+1

_「本文檔涵蓋了可用於mbed 2的網絡庫。對於mbed 5,網絡庫已進行了修訂,以更好地支持更多的網絡堆棧和線程安全[此處](https://docs.mbed.com/docs/mbed -os-api-reference/en/5.1/APIs/communication/network_sockets /)。「__ - 據我所知,mbed Classic(版本2)基本上只是一套HAL庫,而mbed OS(版本5)是一個完整的以連接爲中心的RTOS,兩者之間存在重要的源級不兼容問題。儘管如此,我不能說我實際上曾經使用過自己。 – Notlikethat

回答

2

我想知道你在做什麼我失蹤,因爲這個工作對我來說:

$ mbed new ethernet-test 
$ cd ethernet-test 
$ mbed target K64F 
$ mbed toolchain GCC_ARM 

打開ethernet-test/main.cpp和投入:

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

int main(int, char**) { 
    EthernetInterface eth; 
    eth.connect(); 
} 

然後:

$ mbed compile 
... 
Total Flash memory (text + data + misc): 108092 bytes 
Image: ./.build/K64F/GCC_ARM/ethernet-test.bin 
+0

的確如此,但是,正如我發現的那樣,EthernetInterface實現具有更多的功能(如靜態分配而不是使用DHCP),可以在這裏找到(https://developer.mbed.org/handbook/Ethernet-Interface),還沒有成爲mbed5([來源](https://developer.mbed.org/questions/73258/How-does-mbed-cli-create-includes-and-li/))。雖然這兩個實現都包含在mbed repo中,但實際上只編譯了一個[this](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/network_sockets/)並與之相關聯。 – sherrellbc

+0

雖然有趣的是,我在上面提到的API([此處顯示](https://docs.mbed.com/docs/mbed-os-api-reference/en/5.1/APIs/communication/ethernet/))沒有實際上工作。如果您查看'features'目錄中的源文件(參見OP,'libraries'具有完整的實現,'features'似乎有一個子集),它只有'Public Member Functions'的代碼,而不是'靜態Public Member Functions「。嘗試使用狀態成員函數之一 - .e.g EthernetInterface.init()或類似的;這是行不通的。 – sherrellbc

相關問題