头图

Welcome to pay attention to my public account [Extreme Wisdom Vision], reply 001 to get Google programming specification

O_o>_<   o_OO_o~_~o_O

Hello everyone, I am Jizhi Vision. This article introduces the implementation of Quanzhi XR806 say hello world.

We have completed the firmware compilation and firmware burning of the XR806 Hongmeng system before, and the terminal output obtained is similar to this:

Entering the next stage here, let the XR806 board blink and blink first to show that it is ready.

Enter the following command in the serial port debugging command terminal:

hm iot pwm init p=2
hm iot pwm start p=2 d=50 f=5

Kanban lights blink~blink~blink~

Next, start implementing hello world.

You need to go through the firmware compilation and firmware burning again, open <xr806_openharmony_path>/device/xradio/xr806/BUILD.gn , and configure it to enable deps += "ohosdemo:ohosdemo" , as follows:

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

Follow the directions to <xr806_openharmony_path>/device/xradio/xr806/ohosdemo/BUILD.gn and enable deps = "hello_demo:app_hello" as follows:

# device/xradio/xr806/ohosdemo/BUILD.gn

group("ohosdemo") {
    deps = [
        "hello_demo:app_hello",
        #"iot_peripheral:app_peripheral",
        #"wlan_demo:app_WlanTest",
    ]
}

You can configure it here. In order to go deeper, let's continue to see. The <xr806_openharmony_path>/device/xradio/xr806/ohosdemo is as follows:

-
|-- hello_demo
|  |-- src
|      |-- main.c
|  |-- BUILD.gn
|-- iot_peripheral
|  |-- ...
|-- wlan_demo
|  |-- ...
|-- BUILD.gn

Take a look at BUILD.gn in the hello_demo folder:

# 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",
   ]
}

The final implementation is in src/main.c , the code is very simple:

#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);

The above is the entire logic of XR806 say hello world. The next thing to do is to go through the firmware compilation and burning again, and then display it in the terminal:

[Note]

Solve terminal output offset problem , similar to:

There are separate workarounds for Xshell and MobaXterm.

  • Xshell:

worked:

  • MobaXterm:

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

(2) Right-click the terminal and select "Change Terminal Settings", then check "Implicit CR in every LF":

This works:

The above has shared the process of saying hello on the Allwinner XR806 board. I hope my sharing can help you in your study.


【Public number transmission】
[Embedded AI] Allwinner XR806 say hello world


极智视界
13 声望4 粉丝