# himcu **Repository Path**: hilink_blue/himcu ## Basic Information - **Project Name**: himcu - **Description**: No description available - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: trunk - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2025-06-07 - **Last Updated**: 2025-10-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # HIMCU ## 介绍 ``` +-----------+ +-----------+ | Module | | MCU | | TX ----->+--------------------------------->+ RX | | RX <-----+<---------------------------------+ TX | +-----------+ +-----------+ ``` HIMCU是鸿蒙智联标准串口协议的代码实现,集成在MCU侧以后,可以与使用了标准固件的通信模组进行交互,提供了控制、OTA、产测等功能,支持无OS平台,资源占用:代码空间35k、静态RAM<1K、HEAP最小需3K ## 目录 ``` himcu ├── demo # 示例文件 ├── interfaces # himcu对外接口 └── source # himcu源文件 ``` ## DEMO快速上手 ### 集成himcu与DEMO到工程编译框架 1. himcu源码包含以下文件 ``` himcu/source/adapter/himcu_init_param.c himcu/source/adapter/himcu_prod.c himcu/source/adapter/himcu_sal.c himcu/source/adapter/himcu_tx_rx.c himcu/source/adapter/himcu_ota.c himcu/source/base/himcu_log.c himcu/source/biz/control/himcu_base_info_conf.c himcu/source/biz/control/himcu_control.c himcu/source/biz/control/himcu_heartbeat.c himcu/source/biz/control/himcu_module_event.c himcu/source/biz/control/himcu_profile_control.c himcu/source/biz/control/himcu_profile_query.c himcu/source/biz/control/himcu_profile_report.c himcu/source/biz/control/himcu_profile_utils.c himcu/source/biz/control/himcu_module_restart.c himcu/source/biz/control/himcu_restore_factory.c himcu/source/biz/control/himcu_info_query.c himcu/source/biz/control/himcu_diagnosis_info.c himcu/source/biz/fsm/himcu_biz_fsm.c himcu/source/biz/ota/himcu_biz_ota.c himcu/source/biz/factory/himcu_biz_factory.c himcu/source/framework/event_loop/event_loop.c himcu/source/framework/event_loop/event_source_msg_queue.c himcu/source/framework/event_loop/event_source_timer.c himcu/source/framework/event_loop/event_source.c himcu/source/framework/schedule/sched_event_loop.c himcu/source/framework/schedule/sched_executor.c himcu/source/framework/schedule/sched_msg_queue.c himcu/source/framework/schedule/sched_timer.c himcu/source/framework/event_bus/event_bus.c himcu/source/transport/himcu_trans_endpoint.c himcu/source/transport/himcu_trans_recv.c himcu/source/transport/himcu_trans_send.c himcu/source/transport/himcu_trans_io.c himcu/source/transport/himcu_trans_utils.c himcu/source/transport/himcu_trans.c himcu/source/utils/himcu_fsm.c himcu/source/utils/himcu_ring_buffer.c himcu/source/utils/himcu_utils.c himcu/source/utils/himcu_msg_queue.c himcu/source/utils/himcu_mutex_ex.c himcu/source/utils/himcu_queue.c himcu/source/himcu_main.c ``` 2. HIMCU头文件包含以下目录 ``` himcu/interfaces himcu/source/adapter/include himcu/source/base/include himcu/source/biz/control/include himcu/source/biz/ota/include himcu/source/biz/fsm/include himcu/source/biz/factory/include himcu/source/framework/event_loop/include himcu/source/framework/schedule/include himcu/source/framework/event_bus/include himcu/source/transport/include himcu/source/utils/include ``` 3. DEMO包含以下文件 ``` himcu/demo/product/light/demo_prod_light.c himcu/demo/comm/demo_comm.c himcu/demo/arch/noos/demo_arch_noos.c # 无OS系统适用,可用于快速集成,对于支持cmsis2接口的平台请使demo/arch/cmsis2/demo_arch_cmsis2.c,对于其他OS平台可以参考cmsis2进行实现 ``` 4. DEMO包含以下头文件 ``` himcu/demo/product/light himcu/demo/arch/include himcu/demo/comm/include ``` ### 集成安全函数组件 himcu依赖安全函数,`开发者可以在开源项目OpenHarmony中获取对应开源软件bounds_checking_function`,参考[链接](https://gitcode.com/openharmony/third_party_bounds_checking_function) 1. 安全函数源码集成 ``` third_party_bounds_checking_function/src/memcpy_s.c third_party_bounds_checking_function/src/memmove_s.c third_party_bounds_checking_function/src/memset_s.c third_party_bounds_checking_function/src/securecutil.c third_party_bounds_checking_function/src/secureprintoutput_a.c third_party_bounds_checking_function/src/snprintf_s.c third_party_bounds_checking_function/src/sprintf_s.c third_party_bounds_checking_function/src/strcat_s.c third_party_bounds_checking_function/src/strcpy_s.c third_party_bounds_checking_function/src/strncat_s.c third_party_bounds_checking_function/src/strncpy_s.c third_party_bounds_checking_function/src/vsnprintf_s.c third_party_bounds_checking_function/src/vsprintf_s.c ``` 2. 安全函数头文件路径 ``` third_party_bounds_checking_function/include ``` ### 实现串口收发函数 在`himcu/demo/product/light/demo_prod_light.c`中实现TX RX相关函数逻辑 这里给出hi3861芯片平台实现参考: ``` static int32_t DEMO_TxSend(const uint8_t *data, uint32_t len) { if (data == NULL || len == 0) { DEMO_LOG("invalid param"); return -1; } return hi_uart_write(HI_UART_IDX_2, data, len); } static int32_t DEMO_RxRecv(uint8_t *buf, uint32_t len, uint32_t timeoutMs) { if (buf == NULL || len == 0) { DEMO_LOG("invalid param"); return -1; } return hi_uart_read_timeout(HI_UART_IDX_2, buf, len, timeoutMs); } static int32_t DEMO_TxRxInit(void) { hi_io_set_func(HI_IO_NAME_GPIO_11, HI_IO_FUNC_GPIO_11_UART2_TXD); /* uart2 tx */ hi_io_set_func(HI_IO_NAME_GPIO_12, HI_IO_FUNC_GPIO_12_UART2_RXD); /* uart2 rx */ static hi_uart_attribute uartCfg = {115200, 8, 1, 0, 0}; hi_u32 err = hi_uart_init(HI_UART_IDX_2, &uartCfg, HI_NULL); if (err != HI_ERR_SUCCESS) { DEMO_LOG("uart init fail %u", err); return -1; } return 0; } static void DEMO_TxRxDeinit(void) { return; } ``` ### 无OS相关配置 在`himcu/demo/arch/noos/demo_arch_noos.c`中实现`DEMO_GetOsTime`接口,返回系统运行的毫秒时间戳 在`himcu/demo/product/light/demo_prod_light.c`中使能`DEMO_NOOS`宏 ### 调用DEMO入口 针对无OS平台:参考`himcu/demo/product/light/demo_prod_light.c`中的`DEMO_Main`,将`HIMCU_Loop`加入到轮询调用中 针对有OS的平台:起一个线程拉起`DEMO_Main`函数 ### 上板测试 正常启动后会通过`DEMO_Vprintf`函数输出以下日志 ``` HIMCU:N:himcu_log.c:86 set log level to 7 HIMCU:I:himcu_main.c:102 init ok, comp=log index=1 HIMCU:N:sched_event_loop.c:51 no task mode HIMCU:I:himcu_main.c:102 init ok, comp=event_loop index=2 HIMCU:I:himcu_main.c:102 init ok, comp=executor index=3 HIMCU:I:himcu_queue.c:53 queue create success count=0,capacity=32 HIMCU:D:himcu_msg_queue.c:164 create msg queue success HIMCU:I:himcu_main.c:102 init ok, comp=msg_queue index=4 HIMCU:I:himcu_main.c:102 init ok, comp=timer index=5 HIMCU:I:himcu_main.c:102 init ok, comp=event_bus index=6 HIMCU:I:himcu_trans_io.c:98 trans tx rx init ok no rx task buffer HIMCU:I:himcu_main.c:102 init ok, comp=trans index=7 HIMCU:I:himcu_main.c:102 init ok, comp=biz_control index=8 HIMCU:I:himcu_main.c:102 init ok, comp=biz_fsm index=9 HIMCU:I:himcu_main.c:102 init ok, comp=biz_ota index=10 HIMCU:I:himcu_main.c:102 init ok, comp=biz_factory index=11 HIMCU:N:himcu_main.c:136 himcu start ok HIMCU:N:himcu_base_info_conf.c:39 build mcu version 1.0.0.0 ``` ### 串口连接 将MCU的串口与烧录了标准固件的推荐模组串口连接 ### 智慧生活添加 使用智慧生活(Beta版沙箱环境)搜索,即可看到*NearLink演示灯*的设备