关于人工智能:嵌入式AI全志-XR806-say-hello-world

6次阅读

共计 2579 个字符,预计需要花费 7 分钟才能阅读完成。

欢送关注我的公众号 [极智视界],回复 001 获取 Google 编程标准

O_o>_<   o_OO_o~_~o_O

  大家好,我是极智视界,本文介绍了全志 XR806 say hello world 实现。

  咱们之前曾经实现了 XR806 鸿蒙零碎的固件编译和固件烧录,失去的终端输入相似这样:

     

   这里进入下一阶段,先让 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 的整个逻辑,上面要做的就是从新走一遍固件编译和烧录,而后终端展现:

     

   [注]

   解决 终端输入偏移问题,相似:

     

   对于 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 的过程,心愿我的分享能对你的学习有一点帮忙。


【公众号传送】
《【嵌入式 AI】全志 XR806 say hello world》

正文完
 0