当前位置:网站首页>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
边栏推荐
- AI CC 2019 installation tutorial under win10 (super detailed - small white version)
- Opencv4 QR code recognition test
- PHP export excel table
- PolarMask is not in the models registry
- 一个函数秒杀2Sum 3Sum 4Sum问题
- (valid for personal testing) compilation guide of paddedetection on Jetson
- 创下国产手机在海外市场销量最高纪录的小米,重新关注国内市场
- Process seven state transition diagram
- MATLAB lit plusieurs diagrammes fig et les combine en un seul diagramme (sous forme de sous - Diagramme)
- [AI vision · quick review of robot papers today, issue 29] Mon, 14 Feb 2022
猜你喜欢

matlab讀取多張fig圖然後合並為一張圖(子圖的形式)

Source code and update details of new instance segmentation network panet (path aggregation network for instance segmentation)

LabVIEW 小端序和大端序区别

为什么推荐你学嵌入式

OpenCV----YOLACT实例分割模型推理

Variables, constants, operators

Installation and configuration of clion under win10

【BIM+GIS】ArcGIS Pro2. 8 how to open Revit model, Bim and GIS integration?
![[AI vision · quick review of NLP natural language processing papers today, issue 30] Thu, 14 APR 2022](/img/cc/21b20f56a7eb3e43b9c23792c597ef.png)
[AI vision · quick review of NLP natural language processing papers today, issue 30] Thu, 14 APR 2022
![[BIM introduction practice] wall hierarchy and FAQ in Revit](/img/95/e599c7547029f57ce23ef4b87e8b9a.jpg)
[BIM introduction practice] wall hierarchy and FAQ in Revit
随机推荐
ROS series (IV): ROS communication mechanism series (2): Service Communication
VS Studio 修改C語言scanf等報錯
C语言 字符常量
Machine translation baseline
Why is it necessary to divide the variance by 255^2 when adding Gaussian noise using the imnoise function of MATLAB
Vs Studio modifie le langage C scanf et d'autres erreurs
伦敦银最新价格走势图与买卖点
Man's life
The whole process of connecting the newly created unbutu system virtual machine with xshell and xftp
OpenCV----YOLACT实例分割模型推理
【测绘程序设计】坐标方位角推算神器(C#版)
[AI vision · quick review of robot papers today, issue 29] Mon, 14 Feb 2022
【ICCV 2019】MAP-VAE:Multi-Angle Point Cloud-VAE: Unsupervised Feature Learning for 3D Point Clouds..
標識符、關鍵字、數據類型
Photoshop installation under win10
Cause analysis of incorrect time of AI traffic statistics of Dahua Equipment Development Bank
How Zotero quotes in word jump to references / hyperlink
According to the category information and coordinate information of the XML file, the category area corresponding to the image is pulled out and stored in the folder.
Express middleware ① (use of Middleware)
Vs studio modifies C language scanf and other errors