主要包含4个源文件,FreeRTOS_CLK.c、Sample-CLI-command.c、uart_console.c、console_user.c,FreeRTOS_CLK.c、Sample-CLI-command.c不用修改修改直接包含进工程,Sample-CLI-command.c为使用命令行的打印任务状态及向命令操作传感2个或3个参数的示例。
uart_console.c为命令行接口的串口接口函数,需要修改为
static BaseType_t console_user_format_execute( char *pcWriteBuffer, size_t xWriteBufferLen, const char *pcCommandString ){
( void ) pcCommandString;
( void ) xWriteBufferLen;
configASSERT( pcWriteBuffer );
if( login_flag==0 ){
strcpy(pcWriteBuffer,"请先登录\r\n");
return pdFALSE;
}
extern const struct lfs_config lfs_cfg;
FILE_HANDLER fp;
int err;
lfs_unmount( &myfs.fs );
lfs_format( &myfs.fs, &lfs_cfg );
err = lfs_mount( &myfs.fs, &lfs_cfg );
FOPEN( &fp, "lfsformated", "w" );
FCLOSE(&fp);
strcpy(pcWriteBuffer,"格式化成功,请重启建立文件\r\n");
return pdFALSE;
}
static const CLI_Command_Definition_t console_user_format ={
"format",
"\r\nformat: format ---- 格式化SPI Flash",
console_user_format_execute,
0
};
CLI_Command_Definition_t 为命令定义格式,第一个参数是命令名称,第二个参数为使用方法打印提示,第三个参数的执行函数,第四个参数为命令带有多少个命令行参数,最多为2个,在执行函数中pcCommandString 参数指针带入。
最后在console_user_init函数中添加
FreeRTOS_CLIRegisterCommand( &console_user_format );
调用
uart_console_start(CONSOLE_STACK_SIZE,CONSOLE_TASK_PRIORITY);
完成命令行控制台的线程建立,即可在串口终端中使用定义的命令,命令行可以很方便打印自己需要的运行状态,很适合离线调试的场合或者交给调试安装的同事使用
移植代码下载连接:https://download.csdn.net/download/dmjkun/10902204