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


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

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

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

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

    1. # Copyright (c) 2020 Huawei Device Co., Ltd.
    2. # Licensed under the Apache License, Version 2.0 (the "License");
    3. # you may not use this file except in compliance with the License.
    4. # You may obtain a copy of the License at
    5. #
    6. # http://www.apache.org/licenses/LICENSE-2.0
    7. #
    8. # Unless required by applicable law or agreed to in writing, software
    9. # distributed under the License is distributed on an "AS IS" BASIS,
    10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11. # See the License for the specific language governing permissions and
    12. # limitations under the License.
    13. import("//build/lite/config/component/lite_component.gni")
    14. lite_component("app") {
    15. features = [
    16. # "startup",
    17. "//vendor/rtplay/rt_hi3861/demo:demo",
    18. ]
    19. }

    在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,并修改里面的开发板信息。

    1. {
    2. "product_name": "rt_hi3861",
    3. "ohos_version": "OpenHarmony 1.0",
    4. "device_company": "rtplay",
    5. "board": "rtplay_hi3861",
    6. "kernel_type": "liteos_m",
    7. "kernel_version": "",
    8. "subsystems": [
    9. {
    10. "subsystem": "applications",
    11. "components": [
    12. { "component": "wifi_iot_sample_app", "features":[] }
    13. ]
    14. },
    15. {
    16. "subsystem": "iot_hardware",
    17. "components": [
    18. { "component": "iot_controller", "features":[] }
    19. ]
    20. },
    21. {
    22. "subsystem": "hiviewdfx",
    23. "components": [
    24. { "component": "hilog_lite", "features":[] }
    25. ]
    26. },
    27. {
    28. "subsystem": "distributed_schedule",
    29. "components": [
    30. { "component": "samgr_lite", "features":[] }
    31. ]
    32. },
    33. {
    34. "subsystem": "security",
    35. "components": [
    36. { "component": "hichainsdk", "features":[] },
    37. { "component": "deviceauth_lite", "features":[] },
    38. { "component": "huks", "features":
    39. [
    40. "disable_huks_binary = false",
    41. "disable_authenticate = false",
    42. "huks_use_lite_storage = true",
    43. "huks_use_hardware_root_key = true",
    44. "huks_config_file = \"hks_config_lite.h\"",
    45. "huks_mbedtls_path = \"//device/hisilicon/hispark_pegasus/sdk_liteos/third_party/mbedtls/include/\""
    46. ]
    47. }
    48. ]
    49. },
    50. {
    51. "subsystem": "startup",
    52. "components": [
    53. { "component": "bootstrap_lite", "features":[] },
    54. { "component": "syspara_lite", "features":
    55. [
    56. "enable_ohos_startup_syspara_lite_use_thirdparty_mbedtls = false"
    57. ]
    58. }
    59. ]
    60. },
    61. {
    62. "subsystem": "communication",
    63. "components": [
    64. { "component": "wifi_lite", "features":[] },
    65. { "component": "softbus_lite", "features":[] },
    66. { "component": "wifi_aware", "features":[]}
    67. ]
    68. },
    69. {
    70. "subsystem": "update",
    71. "components": [
    72. { "component": "ota_lite", "features":[] }
    73. ]
    74. },
    75. {
    76. "subsystem": "iot",
    77. "components": [
    78. { "component": "iot_link", "features":[] }
    79. ]
    80. },
    81. {
    82. "subsystem": "utils",
    83. "components": [
    84. { "component": "file", "features":[] },
    85. { "component": "kv_store", "features":[] },
    86. { "component": "os_dump", "features":[] }
    87. ]
    88. },
    89. {
    90. "subsystem": "vendor",
    91. "components": [
    92. { "component": "hi3861_sdk", "target": "//device/hisilicon/hispark_pegasus/sdk_liteos:wifiiot_sdk", "features":[] }
    93. ]
    94. }
    95. ],
    96. "third_party_dir": "//device/hisilicon/hispark_pegasus/sdk_liteos/third_party",
    97. "product_adapter_dir": "//vendor/hisilicon/hispark_pegasus/hals"
    98. }

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

    1. # Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
    2. # Licensed under the Apache License, Version 2.0 (the "License");
    3. # you may not use this file except in compliance with the License.
    4. # You may obtain a copy of the License at
    5. #
    6. # http://www.apache.org/licenses/LICENSE-2.0
    7. #
    8. # Unless required by applicable law or agreed to in writing, software
    9. # distributed under the License is distributed on an "AS IS" BASIS,
    10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11. # See the License for the specific language governing permissions and
    12. # limitations under the License.
    13. import("//build/lite/config/component/lite_component.gni")
    14. lite_component("demo") {
    15. features = [
    16. "base_00_hellowrold:base_helloworld_example",
    17. ]
    18. }

    创建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文件

    1. # Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
    2. # Licensed under the Apache License, Version 2.0 (the "License");
    3. # you may not use this file except in compliance with the License.
    4. # You may obtain a copy of the License at
    5. #
    6. # http://www.apache.org/licenses/LICENSE-2.0
    7. #
    8. # Unless required by applicable law or agreed to in writing, software
    9. # distributed under the License is distributed on an "AS IS" BASIS,
    10. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    11. # See the License for the specific language governing permissions and
    12. # limitations under the License.
    13. static_library("base_led_example") {
    14. sources = [
    15. "base_helloworld_example.c",
    16. ]
    17. include_dirs = [
    18. "//utils/native/lite/include",
    19. "//kernel/liteos_m/kal/cmsis",
    20. "//base/iot_hardware/peripheral/interfaces/kits",
    21. "//vendor/hqyj/fs_hi3861/common/bsp/include"
    22. ]
    23. }
    1. /*
    2. * Copyright (c) 2023 Beijing HuaQing YuanJian Education Technology Co., Ltd
    3. * Licensed under the Apache License, Version 2.0 (the "License");
    4. * you may not use this file except in compliance with the License.
    5. * You may obtain a copy of the License at
    6. *
    7. * http://www.apache.org/licenses/LICENSE-2.0
    8. *
    9. * Unless required by applicable law or agreed to in writing, software
    10. * distributed under the License is distributed on an "AS IS" BASIS,
    11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12. * See the License for the specific language governing permissions and
    13. * limitations under the License.
    14. */
    15. #include <stdio.h>
    16. #include <unistd.h>
    17. #include "cmsis_os2.h"
    18. #include "ohos_init.h"
    19. osThreadId_t Task1_ID = 0; // 任务1 ID
    20. #define TASK_STACK_SIZE 1024
    21. #define TASK_DELAY_TIME (1000 * 1000)
    22. /**
    23. * @description: 任务1
    24. * @param {*}
    25. * @return {*}
    26. */
    27. void Task1(void)
    28. {
    29. printf("enter Task 1.......\r\n");
    30. while (1) {
    31. printf("hello world\r\n");
    32. usleep(TASK_DELAY_TIME); // 1s sleep
    33. }
    34. }
    35. /**
    36. * @description: 初始化并创建任务
    37. * @param {*}
    38. * @return {*}
    39. */
    40. static void base_helloworld_demo(void)
    41. {
    42. printf("[demo] Enter base_led_demo()!\r\n");
    43. osThreadAttr_t taskOptions;
    44. taskOptions.name = "Task1"; // 任务的名字
    45. taskOptions.attr_bits = 0; // 属性位
    46. taskOptions.cb_mem = NULL; // 堆空间地址
    47. taskOptions.cb_size = 0; // 堆空间大小
    48. taskOptions.stack_mem = NULL; // 栈空间地址
    49. taskOptions.stack_size = TASK_STACK_SIZE; // 栈空间大小 单位:字节
    50. taskOptions.priority = osPriorityNormal; // 任务的优先级:wq
    51. Task1_ID = osThreadNew((osThreadFunc_t)Task1, NULL, &taskOptions); // 创建任务1
    52. if (Task1_ID != NULL) {
    53. printf("ID = %d, Create Task1_ID is OK!\r\n", Task1_ID);
    54. }
    55. }
    56. SYS_RUN(base_helloworld_demo);

    目录结构

    1. │ config.json
    2. ├─common
    3. │ └─bsp
    4. │ ├─include
    5. │ └─src
    6. ├─demo
    7. │ │ BUILD.gn
    8. │ │
    9. │ └─base_00_helloworld
    10. │ base_helloworld_example.c
    11. │ BUILD.gn
    12. └─doc
    13. │ HarmonyOS开发板实验指导书 v2.1.pdf
    14. │ 华清远见 FS_Hi3861开发指导.md
    15. │ 华清远见 FS_Hi3861新手入门手册.md
    16. ├─board
    17. │ FS-Hi3861-V4.2.pdf
    18. │ FS-Hi3861QDB-V3.2.pdf
    19. │ hi-12f_kit_v1.1.0A7E6BCB9%A6-20211025.pdf
    20. │ hi-12f_v1.1.2-A7E6BCB9%A6-20211202.pdf
    21. │ nodemcu-hi-07s_12f-kit_v1.1-20210913.pdf
    22. │ RTplay2.01_2024-06-14.pdf
    23. └─figures

    使用build

    不出意外会出现如下

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

    间隔1秒打印hello world。

  • 相关阅读:
    Docker(三)dockerfile命令说明(图文)
    认识前端包常用包管理工具(npm、cnpm、pnpm、nvm、yarn)
    2023软件测试面试题(亲身经历)
    服务器应用程序不可用的原因是什么引起的
    luogu P3842 [TJOI2007]线段
    golang linux下安装、环境变量配、置快速体验 beego(一)
    Ph.D,指哲学博士学位
    护眼灯显色指数怎么选?台灯显色指数Ra95和98哪个好
    Hadoop(五)C#操作Hive
    构建数据中台的组织架构
  • 原文地址:https://blog.csdn.net/andylauren/article/details/139743876