大家好,我是極智視界,本文介紹了全志 XR806 say hello world 實現(xiàn)。
咱們之前已經(jīng)完成了 XR806 鴻蒙系統(tǒng)的固件編譯和固件燒錄,得到的終端輸出類似這樣:
這里進入下一階段恋追,先讓 XR806 板子來一下 blink、blink罚屋,以示準(zhǔn)備就緒苦囱。
在串口調(diào)試命令終端輸入如下指令:
hm iot pwm init p=2
hm iot pwm start p=2 d=50 f=5
看板子的燈 blinkblinkblink~
接下來開始實現(xiàn) hello world。
需要重新走一遍固件編譯與固件燒錄沿后,打開 <xr806_openharmony_path>/device/xradio/xr806/BUILD.gn
沿彭,配置為啟用 deps += "ohosdemo:ohosdemo"
,如下:
# device/xradio/xr806/BUILD.gn
import("http://build/lite/config/subsystem/lite_subsystem.gni")
import("http://build/lite/config/component/lite_component.gni")
import("http://base/security/huks/build/config.gni")
build_ext_component("libSDK") {
exec_path = rebase_path(".", root_build_dir)
outdir = rebase_path("$root_out_dir")
command = "./build.sh ${outdir}"
deps = [
"http://build/lite/:ohos",
"http://kernel/liteos_m:kernel",
"os:liteos_glue",
]
if (IsBootloader == "false") {
deps += [
"adapter/hals:adapter",
"adapter/console:app_console",
"ohosdemo:ohosdemo" # 啟用 ohosdemo
]
}
if (disable_huks_binary == true) {
deps += [
"http://base/security/huks/frameworks/huks_lite:huks_sdk",
]
}
}
group("xr806") {
}
循著指示到 <xr806_openharmony_path>/device/xradio/xr806/ohosdemo/BUILD.gn
尖滚,啟用 deps = "hello_demo:app_hello"
喉刘,如下:
# device/xradio/xr806/ohosdemo/BUILD.gn
group("ohosdemo") {
deps = [
"hello_demo:app_hello",
#"iot_peripheral:app_peripheral",
#"wlan_demo:app_WlanTest",
]
}
到這里配置就可以了瞧柔,為了更加深入一些,咱們繼續(xù)看睦裳,<xr806_openharmony_path>/device/xradio/xr806/ohosdemo
目錄結(jié)構(gòu)如下:
-
|-- hello_demo
| |-- src
| |-- main.c
| |-- BUILD.gn
|-- iot_peripheral
| |-- ...
|-- wlan_demo
| |-- ...
|-- BUILD.gn
來看一下 hello_demo 文件夾下的 BUILD.gn:
# device/xradio/xr806/ohosdemo/hello_demo/BUILD.gn
import("http://device/xradio/xr806/liteos_m/config.gni")
static_library("app_hello") { # 這里就很容易看懂 "hello_demo:app_hello"
configs = []
sources = [
"src/main.c",
]
cflags = board_cflags
include_dirs = board_include_dirs
include_dirs += [
"http://kernel/liteos_m/kernel/arch/include",
]
}
最后的實現(xiàn)在 src/main.c
造锅,代碼很簡單:
#include <stdio.h>
#include "ohos_init.h"
#include "kernel/os/os.h"
static OS_Thread_t g_main_thread;
static void MainThread(void *arg){ /// 每秒打印 hello world
while (1) {
printf("hello world!\n");
LOS_Msleep(1000);}
}
void HelloTestMain(void){
printf("Wifi Test Start\n");
if (OS_ThreadCreate(&g_main_thread, "MainThread", MainThread, NULL,
OS_THREAD_PRIO_APP, 4 * 1024) != OS_OK) {
printf("[ERR] Create MainThread Failed\n");}
}
SYS_RUN(HelloTestMain);
以上就是 XR806 say hello world 的整個邏輯,下面要做的就是重新走一遍固件編譯和燒錄廉邑,然后終端展示:
[注]
解決終端輸出偏移問題哥蔚,類似:
對于 Xshell 和 MobaXterm 分別提供解決方法。
- Xshell:
work 了:
- MobaXterm:
(1) Setting->Configuration->Terminal->Terminal features 取消 "Paste using right-click":
(2) 右擊終端選擇 "Change Terminal Settings"蛛蒙,然后勾選 "Implicit CR in every LF":
這樣就 work 了:
以上分享了全志 XR806 板子 say hello 的過程糙箍,希望我的分享能對你的學(xué)習(xí)有一點幫助。