【嵌入式AI】全志 XR806 say hello world

極智視界發表於2021-12-27

歡迎關注我的公眾號 [極智視界],回覆001獲取Google程式設計規範

O_o >_<  o_O O_o ~_~ o_O

大家好,我是極智視界,本文介紹了全志 XR806 say hello world 實現。

我們們之前已經完成了 XR806 鴻蒙系統的韌體編譯和韌體燒錄,得到的終端輸出類似這樣:

【嵌入式AI】全志 XR806 say hello world

  這裡進入下一階段,先讓 XR806 板子來一下 blink、blink,以示準備就緒。

  在串列埠除錯命令終端輸入如下指令:

hm iot pwm init p=2
hm iot pwd

  看板子的燈 blink~blink~blink~

 

接下來開始實現 hello world。

  需要重新走一遍韌體編譯與韌體燒錄,開啟 <xr806_openharmony_path>/device/xradio/xr806/BUILD.gn,配置為啟用 deps += "ohosdemo:ohosdemo",如下:

# device/xradio/xr806/BUILD.gn

import("//build/lite/config/subsystem/lite_subsystem.gni")
import("//build/lite/config/component/lite_component.gni")
import("//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 = [
   "//build/lite/:ohos",
   "//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 += [
     "//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",
  ]
}

到這裡配置就可以了,為了更加深入一些,我們們繼續看,<xr806_openharmony_path>/device/xradio/xr806/ohosdemo 目錄結構如下:

-
|-- 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("//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 += [
     "//kernel/liteos_m/kernel/arch/include",
  ]
}

  最後的實現在 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 的整個邏輯,下面要做的就是重新走一遍韌體編譯和燒錄,然後終端展示:

【嵌入式AI】全志 XR806 say hello world

  [注]

  解決終端輸出偏移問題,類似:

【嵌入式AI】全志 XR806 say hello world

  對於 Xshell 和 MobaXterm 分別提供解決方法。

  • Xshell:

【嵌入式AI】全志 XR806 say hello world

  work 了:

【嵌入式AI】全志 XR806 say hello world

  • MobaXterm:

  (1) Setting->Configuration->Terminal->Terminal features 取消 "Paste using right-click":

【嵌入式AI】全志 XR806 say hello world

(2) 右擊終端選擇 "Change Terminal Settings",然後勾選 "Implicit CR in every LF":

【嵌入式AI】全志 XR806 say hello world

【嵌入式AI】全志 XR806 say hello world

  這樣就 work 了:

【嵌入式AI】全志 XR806 say hello world

 

以上分享了全志 XR806 板子 say hello 的過程,希望我的分享能對你的學習有一點幫助。

 

【公眾號傳送】

【嵌入式AI】全志 XR806 say hello world

相關文章