我已通過使用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/
中的那個。
這個問題說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
@Notlikethat,有什麼區別?在我最後的問題末尾的'find'命令中,有兩個結果:'libraries'中的第一個是與[文檔]相對應的源文件(https://developer.mbed.org/handbook/Ethernet-Interface ),而'features'中的後者與您在評論中鏈接的源相同。如果我在源文件中包含「EthernetInterface.h」,它似乎包含後者而不是前者(它具有更多的特性,如'init'等)。 – sherrellbc
_「本文檔涵蓋了可用於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