1
Introduction to nr_micro_shell
Original Project | Increase of Adding nr_micro_shell | Increase of Adding finsh | |
---|---|---|---|
ROM | 63660 | +3832 | +26908 |
RAM | 4696 | +1104 | +1304 |
-
Up to 3 historical commands. -
Supports Tab completion. -
Maximum command line length is 100. -
Up to 10 command parameters. -
Command line thread stack is 512 bytes.
1.1 Directory Structure
Name | Description |
---|---|
docs | Documentation directory, contains demonstration GIF images, etc. |
examples | Example directory, includes command function examples: nr_micro_shell_commands.c and RT_Thread usage examples nr_micro_shell_thread.c |
inc | Header file directory |
src | Source code directory |
1.2 License
<span>LICENSE</span>
file for details.1.3 Dependencies
2
Using nr_micro_shell in RT_Thread ENV Tool
RT-Thread online packages
tools packages --->
[*] nr_micro_shell: Lightweight command line interaction tool. --->
<span>space</span>
key to select, then press the <span>enter</span>
key for related parameter configuration. Then let the RT-Thread package manager update automatically, or use the <span>pkgs --update</span>
command to update the package to the BSP.<span>Using console for kt_printf.</span>
in the RT_Thread configuration is enabled, and that <span>Use components automatically initialization.</span>
option is checked. You can compile and download or simulate to use nr_micro_shell directly. When the command line is blank, pressing Tab will display all supported commands. Test example commands can be seen in the usage example animations under doc/pic. For the process of custom commands, refer to the method in 3. Using nr_micro_shell package in Bare Metal.3
Using nr_micro_shell package in Bare Metal
3.1 Configuration:
3.2 Usage:
-
Ensure that all files are added to the project.
-
Ensure that the macro functions “shell_printf()” and “ansi_show_char()” in nr_micro_shell_config.h can be used normally in the project.
-
Usage example is as follows
#include "nr_micro_shell.h"
int main(void)
{
/* Initialization */
shell_init();
while(1)
{
if(USART GET A CHAR 'c')
{
/* nr_micro_shell receives character */
shell(c);
}
}
}
#include "nr_micro_shell.h"
int main(void)
{
unsigned int i = 0;
// Match the end character configuration NR_SHELL_END_OF_LINE 0
char test_line[] = "test 1 2 3\n"
/* Initialization */
shell_init();
/* Preliminary test code */
for(i = 0; i < sizeof(test_line)-1; i++)
{
shell(test_line[i]);
}
/* Official working code */
while(1)
{
if(USART GET A CHAR 'c')
{
/* nr_micro_shell receives character */
shell(c);
}
}
}
3.3 Adding Your Own Commands
void your_command_function(char argc, char *argv)
{
.....
}
test -a 1
-------------------------------------------------------------
0x03|0x08|0x0b|'t'|'e'|'s'|'t'|'\0'|'-'|'a'|'\0'|'1'|'\0'|
-------------------------------------------------------------
/* "-a" */
printf(argv[argv[1]])
/* "1" */
printf(argv[argv[2]])
const static_cmd_st static_cmd[] =
{
.....
{"your_command_name",your_command_function},
.....
{"\0",NULL}
};
NR_SHELL_CMD_EXPORT(your_command_name,your_command_function);
4
Simulating nr_micro_shell under Linux
<span>./examples/simulator/</span>
directory, and you can still add custom commands in the <span>./examples/nr_micro_shell_commands.c</span>
file as described above. After adding, you can use the make command to compile the source code, and the generated executable file will be <span>./examples/simulator/out/nr_micro_shell</span>
or <span>./examples/simulator/out/nr_micro_shell_db</span>
. The usable make commands are as follows# Compile the executable file
make
# Compile the simulation executable file
make debug
# Clean up compiled files
make clean
5
Notes
const static_cmd_st static_cmd[] =
{
.....
{"\0",NULL}
};
Original source:Maintainer: Nrusher
1. None)
2. Why can’t I draw schematics well? These tips are essential
3. How to display IP location on embedded devices?
4. RISC-V faces challenges in MCU/MPU and RTOS…
5. A method for self-updating firmware in microcontrollers!
6. The Xuan Tie Cup RISC-V Application Innovation Competition officially starts, registration is now open!
Disclaimer: This article is a network reprint, and the copyright belongs to the original author. If there are copyright issues, please contact us, and we will confirm the copyright based on the copyright certificate you provide and pay the remuneration or delete the content.