1.拷贝所有文件,libcpu,bsp文件夹中只需要拷贝对应M4/M3文件
2.rtthread_startup函数芯片外设初始化,systick初始化。芯片库自带的systick中断入口函数去掉,因为rt-thread中用到这个函数
3.rtconfig.h配置,仔细阅读每一条配置含义
4.适配调试打印函数,调试命令接收函数,如下:
1 void rt_hw_console_output(const char *str) 2 { 3 /* empty console output */ 4 #ifdef SYSTEM_DEBUG_EN 5 Uart_SendBuf(USART0,(void*)str,strlen(str)); 6 #endif 7 //SEGGER_RTT_WriteString(0,str); 8 return; 9 } 10 char rt_hw_console_getchar(void) 11 { 12 u8 ch=0; 13 #ifdef SYSTEM_DEBUG_EN 14 ring_getchar(&Usart0_Ring, &ch); 15 #endif 16 return ch; 17 }
5.上面实现了rt_hw_console_getchar()函数就可以使用发送msh命令调试一些东西,前提是rtconfig.h要打开配置,如下:
rt-thread自带的msh命令:help ,version,list_thread,list_sem,list_event,list_mutex,list_mailbox,list_msgqueue,list_timer,发送要以 \r\n 结尾
rt-thread加入自定义msh命令方法,示例如下:
1 long brush(int argc,char* arg[]) 2 { 3 if(argc>3)return 0; 4 SYSTEM_DEBUG("arg[0]=%s,arg[1]=%s,arg[2]=%s\n",arg[0],arg[1],arg[2]); 5 if(strstr(arg[1],"B1")) 6 { 7 brush_B1_duty_set(atof(arg[2])); 8 } 9 if(strstr(arg[1],"F1")) 10 { 11 brush_F1_duty_set(atof(arg[2])); 12 } 13 if(strstr(arg[1],"B2")) 14 { 15 brush_B2_duty_set(atof(arg[2])); 16 } 17 if(strstr(arg[1],"F2")) 18 { 19 brush_F2_duty_set(atof(arg[2])); 20 } 21 return 0; 22 } 23 MSH_CMD_EXPORT(brush, "example: brush F1/F2/B1/B2 0.5, means: F1/F2/B1/B2 -which brush, 0.5-duty[0.0~1.0]");
标签:RT,rt,console,nano,THREAD,list,duty,brush,arg From: https://www.cnblogs.com/ycpkbql/p/16733716.html