文章作者: 盧宜良
Subsystems 裡有許多好用的東西,例如Shell,這是一個已經寫好的UART command系統,像是AT系統,這節來介紹要如何編譯與使用。
1.在 prj.conf 加入CONFIG_CONSOLE_SHELL=y
2.CODE
#include <zephyr.h>
#include <shell/shell.h>
static int shell_cmd_ping(int argc, char *argv[])
{
ARG_UNUSED(argc);
ARG_UNUSED(argv);
printk("pong\n");
return 0;
}
static int shell_cmd_params(int argc, char *argv[])
{
int cnt;
printk("argc = %d\n", argc);
for (cnt = 0; cnt < argc; cnt++) {
printk(" argv[%d] = %s\n", cnt, argv[cnt]);
}
return 0;
}
#define MY_SHELL_MODULE "test"
static struct shell_cmd commands[] = {
{ "ping", shell_cmd_ping, NULL },
{ "params", shell_cmd_params, "print argc" },
{ NULL, NULL, NULL }
};
static void myshell_init(void)
{
SHELL_REGISTER(MY_SHELL_MODULE, commands);
}
void main(void)
{
myshell_init();
while (1) {
k_sleep(2000);
}
}
GoMCU![[原創] NXP i.MX8QXP dev kit notes tutorial 開發紀錄教學-GoMCU](https://imxdev.gitlab.io/images/imx8qxp-top.jpg)