【IoT最佳实践】基于小熊派开发板的物联网实战开发(三)-移植Huawei LiteOS操作系统(智慧农业)
上一期:基于小熊派开发板的物联网实战开发(二)-调测NB-IoT模组
请完成前两期的实验再来操作本期实验。
本实验基于STML431_BearPi裸机工程,移植Huawei LiteOS操作系统,在LiteOS操作系统基础上,移植智慧农业传感器代码,与NB-IoT模组通信,实现数据上报,并通过平台下发控制指令,开发板接收命令并对命令进行应答。
本期博客介绍移植Huawei LiteOS操作系统部分。
移植Huawei LiteOS操作系统、
打开LiteOS Studio,点击“工程配置”按钮;
选择“编译输出”,点击输出目录右侧“...”按钮;
选择“HCIP\BearPi_LiteOS\targets\STM32L431_BearPi\GCC”文件夹,点击“确认”;
双击打开Makefile文件;
在Makefile中添加移植启动汇编的代码;
# ASM ASM_SOURCES_s = \ ${wildcard $(PROJECTBASE)/los_startup_gcc.s} ASM_SOURCES_S = \ ${wildcard $(TOP_DIR)/arch/arm/arm-m/cortex-m4/gcc/los_dispatch_gcc.S} |
删除Makefile中”C_SOURCES = \ ”到“Src/spi.c”之间的原始hal库代码;
删除“ASM_SOURCES = \“,”startup_stm32l431xx.s”两行启动文件代码;
在Makefile中添加移植stm32 HAL库的代码;
HAL_DRIVER_SRC = \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim_ex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr_ex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_pwr.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_gpio.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rcc_ex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_flash_ramfunc.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_cortex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_uart.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_tim.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_spi.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_spi_ex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_adc_ex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_i2c_ex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_qspi.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_iwdg.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_dma_ex.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Src/stm32l4xx_hal_rng.c C_SOURCES += $(HAL_DRIVER_SRC) |
在Makefile中添加移植USER的代码:
USER_SRC = \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/main.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/system_stm32l4xx.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/usart.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/dwt.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/sys_init.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/i2c.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/spi.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/gpio.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/user_task.c C_SOURCES += $(USER_SRC) |
在Makefile中添加移植hardware传感器的代码;
HARDWARE_SRC = \ $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_IA1/E53_IA1.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/LCD/lcd.c \ $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/Src/hal_rng.c C_SOURCES += $(HARDWARE_SRC) |
在Makefile中添加移植kernel的代码;
KERNEL_SRC = \ ${wildcard $(TOP_DIR)/kernel/*.c} \ ${wildcard $(TOP_DIR)/kernel/base/core/*.c} \ ${wildcard $(TOP_DIR)/kernel/base/ipc/*.c} \ ${wildcard $(TOP_DIR)/kernel/base/mem/bestfit_little/*.c} \ ${wildcard $(TOP_DIR)/kernel/base/mem/membox/*.c} \ ${wildcard $(TOP_DIR)/kernel/base/mem/common/*.c} \ ${wildcard $(TOP_DIR)/kernel/base/misc/*.c} \ ${wildcard $(TOP_DIR)/kernel/base/om/*.c} \ ${wildcard $(TOP_DIR)/kernel/extended/tickless/*.c} C_SOURCES += $(KERNEL_SRC) |
在Makefile中添加移植cmsis的代码;
CMSIS_SRC = \ ${wildcard $(TOP_DIR)/osdepends/liteos/cmsis/*.c} C_SOURCES += $(CMSIS_SRC) |
在Makefile中添加移植ARCH的代码;
ARCH_SRC = \ ${wildcard $(TOP_DIR)/arch/arm/arm-m/src/*.c} \ ${wildcard $(TOP_DIR)/arch/arm/arm-m/cortex-m4/*.c} C_SOURCES += $(ARCH_SRC) |
在Makefile中添加移植CoAP、LWM2M、AgentTiny协议的代码;
ifeq ($(WITH_LWM2M), yes) ER_COAP_SRC = \ ${wildcard $(TOP_DIR)/components/connectivity/lwm2m/core/er-coap-13/er-coap-13.c} C_SOURCES += $(ER_COAP_SRC)
LWM2M_SRC = \ ${wildcard $(TOP_DIR)/components/connectivity/lwm2m/core/*.c} \ ${wildcard $(TOP_DIR)/components/connectivity/lwm2m/examples/shared/*.c} C_SOURCES += $(LWM2M_SRC) ATINY_TINY_SRC = \ ${wildcard $(TOP_DIR)/components/connectivity/agent_tiny/atiny_lwm2m/*.c} ATINY_TINY_SRC_NO_FOTA = \ $(filter-out $(TOP_DIR)/components/connectivity/agent_tiny/atiny_lwm2m/atiny_fota_manager.c \ $(TOP_DIR)/components/connectivity/agent_tiny/atiny_lwm2m/atiny_fota_state.c \ $(TOP_DIR)/components/connectivity/agent_tiny/atiny_lwm2m/firmware_update.c, $(ATINY_TINY_SRC)) C_SOURCES += $(ATINY_TINY_SRC_NO_FOTA)
AGENT_DEMO_SRC = \ ${wildcard $(TOP_DIR)/demos/agenttiny_lwm2m/*.c} C_SOURCES += $(AGENT_DEMO_SRC)
endif |
在Makefile中添加移植osdepends、components的代码;
OS_DEPENDS_SRC = \ ${wildcard $(TOP_DIR)/osdepends/liteos/*.c} C_SOURCES += $(OS_DEPENDS_SRC)
SOCKET_ADAPTER_SRC = \ ${wildcard $(TOP_DIR)/components/net/sal/*.c} C_SOURCES += $(SOCKET_ADAPTER_SRC)
NEWLIB_SRC = \ ${wildcard $(TOP_DIR)/components/lib/libc/malloc.c}\ C_SOURCES += $(NEWLIB_SRC)
ATINY_LOG = \ ${wildcard $(TOP_DIR)/components/log/*.c} C_SOURCES += $(ATINY_LOG) |
在Makefile中添加移植AT框架的代码;
ifeq ($(WITH_AT_FRAMEWORK), yes) AT_FRAME_SRC = \ ${wildcard $(TOP_DIR)/components/net/at_frame/*.c} \ $(TOP_DIR)/targets/STM32L431_BearPi/Src/at_hal.c C_SOURCES += $(AT_FRAME_SRC)
ifeq ($(NETWORK_TYPE), ESP8266) USER_DRIVERS_SRC = ${wildcard $(TOP_DIR)/components/net/at_device/wifi_esp8266/*.c} else ifeq ($(NETWORK_TYPE), M26) USER_DRIVERS_SRC = ${wildcard $(TOP_DIR)/components/net/at_device/gprs_M26/*.c} else ifneq ($(findstring $(NETWORK_TYPE)$(NETWORK_TYPE), NB_NEUL95 NB_NEUL95_NO_ATINY),) USER_DRIVERS_SRC = \ ${wildcard $(TOP_DIR)/components/net/at_device/nb_bc95/*.c} \ ${wildcard $(TOP_DIR)/components/connectivity/nb_iot/*.c} endif
#As default,below compile all device file for AT_FRAMEWORK ifeq ($(AT_COMPILE_ALL), ALL) USER_DRIVERS_SRC = ${wildcard $(TOP_DIR)/components/net/at_device/wifi_esp8266/*.c} USER_DRIVERS_SRC += ${wildcard $(TOP_DIR)/components/net/at_device/gprs_M26/*.c} USER_DRIVERS_SRC += \ ${wildcard $(TOP_DIR)/components/net/at_device/nb_bc95/*.c} \ ${wildcard $(TOP_DIR)/components/connectivity/nb_iot/*.c} endif C_SOURCES += $(USER_DRIVERS_SRC) endif
ifeq ($(NETWORK_TYPE), NB_NEUL95_NO_ATINY) NB_NEUL95_ONYL_DEMO = \ $(TOP_DIR)/demos/nbiot_without_atiny/nb_demo.c \ $(TOP_DIR)/demos/nbiot_without_atiny/nb_cmd_ioctl.c C_SOURCES += $(NB_NEUL95_ONYL_DEMO) endif |
删除Makefile中“C_INCLUDES = \ ”到“-IDrivers/CMSIS/Include”之间的代码;
在Makefile中添加移植所有头文件的代码;
HAL_DRIVER_INC = \ -I $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Inc \ -I $(TOP_DIR)/targets/STM32L431_BearPi/Drivers/STM32L4xx_HAL_Driver/Inc/Legacy C_INCLUDES += $(HAL_DRIVER_INC)
INCLUDE_INC = \ -I $(TOP_DIR)/include C_INCLUDES += $(INCLUDE_INC)
LWM2M_ATINY_INC = \ -I $(TOP_DIR)/components/connectivity/agent_tiny/atiny_lwm2m C_INCLUDES += $(LWM2M_ATINY_INC)
HARDWARE_INC = \ -I $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/E53_IA1 \ -I $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/LCD \ -I $(TOP_DIR)/targets/STM32L431_BearPi/Hardware/Inc C_INCLUDES += $(HARDWARE_INC)
USER_INC = \ -I $(TOP_DIR)/targets/STM32L431_BearPi/Inc C_INCLUDES += $(USER_INC)
CMSIS_INC = \ -I $(TOP_DIR)/arch/arm/arm-m/include \ -I $(TOP_DIR)/arch/arm/common/cmsis C_INCLUDES += $(CMSIS_INC)
LITEOS_CMSIS = \ -I $(TOP_DIR)/osdepends/liteos/cmsis C_INCLUDES += $(LITEOS_CMSIS)
OS_CONFIG_INC = \ -I $(TOP_DIR)/targets/STM32L431_BearPi/OS_CONFIG C_INCLUDES += $(OS_CONFIG_INC)
KERNEL_INC = \ -I $(TOP_DIR)/kernel/include \ -I $(TOP_DIR)/kernel/base/include \ -I $(TOP_DIR)/kernel/extended/include C_INCLUDES += $(KERNEL_INC)
ARCH_INC = \ -I $(TOP_DIR)/arch/arm/arm-m/include \ -I $(TOP_DIR)/arch/arm/arm-m/cortex-m4 C_INCLUDES += $(ARCH_INC)
ifneq ($(OTA_IS_NEED_DTLS)_$(WITH_DTLS), no_no) MBEDTLS_INC = \ -I $(TOP_DIR)/components/security/mbedtls/mbedtls-2.6.0/include C_INCLUDES += $(MBEDTLS_INC)
MBEDTLS_PORT_INC = \ -I $(TOP_DIR)/components/security/mbedtls/mbedtls_port C_INCLUDES += $(MBEDTLS_PORT_INC) endif
ifeq ($(WITH_LWM2M), yes) ER_COAP_INC = \ -I $(TOP_DIR)/components/connectivity/lwm2m/core/er-coap-13 C_INCLUDES += $(ER_COAP_INC) LWM2M_INC = \ -I $(TOP_DIR)/components/connectivity/lwm2m/core \ -I $(TOP_DIR)/components/connectivity/lwm2m/examples/shared C_INCLUDES += $(LWM2M_INC) endif
DEMO_INC = \ -I $(TOP_DIR)/demos C_INCLUDES += $(DEMO_INC) |
点击“保存”;
双击打开“main.c”文件;
在“main.c”文件中加入硬件初始化函数代码;
VOID HardWare_Init(VOID) { HAL_Init(); /* Configure the system clock */ SystemClock_Config(); MX_GPIO_Init(); MX_USART1_UART_Init(); dwt_delay_init(SystemCoreClock); LCD_Init(); LCD_Clear(WHITE); POINT_COLOR = RED; LCD_ShowString(10, 50, 240, 24, 24, "Welcome to Huawei!"); LCD_ShowString(20, 90, 240, 16, 16, "BearPi IoT Develop Board"); LCD_ShowString(20, 130, 240, 16, 16, "Powerd by Huawei LiteOS!"); LCD_ShowString(10, 170, 240, 16, 16, "Please wait for system init"); } |
在“int main(void)”函数中添加调用硬件初始化函数;
HardWare_Init(); |
点击“保存”,点击“编译”按钮,等待控制台显示“编译成功”
将小熊派开发板用USB线与电脑连接,点击“烧录”,等待提示“烧录成功”;
在小熊派开发板的LCD屏幕上可以看到,有“Welcome to Huawei!”等字样显示。
下一期:基于小熊派开发板的物联网实战开发(四)-开发智慧农业传感器数据收集功能
最后,让我们宣传一下:
3月27-28日,华为物联网平台在华为开发者大会静候您的光临。
华为开发者大会2020(Cloud)是华为面向ICT(信息与通信)领域全球开发者的年度顶级旗舰活动。大会旨在搭建一个全球性的交流和实践平台,开放华为30年积累的ICT技术和能力,以“鲲鹏+昇腾”硬核双引擎,为开发者提供澎湃动力,改变世界,变不可能为可能。
我们期待与你共创计算新时代
在一起,梦飞扬!
- 点赞
- 收藏
- 关注作者
评论(0)