Bearpi Harmonyos
Bearpi Harmonyos
2023-10-11-bearpi-harmonyOS
office_link:bearpi-hm_nano
Preparation
- image:下载地址(百度云):https://pan.baidu.com/s/1T0Tcl3y48C1p5L6y-6HJNg 提取码:eusr
- HiBurn:下载地址(百度云):https://pan.baidu.com/s/1bp2ypAfH2HaNPTY2KwEhEA 提取码:1234
- VMware Workstation
- MobaXterm
- RaiDrive
- USB drive:http://www.wch.cn/search?q=ch340g&t=downloads
- VS Code
get and compile the source code
on project root directory
Method one (from gitee)
1
2
git clone https://gitee.com/bearpi/bearpi-hm_nano.git -b master // get
python build.py BearPi-HM_Nano // compile
Method two (by hpm)
1
2
3
4
hpm init -t default
hpm i @bearpi/bearpi_hm_nano //get source code
hpm dist // compile code
And projeck/out/BearPi-HM_Nano
is the path of bin file.
Burn
At this time press the reset button
View the serial port and print log
Compilation Instructions
directory structure
work directory: ./applications/BearPi/BearPi-HM_Nano/sample/{my_app}
required file: file.c, BUILD.gn
example - hello_world follows:
- my_app
- file.c
- BUILD.gn
1
2
3
4
5
6
7
8
9
#include <stio.h>
#include "ohos_init.h" // APP_define head_file
void Hello_Wolrd(void)
{
printf("Hello World! \r\n");
}
APP_FEATURE_INIT(Hello_World); // call the function when init
1
2
3
4
5
6
7
8
static_library("myapp") {
sources = [
"hello_world.c"
]
include_dirs = [
"//utils/native/lite/include"
]
}
- static_library specify the result of compilation and that is libmyapp.a
- sources specify .c file depent by static_library .a. And “//” means absolute path otherwise relative path.
include_dirs specify the path of .h file
- edit the module file BUILD.gn
add the following code
1
2
3
4
5
6
7
import("//build/lite/config/component/lite_component.gni")
lite_component("app") {
features = [
"my_app:myapp"
]
}
- my_app is relative path.
- myapp is target wich refer to static_library{“myapp”} in my_app/BUILD.gn
Ninja introduction
file convert & link : .c -> .a -> .bin
task related conception
manage thread
mechanism of thread
create thread interface
example
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "ohos_init.h"
#include "cmsis_os2.h"
#include "wifiiot_gpio.h"
#include "wifiiot_gpio_ex.h"
void thread1(void)
{
int sum = 0;
while (1)
{
printf("This is Led Thread1----%d\r\n", sum++);
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_2, 1);
usleep(1000000);
GpioSetOutputVal(WIFI_IOT_IO_NAME_GPIO_2,0);
usleep(1000000);
}
}
void thread2(void)
{
int sum = 0;
while (1)
{
printf("This is BearPi Harmony Thread2----%d\r\n", sum++);
usleep(500000); //延时0.5s
}
}
static void Thread_example(void)
{
GpioInit();
IoSetFunc(WIFI_IOT_IO_NAME_GPIO_2,WIFI_IOT_IO_FUNC_GPIO_2_GPIO);
GpioSetDir(WIFI_IOT_IO_NAME_GPIO_2,WIFI_IOT_GPIO_DIR_OUT);
osThreadAttr_t attr;
attr.name = "thread1";
attr.attr_bits = 0U; // decide if osThreadJoin can be used: 0U means off & 1U means on
attr.cb_mem = NULL; // set the pointer to control block
attr.cb_size = 0U;
attr.stack_mem = NULL;// set the pointer to control stack
attr.stack_size = 1024 * 4;
attr.priority = 25;
if (osThreadNew((osThreadFunc_t)thread1, NULL, &attr) == NULL)
{
printf("Falied to create thread1!\n");
}
attr.name = "thread2";
if (osThreadNew((osThreadFunc_t)thread2, NULL, &attr) == NULL)
{
printf("Falied to create thread2!\n");
}
}
APP_FEATURE_INIT(Thread_example);
1
2
3
4
5
6
7
8
9
10
11
12
static_library("mythread") {
sources = [
"thread.c"
]
include_dirs = [
"//utils/native/lite/include", // printf
"//kernel/liteos_m/components/cmsis/2.0", // thread
"//base/iot_hardware/interfaces/kits/wifiiot_lite" // led light
]
}
This post is licensed under CC BY 4.0 by the author.