【简介】
RT-Thread Nano 的代码可以在官网该路径获取下载(https://www.rt-thread.org/download.html#download-rt-thread-nano)本地的开发环境为IAR IDE 针对IAR 环境下移植适配Rt-thread nano 的方法可以参照官方的以下文档(https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-nano/nano-port-iar/an0040-nano-port-iar),官方的文档对移植的过程有详细的说明,我们参照该文档完成RT-Thread Nano 的适配。以下是官方资料对RT-Thread Nano 敢要说明。
【 RT-Thread Nano 适配】
1.添加代码
RT-Thread Nano 的适配我们首先把下载的 RT-Thread Nano kernel 代码加入工程参与编译,在IAR 下添加以下kernel 代码编译。
将CPU libcpu 体系架构相关的代码加入IAR环境,本地使用的CORTEX M0相关的文件
2.配置SysTick
配置SysTick 为RT-Thread Nano 的任务调度定时器,定时器周期配置为1ms
添加systick 中断处理函数
#include <rtthread.h> /******************************************************************************************************** * Private Function Declarations * *******************************************************************************************************/ void SysTick_Handler(void) { /* enter interrupt */ rt_interrupt_enter(); rt_tick_increase(); /* leave interrupt */ rt_interrupt_leave(); }
3. 配置FinSH
finsh 的添加可以查看官方的该文档 https://www.rt-thread.org/document/site/#/rt-thread-version/rt-thread-nano/finsh-port/an0045-finsh-port
将代码加工程并配置finish编译配置
/* FinSH config file */ #ifndef __MSH_CFG_H__ #define __MSH_CFG_H__ // <<< Use Configuration Wizard in Context Menu >>> #define RT_USING_FINSH #define FINSH_USING_MSH #define FINSH_USING_MSH_ONLY // <h>FinSH Configuration // <o>the priority of finsh thread <1-30> // <i>the priority of finsh thread // <i>Default: 21 #define FINSH_THREAD_PRIORITY 21 // <o>the stack of finsh thread <1-4096> // <i>the stack of finsh thread // <i>Default: 4096 (4096Byte) #define FINSH_THREAD_STACK_SIZE 512 #define FINSH_USING_SYMTAB // <c1>Enable command description // <i>Enable command description #define FINSH_USING_DESCRIPTION // </c> // </h> // <<< end of configuration section >>> #endif
使用finish 需要实现console 的读写接口,本地使用的uart 作为物理层的输入/输出 对应函数如下
void rt_hw_console_output(const char *str) { size_t idx; int len = strlen(str); for (idx = 0; idx < len; idx++) { if(*str == '\n') DL_UART_Extend_transmitDataBlocking(UART_0_INST,'\r'); DL_UART_Extend_transmitDataBlocking(UART_0_INST,*str); str++; } } char rt_hw_console_getchar(void) { uint16_t ret = 0; uint8_t pdata; ret = RingBuffer_Read(&ringbuff,&pdata,1); return ret == 0 ? -1 : pdata; } void UART0_IRQHandler(void) { uint8_t data; if (DL_UART_Main_getPendingInterrupt(UART_0_INST) == DL_UART_IIDX_RX) { data = DL_UART_receiveDataBlocking(UART_0_INST); /* Get date and write to ringbuffer */ RingBuffer_Write(&ringbuff,&data,1); } }
至此已经完成了适配的工作,启动后finsh 可以输入输出了,启动会输出rt-thread 的log
查看任务信息