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。

相关推荐
yilylong6 分钟前
鸿蒙(Harmony)实现滑块验证码
华为·harmonyos·鸿蒙
baby_hua6 分钟前
HarmonyOS第一课——DevEco Studio的使用
华为·harmonyos
HarmonyOS_SDK33 分钟前
融合虚拟与现实,AR Engine为用户提供沉浸式交互体验
harmonyos
- 羊羊不超越 -2 小时前
App渠道来源追踪方案全面分析(iOS/Android/鸿蒙)
android·ios·harmonyos
长弓三石4 小时前
鸿蒙网络编程系列44-仓颉版HttpRequest上传文件示例
前端·网络·华为·harmonyos·鸿蒙
SameX5 小时前
鸿蒙 Next 电商应用安全支付与密码保护实践
前端·harmonyos
SuperHeroWu76 小时前
【HarmonyOS】键盘遮挡输入框UI布局处理
华为·harmonyos·压缩·keyboard·键盘遮挡·抬起
sanzk11 小时前
华为鸿蒙应用开发
华为·harmonyos
SoraLuna15 小时前
「Mac畅玩鸿蒙与硬件28」UI互动应用篇5 - 滑动选择器实现
macos·ui·harmonyos
ClkLog-开源埋点用户分析16 小时前
ClkLog企业版(CDP)预售开启,更有鸿蒙SDK前来助力
华为·开源·开源软件·harmonyos