目录
引言
在前面的博文星闪WS63E开发板的OpenHarmony环境构建-CSDN博客中介绍了如何构建W63E开发板的OpenHarmony环境,今天来尝试运行第一个程序。考虑到有很多朋友以前使用过hi3861系统,所以我主要说明两者在OpenHarmony下的区别。如果以前从来没有使用OpenHarmony开发过轻量级开发板,建议先从hi3861学起。
demolink示例
星闪OpenHarmony SDK里面带的例子其实都是hi3861的,毕竟hi3861是主线支持的芯片。这些例子在星闪派上运行要稍加修改才行。我测试的例子是applications/sample/wifi-iot/app/demolink。demolink这个例子的作用是打印hello world,不依赖I/O,所以最为简单。其基本流程如下图显示。
程序修改
要运行示例程序需要以下5个步骤,其中第2和第3步与hi3861一致,后两个是星闪SDK独有的。
修改任务堆栈的大小
修改applications/sample/wifi-iot/app/demolink/demosdk.c中的任务堆栈大小,由1000改为4000。1000这个大小在WS63上会导致无法创建任务。
//#define TASK_STACK_SIZE 1000
#define TASK_STACK_SIZE 4096
修改示例程序的build.gn
修改applications/sample/wifi-iot/app/demolink/BUILD.gn,将其static_library的名字和目录名一致,这步不是必须,但是修改后对后序处理有利。
static_library("demolink") {
sources = [
"demosdk.c",
"demosdk_adapter.c",
"helloworld.c",
]
include_dirs = [ "//commonlibrary/utils_lite/include" ]
}
修改App的build.gn
修改applications/sample/wifi-iot/app/BUILD.gn,其默认的startup实际上什么也不做,此处加上demolink例子。
import("//build/lite/config/component/lite_component.gni")
lite_component("app") {
features = [ "demolink:demolink" ]
}
修改ohos.cmake
修改device/soc/hisilicon/ws63v100/sdk/libs_url/ws63/cmake/ohos.cmake文件(老版本的SDK为device\soc\hisilicon\ws63v100\sdkv100\libs_url\ws63\cmake\ohos.cmake),添加 `"demolink"`,如下:
elseif(${TARGET_COMMAND} MATCHES "ws63-liteos-app")
set(COMPONENT_LIST
"begetutil" "hilog_lite_static" "samgr_adapter" "bootstrap" "fsmanager_static" "hal_update_static" "hilog_static" "inithook" "samgr_source"
"broadcast" "hal_file_static" "init_log" "native_file" "udidcomm"
"cjson_static" "hal_sys_param" "hichainsdk" "hota" "init_utils" "param_client_lite"
"hiview_lite_static" "hal_sysparam" "hievent_lite_static" "huks_3.0_sdk" "samgr" "blackbox_lite" "hal_iothardware" "wifiservice"
"hidumper_mini" "ble_lite" "sle_lite" "demolink")
endif()
修改config.py
修改device/soc/hisilicon/ws63v100/sdk/build/config/target_config/ws63/config.py(老版本为device\soc\hisilicon\ws63v100\sdkv100\libs_url\ws63\cmake\ohos.cmake),加入"demolink":
'ws63-liteos-app': {
'base_target_name': 'target_ws63_app_rom_template',
'os': 'liteos',
'defines': [
......
],
'ram_component': [
.......
'xo_trim_port',
"mqtt",
'printf_adapt',
"demolink"
],
'ccflags': [
"-DBOARD_ASIC", '-DPRE_ASIC',
],
'application': 'application',
'bin_name': 'ws63-liteos-app',
'smaller': True,
'hso_enable_bt': True,
'hso_enable': True,
'codesize_statistic': True,
'nv_update':True,
'generate_efuse_bin': True,
'copy_files_to_interim': True
此处除了demolink, 还加上了printf_adapt。后者是确保printf会被转向到串口输出。海思的SDK默认是ws63-liteos-xts有printf_adapt,而ws63-liteos-app没有,这导致我最开始的程序啥也不输出,走了弯路。
编译程序
修改过这4个地方之后,就可以使用hb build -f命令进行编译了。如果想先clean再build,可以使用hb clean --clean-all或者hb clean --clean-out-product。如果以前用过hi3861开发的都应该有经验,如果不clean就build,可能会吧以前编译过的模块加进来,导致程序不正常。
烧写程序
可以使用官方的burntool软件(tools · HiHopeORG/NearLink - 码云 - 开源中国)在Windows下烧写程序。
烧写前需要选择菜单"Option|Change chip"将芯片类型改为WS63。
剩下的设置参见下图:
点击Connect按钮后,再按下板子上的reset键就可以下载程序了。
如果希望在Linux下进行烧写,可以使用网友开发的软件:GitHub - geekheart/xf_burn_tools: ws63 automatic burning softwarehttps://github.com/geekheart/xf_burn_tools
程序运行
再次按下reset重启开发板,就可以运行程序了,下面是串口打印输出,可以从中看到我们想要的那两句打印信息。
boot.
Flash Init Fail! ret = 0x80001341
verify_public_rootkey secure verify disable!
verify_params_key_area secure verify disable!
verify_params_area_info secure verify disable!
verify_image_key_area secure verify disable!
verify_image_code_info secure verify disable!
SSB Uart Init Succ!
SSB Flash Init Succ!
verify_image_key_area secure verify disable!
verify_image_code_info secure verify disable!
Flashboot Uart Init Succ!
Flashboot Malloc Init Succ!
Flash Init Succ!
No need to fix SR!
flashboot version : 1.10.101
[UPG] upgrade init OK!
No need to upgrade...
flash_encrypt disable.
verify_image_key_area secure verify disable!
verify_image_code_info secure verify disable!
APP|Debug uart init succ.
[UPG] upgrade init OK!
APP|init_dev_addr, mac_addr:0xab,0x 0,0x73,0xbc,0x**,0x**,
xo_trim_temp_comp val:0 0
[osal_irq_request:57]:LOS_HwiCreate failed! irq[53] ret = 0x2000904.
APP|AT uart init succ.
los_at_plt_cmd_register EXCUTE
[osal_msg_queue_create:25]:qName:dfx_msg qID=0x0
APP|=========FS MOUNT=========
LFS [E]:fs init failed, ret = 0xffffffff
LFS [E]:lfs_format failed, ret = -28
LFS [E]:lfs_mount failed, ret = -84
APP|=========FS READY=========
APP|WARNING: main_initialise::thread[11] func is null
hilog will init.
hievent will init.
hievent init success.
LFS [E]:lfs_file_open failed, ret = -2147483647, name = tmp_persist_parameters
LFS [E]:lfs_file_open failed, ret = -2147483647, name = persist_parameters
LFS [E]:lfs_file_open failed, ret = -2147483647, name = persist_parameters
Please implement the interface according to the platform!
it is demosdk entry.
cpu 0 entering scheduler
[osal_msg_queue_create:25]:qName:BthChannel qID=0x4
[osal_msg_queue_create:25]:qName:BtcChannel qID=0x5
[osal_msg_queue_create:25]:qName:BthChannel qID=0x6
[osal_msg_queue_create:25]:qName:BtcChannel qID=0x7
[osal_irq_request:57]:LOS_HwiCreate failed! irq[46] ret = 0x2000904.
APP|btc open
hiview init success.
it is demo biz: hello world.
[RADAR_LOG] alg ctrl read from nv [1][2][0][0][1][1][20]
[osal_kthread_set_priority:59]:parameter invalid!
[osal_kthread_set_priority:59]:parameter invalid!
device_main_init: 0!
===hal_initialize_phy===225===
device_module_init:: succ!
cali_set_cali_mask:old[0x0] -> new[0x1fa2]
fe_rf_initialize
cali_offline_cali_entry enter
cali_set_cali_done_flag:old[0x0] -> new[0x1]
rf cali OK. time cost:23, ret:0
结语
虽然为WS63开发板所使用的hi3863芯片和hi3861非常相似,但是两者的OpenHarmony SDK还是有很多不同,结果一番折腾,也算是让程序运行起来了。后面有时间的话,就给大家多演示几个例子。