Hi3861 OpenHarmony嵌入式应用入门--hello world

这篇文章我们开始根据自己的开发板编写测试例程,通过编写例程来更好的学习。

目的:使用开发板上电后周期性打印"hello world"

我们需要创建自己的开发板工程目录,这里大部分时候会参考hqyj开发板的目录,但是我们会从0开始,这样能够更好的了解我们的工程中有哪些是我们自己的,哪些是鸿蒙sdk的。

修改D:\DevEcoProjects\test\src\applications\sample\wifi-iot\app\BUILD.gn文件

# Copyright (c) 2020 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import("//build/lite/config/component/lite_component.gni")

lite_component("app") {
    features = [
#        "startup",
         "//vendor/rtplay/rt_hi3861/demo:demo",
    ]
}

在D:\DevEcoProjects\test\src\vendor创建文件夹rtplay,里面创建rt_hi3861,编写config文件,复制D:\DevEcoProjects\test\src\vendor\hqyj\fs_hi3861\config.json文件为 D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\config.json,并修改里面的开发板信息。

{
    "product_name": "rt_hi3861",
    "ohos_version": "OpenHarmony 1.0",
    "device_company": "rtplay",
    "board": "rtplay_hi3861",
    "kernel_type": "liteos_m",
    "kernel_version": "",
    "subsystems": [
      {
        "subsystem": "applications",
        "components": [
          { "component": "wifi_iot_sample_app", "features":[] }
        ]
      },
      {
        "subsystem": "iot_hardware",
        "components": [
          { "component": "iot_controller", "features":[] }
        ]
      },
      {
        "subsystem": "hiviewdfx",
        "components": [
          { "component": "hilog_lite", "features":[] }
        ]
      },
      {
        "subsystem": "distributed_schedule",
        "components": [
          { "component": "samgr_lite", "features":[] }
        ]
      },
      {
        "subsystem": "security",
        "components": [
          { "component": "hichainsdk", "features":[] },
          { "component": "deviceauth_lite", "features":[] },
          { "component": "huks", "features":
            [
              "disable_huks_binary = false",
              "disable_authenticate = false",
              "huks_use_lite_storage = true",
              "huks_use_hardware_root_key = true",
              "huks_config_file = \"hks_config_lite.h\"",
              "huks_mbedtls_path = \"//device/hisilicon/hispark_pegasus/sdk_liteos/third_party/mbedtls/include/\""
            ]
          }
        ]
      },
      {
        "subsystem": "startup",
        "components": [
          { "component": "bootstrap_lite", "features":[] },
          { "component": "syspara_lite", "features":
            [
              "enable_ohos_startup_syspara_lite_use_thirdparty_mbedtls = false"
            ]
          }
        ]
      },
      {
        "subsystem": "communication",
        "components": [
          { "component": "wifi_lite", "features":[] },
          { "component": "softbus_lite", "features":[] },
          { "component": "wifi_aware", "features":[]}
        ]
      },
      {
        "subsystem": "update",
        "components": [
          { "component": "ota_lite", "features":[] }
        ]
      },
      {
        "subsystem": "iot",
        "components": [
          { "component": "iot_link", "features":[] }
        ]
      },
      {
        "subsystem": "utils",
        "components": [
          { "component": "file", "features":[] },
          { "component": "kv_store", "features":[] },
          { "component": "os_dump", "features":[] }
        ]
      },
      {
        "subsystem": "vendor",
        "components": [
          { "component": "hi3861_sdk", "target": "//device/hisilicon/hispark_pegasus/sdk_liteos:wifiiot_sdk", "features":[] }
        ]
      }
    ],
    "third_party_dir": "//device/hisilicon/hispark_pegasus/sdk_liteos/third_party",
    "product_adapter_dir": "//vendor/hisilicon/hispark_pegasus/hals"
  }

创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#    http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. 

import("//build/lite/config/component/lite_component.gni")

lite_component("demo") {
  features = [
    "base_00_hellowrold:base_helloworld_example",
  ]
}

创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_00_helloworld文件夹

文件夹中创建D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_00_helloworld\base_helloworld_example.c文件D:\DevEcoProjects\test\src\vendor\rtplay\rt_hi3861\demo\base_00_helloworld\BUILD.gn文件

# Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License. 

static_library("base_led_example") {
    sources = [
        "base_helloworld_example.c",
    ]

    include_dirs = [
        "//utils/native/lite/include",
        "//kernel/liteos_m/kal/cmsis",
        "//base/iot_hardware/peripheral/interfaces/kits",
        "//vendor/hqyj/fs_hi3861/common/bsp/include"
    ]
}

/*
 * Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <stdio.h>
#include <unistd.h>

#include "cmsis_os2.h"
#include "ohos_init.h"

osThreadId_t Task1_ID = 0;    //  任务1 ID
#define TASK_STACK_SIZE 1024
#define TASK_DELAY_TIME (1000 * 1000)

/**
 * @description: 任务1
 * @param {*}
 * @return {*}
 */
void Task1(void)
{
    printf("enter Task 1.......\r\n");

    while (1) {
        printf("hello world\r\n");
        usleep(TASK_DELAY_TIME);                      // 1s sleep
    }
}

/**
 * @description: 初始化并创建任务
 * @param {*}
 * @return {*}
 */
static void base_helloworld_demo(void)
{
    printf("[demo] Enter base_led_demo()!\r\n");

    osThreadAttr_t taskOptions;
    taskOptions.name = "Task1";                // 任务的名字
    taskOptions.attr_bits = 0;                 // 属性位
    taskOptions.cb_mem = NULL;                 // 堆空间地址
    taskOptions.cb_size = 0;                   // 堆空间大小
    taskOptions.stack_mem = NULL;              // 栈空间地址
    taskOptions.stack_size = TASK_STACK_SIZE;  // 栈空间大小 单位:字节
    taskOptions.priority = osPriorityNormal;   // 任务的优先级:wq

    Task1_ID = osThreadNew((osThreadFunc_t)Task1, NULL, &taskOptions);  // 创建任务1
    if (Task1_ID != NULL) {
        printf("ID = %d, Create Task1_ID is OK!\r\n", Task1_ID);
    }
}
SYS_RUN(base_helloworld_demo);

目录结构

│  config.json
│
├─common
│  └─bsp
│      ├─include
│      └─src
├─demo
│  │  BUILD.gn
│  │
│  └─base_00_helloworld
│         base_helloworld_example.c
│         BUILD.gn
└─doc
    │  HarmonyOS开发板实验指导书 v2.1.pdf
    │  华清远见 FS_Hi3861开发指导.md
    │  华清远见 FS_Hi3861新手入门手册.md
    │
    ├─board
    │      FS-Hi3861-V4.2.pdf
    │      FS-Hi3861QDB-V3.2.pdf
    │      hi-12f_kit_v1.1.0A7E6BCB9%A6-20211025.pdf
    │      hi-12f_v1.1.2-A7E6BCB9%A6-20211202.pdf
    │      nodemcu-hi-07s_12f-kit_v1.1-20210913.pdf
    │      RTplay2.01_2024-06-14.pdf
    │
    └─figures

使用build

不出意外会出现如下

下载程序,具体流程详见烧写博文

间隔1秒打印hello world。

相关推荐
Damon小智1 小时前
HarmonyOS NEXT 技术实践-基于基础视觉服务的多目标识别
华为·harmonyos
爱笑的眼睛1119 小时前
uniapp 极速上手鸿蒙开发
华为·uni-app·harmonyos
K.P20 小时前
鸿蒙元服务从0到上架【第三篇】(第二招有捷径)
华为·harmonyos·鸿蒙系统
K.P21 小时前
鸿蒙元服务从0到上架【第二篇】
华为·harmonyos·鸿蒙系统
敲代码的小强1 天前
Flutter项目兼容鸿蒙Next系统
flutter·华为·harmonyos
程序猿会指北1 天前
纯血鸿蒙APP实战开发——Text实现部分文本高亮和超链接样式
移动开发·harmonyos·arkts·openharmony·arkui·组件化·鸿蒙开发
鸿蒙自习室1 天前
鸿蒙开发——关系型数据库的基本使用与跨设备同步
前端·数据库·华为·harmonyos·鸿蒙
SoraLuna2 天前
「Mac畅玩鸿蒙与硬件45」UI互动应用篇22 - 评分统计工具
开发语言·macos·ui·华为·harmonyos
资讯分享周2 天前
鸿蒙风起,未来已来——云学堂鸿蒙应用认证开营啦!
华为·harmonyos
Lincode122 天前
HarmonyOS--鸿蒙三方库--lottie
华为·harmonyos