You are not allowed to add pages
Direct Link
Direct Link
Porting LiteOS to NRF52832, using Keil to build.
本文使用LiteOS的版本为 V200R001C50B037_20181226,获取方式如下:
git clone https://gitee.com/LiteOS/LiteOS.git git checkout tag_LiteOS_V200R001C50B037_20181226
使用SDK中的例子工程,nRF5_SDK_17.0.2_d674dde\examples\peripheral\blinky :
工程经过拷贝后,路径发生已改变,需要重新设置:
裸机工程准备完毕。
使用 RTT 作为打印输出端口 :
#include "SEGGER_RTT.h" ... ... SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal For LiteOS Builder\r\n\r\n");
模块 | 根路径 | 目录 | 文件 | 说明 |
---|---|---|---|---|
arch | arch\arm\arm-m | cortex-m4\keil | los_dispatch_keil.S | |
include | los_exc.h los_hw.h los_hw_tick.h los_hwi.h | |||
src | los_hw.c | |||
los_hw_tick.c | ||||
los_hwi.c | ||||
kernel | kernel | los_init.c | ||
kernel | base\core | * | ||
base\ipc | * | |||
base\mem\bestfit_little | * | |||
base\mem\membox | * | |||
base\misc | * | |||
base\om | * | |||
extended\tickless | * | |||
config | targets\Cloud_STM32F429IGTx_FIRE\OS_CONFIG | target_config.h | 1. 复制所有文件用以建立新的硬件版本(例如targets\NRF52) 2. 修改target_config.h中芯片定义文件引用:#include “stm32f4xx.h” –> #include “nrf52.h” 3. 不接管中断,修改target_config.h, #define LOSCFG_PLATFORM_HWI NO |
|
los_printf.h | ||||
los_builddef.h |
文件 | 修改内容 | 说明 |
---|---|---|
target_config.h | #define LOSCFG_PLATFORM_HWI YES | 改为 #define LOSCFG_PLATFORM_HWI NO, LiteOS不接管中断 |
#include “stm32f4xx.h” | 改为#include “nrf52.h”,使用NRF的器件定义 | |
los_printf.h | 添加 #include “SEGGER_RTT.h” #define printf(fmt,args…) SEGGER_RTT_printf(0,fmt, ##args) | 通过RTT实现LiteOS打印输出 |
修改 main.c,测试建立任务和调度任务。
#include <stdbool.h> #include <stdint.h> #include "nrf_delay.h" #include "SEGGER_RTT.h" #include "boards.h" #include "los_sys.h" #include "los_task.h" #define __HEAP_SIZE__ (16384) uint8_t _heap[__HEAP_SIZE__]; uint32_t __LOS_HEAP_ADDR_START__; uint32_t __LOS_HEAP_ADDR_END__; void* led_task(UINT32 arg) { for(;;) { if( arg < 4 ) bsp_board_led_invert(arg); LOS_TaskDelay(1000); } } UINT32 led1_task_handle; UINT32 led2_task_handle; int main(void) { TSK_INIT_PARAM_S task_param; TSK_INIT_PARAM_S task_param2; __LOS_HEAP_ADDR_START__ = (UINT32)_heap; __LOS_HEAP_ADDR_END__ = __LOS_HEAP_ADDR_START__ + __HEAP_SIZE__ -1; SEGGER_RTT_WriteString(0, "SEGGER Real-Time-Terminal For LiteOS Builder\r\n\r\n"); /* Configure board. */ bsp_board_init(BSP_INIT_LEDS); uint32_t retcd; retcd = LOS_KernelInit(); if( retcd == LOS_OK ) { PRINT_EMG("Initialize LiteOS Kernel successful!\r\n"); } else { PRINT_ERR("Initialize LiteOS Kernel failed!\r\n"); } task_param.pcName = "led1_task"; task_param.pfnTaskEntry = led_task; task_param.uwStackSize = 512; task_param.usTaskPrio = 4; task_param.uwArg = 0; retcd = LOS_TaskCreate(&led1_task_handle, &task_param); if( retcd == LOS_OK) { PRINT_EMG("Create led1 task successful!\r\n"); } else { PRINT_ERR("Create led1 task failed!\r\n"); } task_param2.pcName = "led2_task"; task_param2.pfnTaskEntry = led_task; task_param2.uwStackSize = 512; task_param2.usTaskPrio = 4; task_param2.uwArg = 3; retcd = LOS_TaskCreate(&led2_task_handle, &task_param2); if( retcd == LOS_OK) { PRINT_EMG("Create led2 task successful!\r\n"); } else { PRINT_ERR("Create led2 task failed!\r\n"); } LOS_Start(); /* Toggle LEDs. */ while (true) { for (int i = 0; i < LEDS_NUMBER; i++) { bsp_board_led_invert(i); nrf_delay_ms(500); } } }