当前位置:网站首页>STM32 upper μ C / shell transplantation and Application
STM32 upper μ C / shell transplantation and Application
2022-04-23 04:00:00 【Chenxr32】
In line with “ No suspension ” Principles , You can't be idle at home , Recently, it has been further explored μC/OS When I found out μC/Shell, Make a decisive decision to try .
Micrium Our products are open source ,GitHub You can download the code on .https://github.com/weston-embedded
Let's start with μC/Shell File structure , Then introduce the transplantation method and practical application .
μC/Shell File structure
\Cfg\Template\shell_cfg.h
μC/Shell Configuration file for , Set instruction table size 、 Instruction parameter format 、 Maximum instruction length and other parameters .
\Cmd\General\sh_shell.c, sh_shell.h
I don't understand what these two documents are for , It's not used for transplantation .
\Source\shell.c
μC/Shell All function interfaces of are in this file , Include Shell initialization 、 Add instructions 、 Delete instruction 、 Function interfaces such as execution instructions .
\Source\shell.h
μC/Shell The header file , Including some functions 、 A function pointer 、 Structure 、 Variable declaration and macro definition .
\Terminal\ Terminal folder , The interface provided is convenient for MCU and PC Terminal interaction .
\Terminal\Cfg\Template\terminal_cfg.h
Terminal configuration file .
\Terminal\Mode\VT100\terminal_mode.c
Functions including reading and writing terminal instructions .
\Terminal\OS\uCOS-III\terminal_os.c
coordination uCOS-III Documents used , Create a terminal task . There is also one that can be used for uCOS-II The file of .
\Terminal\Serial\Template\terminal_serial.c
Input / output interface file , When transplanting, it is necessary to modify the functions in the file to cooperate with the hardware interface of MCU .
\Terminal\Source\terminal.c, terminal.h
Including terminal initialization 、 Terminal task function, etc .
μC/Shell transplant
Integrated development environment :keil5. Single chip microcomputer :STM32F405, Transplanted in advance μC/OS-III operating system .
1、 Create... In the project directory UCShell Folder , take μC/Shell Files copied to UCShell In the folder , The file structure can be adjusted by yourself .
2、 stay Keil To establish UCShell and UCShell_terminal grouping , Add corresponding files to the project , I am using uCOS-III Of terminal_os.c file , Does not add \Cmd\General\ The files under the . Configuration header path .
3、 modify terminal_serial.c file . Because the peripheral configuration file I wrote myself is used C++ Written , For ease of invocation C++ The function interface , I will terminal_serial.c Change it to terminal_serial.cpp, stay terminal.h File Riga extern "C".
/*
TerminalSerial_Init Function is used to configure MCU serial port , I configured the serial port in other files .
*/
CPU_BOOLEAN TerminalSerial_Init (void)
{
return (DEF_OK);// In the original file is DEF_FAIL, Be sure to change it to DEF_OK.
}
/*
TerminalSerial_Exit Close the serial port function , There is no need to change .
*/
void TerminalSerial_Exit (void)
{
}
/*
TerminalSerial_Wr Serial port sends string , Add serial port sending function .
*/
CPU_INT16S TerminalSerial_Wr (void *pbuf,
CPU_SIZE_T buf_len)
{
board.USART6Send((unsigned char*)pbuf,buf_len);//USART6 Send string .
return (-1);
}
/*
TerminalSerial_RdByte Read a byte from the serial port .
I'm taking bytes from the buffer queue , The bytes in the buffer queue are sent when the serial port is interrupted .
When the buffer queue is empty , The return value is one 0x00.
*/
CPU_INT08U TerminalSerial_RdByte (void)
{
unsigned char byte = 0x00;
if(!shell_rx_queue.EmptyCheck())
{
byte = shell_rx_queue.GetData();
}
return byte;
}
/*
TerminalSerial_WrByte Serial port sends one byte , Add serial port sending function .
*/
void TerminalSerial_WrByte (CPU_INT08U c)
{
board.USART6Send((unsigned char*)&c,1);
}
thus ,μC/Shell Migration complete , Next, we need to test the success of transplantation with practice .
μC/Shell application
newly build myshell.cpp and myshell.h file , Write a command line control LED The highlighted code verifies whether the migration is successful .
//myshell.c
#include "myshell.h"
#include "shell.h"
#include "terminal.h"
#include "stm32f4xx.h"
// The function prototype , The arguments to the function must be of this form , Otherwise, it cannot be used normally .
CPU_INT16S LedCmd(CPU_INT16U argc,
CPU_CHAR *argv[],
SHELL_OUT_FNCT out_fnct,
SHELL_CMD_PARAM *pcmd_param);
// Instruction list ,"LED" It's the order ,LedCmd Is an instruction callback function .
static SHELL_CMD ShellCmdTbl[] =
{
{"LED", LedCmd},
{0, 0}
};
//Shell initialization , stay μC/OS Middle note in system startup task .
void ShellInit(void)
{
SHELL_ERR err;
Shell_Init(); // initialization Shell
Terminal_Init(); // Initialize the terminal
Shell_CmdTblAdd((CPU_CHAR*)"LED",ShellCmdTbl,&err);// Add an instruction
}
/****************************************************
//LED Instruction callback function , The parameter must be in this form .
//argc Record the number of parameters , Only when the instruction has no parameters; otherwise 1;
//argv String pointer array , Record instructions and parameters ,argv[0] It's the order LED,argv[1] Is the parameter ON or OFF, If there are more parameters , The parameter will exist argv[2]...
//out_fnct A function pointer , Function response points to terminal.c Medium Terminal_OutFnct function ;
//pcmd_param At present, we don't know what this parameter is used for .
*****************************************************/
CPU_INT16S LedCmd(CPU_INT16U argc,
CPU_CHAR *argv[],
SHELL_OUT_FNCT out_fnct,
SHELL_CMD_PARAM *pcmd_param)
{
CPU_INT16S output;
CPU_INT16S ret_val;
if(argc == 2)
{
if(!Str_Cmp(argv[1],"ON"))
{
GPIOB->BSRRL = GPIO_Pin_15;// Light up
}
else if(!Str_Cmp(argv[1],"OFF"))
{
GPIOB->BSRRH = GPIO_Pin_15;// Turn off the lights
}
output = out_fnct((CPU_CHAR*)"OK",(CPU_INT16U)Str_Len("OK"),pcmd_param->pout_opt);
}
else if(argc > 2)
{
output = out_fnct((CPU_CHAR*)"error: too many arguments",(CPU_INT16U)Str_Len("error: too many arguments"),pcmd_param->pout_opt);
}
else
{
output = out_fnct((CPU_CHAR*)"error: missing argument",(CPU_INT16U)Str_Len("error: missing argument"),pcmd_param->pout_opt);
}
ret_val = output;
return ret_val;
}
After the code is written, you can try it , stay SecureCRT Enter a few instructions on the to see the phenomenon .(LED I won't take pictures when the light is off )
Practice has proved , Successful transplantation ,μC/Shell It can be used normally. .
μC/Shell Please see the detailed description of μC/Shell Official documents .
μC/Shell Template download :https://download.csdn.net/download/QDchenxr/12262695
版权声明
本文为[Chenxr32]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204230356325245.html
边栏推荐
- (valid for personal testing) compilation guide of paddedetection on Jetson
- UDP协议与TCP协议
- 伦敦银最新价格走势图与买卖点
- Source code and update details of new instance segmentation network panet (path aggregation network for instance segmentation)
- Xiaomi, which has set the highest sales record of domestic mobile phones in overseas markets, paid renewed attention to the domestic market
- UDP protocol and TCP protocol
- Vscode download and installation + running C language
- Counting and sorting (C language implementation) -- learning notes
- [BIM introduction practice] wall hierarchy and FAQ in Revit
- What if you encounter symbols you don't know in mathematical formulas
猜你喜欢
【测绘程序设计】坐标方位角推算神器(C#版)
Installation and configuration of MinGW under win10
Does China Mobile earn 285 million a day? In fact, 5g is difficult to bring more profits, so where is the money?
Photoshop installation under win10
Identifier, keyword, data type
Process seven state transition diagram
【测绘程序设计】坐标反算神器V1.0(附C/C#/VB源程序)
Source code and update details of new instance segmentation network panet (path aggregation network for instance segmentation)
As a code farmer, what kind of experience is it that a girlfriend can code better than herself?
Basic knowledge of convolutional neural network
随机推荐
现货黄金基本介绍
PHP export excel table
LabVIEW 小端序和大端序区别
Openvino only supports Intel CPUs of generation 6 and above
中国移动日赚2.85亿很高?其实是5G难带来更多利润,那么钱去哪里了?
减治思想——二分查找详细总结
Paddlepaddle model to onnx
Nel ASA: her ø Ya facility in Norway officially opened
Thought of reducing Governance -- detailed summary of binary search
创下国产手机在海外市场销量最高纪录的小米,重新关注国内市场
Second kill all interval related problems
Matlab reads multiple fig graphs and then combines them into one graph (in the form of sub graph)
Machine translation baseline
RuntimeError: output with shape [4, 1, 512, 512] doesn‘t match the broadcast shape[4, 4, 512, 512]
[latex] differences in the way scores are written
RuntimeError: output with shape [4, 1, 512, 512] doesn‘t match the broadcast shape[4, 4, 512, 512]
Why is it necessary to divide the variance by 255^2 when adding Gaussian noise using the imnoise function of MATLAB
Concepts of objects and classes
Cmake qmake simple knowledge
Process seven state transition diagram