Implementation method of Shell function in MCU (Microprogrammed Control Unit) BareMetal software operation mode
By embedding the Shell function component in MCU Bare Metal mode, the inconvenience of traditional debugging methods is solved, enabling command-line interaction and file transfer, improving debugging convenience and efficiency, and maintaining low resource consumption and high reliability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- CHINESE AERONAUTICAL RADIO ELECTRONICS RES INST
- Filing Date
- 2025-12-10
- Publication Date
- 2026-04-21
AI Technical Summary
In the MCU Bare Metal operating mode, traditional debugging methods are inconvenient, cannot achieve command line interaction and file transfer, rely on simulator tools, and are difficult to view resource information. Unlike Linux or VxWorks systems, functions cannot be dynamically invoked through user input.
The Shell functional component is embedded in the MCU Bare Metal software, including serial port opening, initialization and command parsing modules, to realize the interaction and parsing of serial port commands, support command line debugging and file transfer, and has strong extensibility for custom commands.
It enables command-line interaction, simplifies debugging and maintenance, supports file transfer, has low resource consumption, does not affect the functions of the MCU, and improves debugging convenience and efficiency.
Smart Images

Figure CN121901082A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of embedded development in airborne avionics technology. Specifically, it relates to a method for implementing the Shell function of an MCU microcontroller in the Bare Metal software operating mode in airborne avionics products. Background Technology
[0002] Currently, MCU controllers such as the F103 and F407 are being widely used in the field of airborne avionics product health management due to their advantages such as high reliability, low cost, and easy expansion.
[0003] In MCU software design, Bare Metal operation is a common implementation. In this mode, the CPU does not run an operating system, which effectively reduces software complexity and lowers project airworthiness / qualification costs. However, traditional debugging methods in this mode have the following problems:
[0004] 1. Software debugging is not convenient enough, mainly relying on tools such as printers and emulators;
[0005] 2. Viewing certain resource information can only be achieved by recompiling the program or reserving printing options;
[0006] 3. Unlike the Shell console in Linux and VxWorks systems, it cannot dynamically invoke functions through user-input commands.
[0007] While other MCU software in other industries can implement shell functionality through open-source tools such as MCUSH, these solutions mostly rely on real-time operating systems (RTOS) such as FreeRTOS, making them difficult to apply directly to the Bare Metal operating mode. Summary of the Invention
[0008] The purpose of this invention is to provide a method for implementing Shell functionality in MCU Bare Metal operating mode. This method significantly improves the convenience and efficiency of software debugging with minimal increase in system resource consumption.
[0009] The objective of this invention is achieved through the following technical solution:
[0010] A method for implementing Shell functionality in MCU BareMetal operating mode is provided. A Shell functionality component is embedded in the MCU BareMetal software. The Shell functionality component first performs debug serial port initialization. After initialization, it judges the received serial port commands in each cycle. When a valid serial port command is received, the corresponding serial port command program is executed. After execution, it continues to receive serial port commands until the received serial port command is the command to close the debug serial port, at which point the Shell functionality component is closed.
[0011] Preferably, the Shell functional components include a serial port opening module, a serial port initialization module, and a serial port command parsing module;
[0012] After receiving the command to enable the debug serial port, the user terminal sends the openRS232 command. The MCU Bare Metal software then calls the serial port opening module under the Shell function component to enable the debug serial port. After the debug serial port is enabled, the serial port initialization module first completes the initialization of the debug serial port, and then the serial port command parsing module is run. When the serial port command parsing module is waiting for serial port commands, it needs to receive and judge the serial port data sent by the user terminal. If it is a serial port command, it will parse, judge, and execute it, and output it to the user terminal for display.
[0013] Preferably, the serial port opening module is used to provide the function of opening / closing the Shell functional components. The operation flow of the serial port opening module is as follows:
[0014] In runtime mode, send the openRS232 command to the debug serial port;
[0015] After receiving the instruction, the running software compares the instruction with the registered instructions. If the comparison is successful, it continues to the next step; otherwise, it skips the process as an erroneous operation.
[0016] Modify the debug serial port flags;
[0017] Disable other running software functions and enable the debug serial port.
[0018] Preferably, the serial port command parsing module is used to parse the serial port commands input through the debugging serial port and execute the corresponding operations. The parsing process of the serial port command parsing module is as follows:
[0019] When debugging data received from the serial port, first determine if the data is a serial port command type. If the data matches the command type, proceed to the next step to compare the data with the registered commands. If a matching command is found, execute the corresponding function of the registered command. If no matching command is found, print "Incorrect serial port format".
[0020] Preferably, the serial port command parsing module includes the following modules:
[0021] Sensor information parsing and printing module: Parses and prints the required sensor information;
[0022] Configuration file parsing: Parses the configuration file on the user's end.
[0023] Log parsing and printing module: Parses and prints the required log files;
[0024] State switching command module: Switches from the current state to another specified state;
[0025] Software and hardware information parsing module: Parses and prints local software and hardware version information and hardware configuration records;
[0026] Serial port command viewer module: View all executable command-line commands;
[0027] Control command module: Executes the corresponding control commands.
[0028] Preferably, the registration command is a structure member of the serial port command structure, and the structure member contains the command, the execution function, and the description; the serial port command is represented in the form of a structure array, which contains string information, instruction function, and formal parameter information.
[0029] The beneficial effects of this invention are as follows:
[0030] This invention implements a design method for a debug shell by injecting components into the MCU Bare Metal mode software, with the following effects:
[0031] 1) Command line interaction is implemented: users can send commands through the serial port, the MCU Shell receives and executes these commands, and returns the execution results;
[0032] 2) Facilitates debugging and maintenance: The Shell function makes debugging and maintenance more convenient, allowing users to start / stop debug mode, print debugging information, configure system parameters, etc.
[0033] 3) Facilitates file transfer: Supports file transfer protocols such as Ymodem, making it easy to transfer program or data files to the MCU;
[0034] 4) Scalability: Users can customize command scripts and add new command functions as needed to enhance the system's flexibility and functionality.
[0035] 5) Low resource consumption: The design takes resource consumption into account to ensure efficient operation even in low-resource environments;
[0036] 6) High reliability: Triggered only under special conditions, without affecting the functions of the MCU. Attached Figure Description
[0037] Figure 1 This is a diagram showing the main functional architecture of the Bare Metal software for the airborne MCU.
[0038] Figure 2 This is a flowchart illustrating the operation of the Shell functional component embedded in the software.
[0039] Figure 3 This defines the calling relationship between the client and the Shell functional components.
[0040] Figure 4 Flowchart for enabling serial port debugging.
[0041] Figure 5 This is a flowchart for parsing serial port commands. Detailed Implementation
[0042] The present invention will now be described in further detail with reference to the accompanying drawings and embodiments.
[0043] As an example, in this embodiment, the airborne MCU Bare Metal software is divided into a boot program, airborne application software, and ground maintenance software according to its main functions. Each time the device starts, it first enters the boot program, which then starts either the airborne application software or the ground maintenance software based on the jump state. The ground maintenance software is used for firmware loading, log analysis, status detection, etc., while the airborne application software is used to implement airborne functions. Based on this software architecture, this embodiment embeds Shell functional components into the airborne application software and the ground maintenance software to implement the Bare Metal runtime mode Shell console function, such as... Figure 1 As shown.
[0044] The Shell functional component is embedded in the airborne application status and ground maintenance status software. Each loop executes a check; if the serial port command is valid, it is executed. The overall flow of the Shell functional component is as follows: Figure 2 As shown:
[0045] The Shell function component first performs the debug serial port initialization operation. After initialization, it checks the received serial port commands in each cycle. When a valid serial port command is received, the corresponding serial port command program is executed. After execution, it continues to receive serial port commands until the received serial port command is the command to close the debug serial port, at which point the Shell function component is closed.
[0046] The calling relationship between the user client (PC-side serial port tool) and the Shell functional components, such as Figure 3 As shown:
[0047] In airborne application mode, after receiving the command to enable the debug serial port, the user sends the `openRS232` command. The MCUBare Metal software then calls the serial port opening module under the Shell function component to enable the debug serial port. After enabling the debug serial port, the serial port initialization module first completes the initialization of the debug serial port, and then the serial port command parsing module runs. While waiting for serial port commands, the serial port command parsing module needs to receive and judge the serial port data sent by the user terminal. If it is a serial port command, it parses, judges, executes, and outputs it to the user terminal for display.
[0048] After opening the debug serial port, the user can input serial port commands, including sensor information printing, log parsing and printing, hardware and software information printing, serial port command viewing, and status switching commands. Serial port commands are sent to the serial port command parsing module through the command input interface. The Shell functional component itself contains multiple modules to implement various sub-functions of the Shell functional component. These modules are:
[0049] Serial port initialization module: Used to initialize the debug serial port, including command line commands and the status of the debug serial port;
[0050] Sensor information parsing and printing module: Parses and prints the required sensor information;
[0051] Configuration file parsing: Parses the configuration file on the user's end.
[0052] Serial port enabling module: Provides the function to enable / disable the Shell functionality component;
[0053] Log parsing and printing module: Parses and prints the required log files;
[0054] State switching command module: Switches from the current airborne application state to the ground maintenance state;
[0055] Serial port command parsing module: Parses commands input from the serial port and executes the corresponding operations.
[0056] Software and hardware information parsing module: Parses and prints local software and hardware version information and hardware configuration records;
[0057] Serial port command viewer module: View all executable command-line commands;
[0058] Control command module: Executes the corresponding control commands.
[0059] The serial port opening module provides the function of enabling serial port printing output. It can only be opened by inputting a special command (openRS232). This module needs to be called by the user in the serial port data processing.
[0060] The operation flow of the serial port enabling module is as follows: Figure 4 As shown:
[0061] In runtime mode, send commands (openRS232) to the debug serial port;
[0062] After receiving serial port data, the running software compares the instruction with the registered instructions. If the comparison is successful, it continues to the next step; otherwise, it skips the process as an erroneous operation.
[0063] Modify the debug serial port flags;
[0064] Disable other running software functions and enable the debug serial port.
[0065] The parsing process of the serial port command parsing module is as follows: Figure 5 As shown:
[0066] When debugging data received from the serial port, first perform a simple check on the data to determine if it is a serial port command type. If the data matches the command type, proceed to the next step to compare the data with the registered commands. If a matching command is found, execute the corresponding function of the registered command. If no matching command is found, print "Incorrect serial port format".
[0067] The registered command-line commands are members of the serial port command structure. The members of the structure are shown in Tables 1 and 2 below:
[0068] Table 1 Serial Port Command Structure Table
[0069] Structure members Member Definition Order char cmd_name[MAX_LENGTH] Execution function void(*functions)(int argc,char*argv[]); illustrate char cmd_description[MAX_LENGTH] Transmission of parameters uint8_t parameter_num Command keyword length uint8_t cmd_head_len
[0070] Structure members consist of commands, execution functions, and descriptions.
[0071] Table 2 Execution Function Parameter Table
[0072]
[0073] In the program, Shell command information is presented in the form of a structure array, which includes string information, command functions, formal parameter information, etc., making it convenient for users to customize and add.
[0074] Commonly used registration command-line commands are shown in Table 3, and can also be flexibly extended based on the above format:
[0075] Table 3. Detailed List of Serial Port Commands
[0076]
[0077] This embodiment implements Shell control functionality by injecting components into the MCU Bare Metal mode software. While maintaining the system resource usage of airborne product applications, it significantly improves the operation methods for software and hardware debugging, file loading, log parsing, and other scenarios in MCU Bare Metal mode, providing a more convenient way to operate. It solves the dependence of MCU debugging in Bare Metal mode on the emulator, and has high economic benefits and promotional value.
[0078] It is understood that those skilled in the art can make equivalent substitutions or modifications to the technical solution and inventive concept of the present invention, and all such substitutions or modifications should fall within the protection scope of the appended claims.
Claims
1. A method for implementing Shell functionality in MCU Bare Metal operating mode, characterized in that... The Shell function component is embedded in the MCUBare Metal software. The Shell function component first performs the debug serial port initialization operation. After the initialization is completed, it judges the received serial port command in each cycle. When a valid serial port command is received, the corresponding serial port command program is executed. After the execution is completed, it continues to receive serial port commands until the received serial port command is the command to close the debug serial port, at which point the Shell function component is closed.
2. The method for implementing Shell functionality in MCU Bare Metal operating mode according to claim 1, characterized in that... The Shell functional components include a serial port opening module, a serial port initialization module, and a serial port command parsing module. After receiving the command to enable the debug serial port, the user end sends the openRS232 command. The MCU Bare Metal software calls the serial port opening module under the Shell function component to enable the debug serial port. After the debug serial port is enabled, the serial port initialization module first completes the initialization of the debug serial port, and then the serial port command parsing module is run. When the serial port command parsing module is waiting for a serial port command, it needs to receive and judge the serial port data sent by the user terminal. If it is a serial port command, it will parse, judge and execute it, and output it to the user terminal for display.
3. The method for implementing Shell functionality in MCU Bare Metal operating mode according to claim 2, characterized in that... The serial port enabling module provides the function to enable / disable the Shell functionality component. The operation flow of the serial port enabling module is as follows: In runtime mode, send the openRS232 command to the debug serial port; After receiving the instruction, the running software compares the instruction with the registered instructions. If the comparison is successful, it continues to the next step; otherwise, it skips the process as an erroneous operation. Modify the debug serial port flags; Disable other running software functions and enable the debug serial port.
4. The method for implementing Shell functionality in MCU Bare Metal operating mode according to claim 2, characterized in that... The serial port command parsing module is used to parse serial port commands input through the debugging serial port and execute the corresponding operations. The parsing process of the serial port command parsing module is as follows: When debugging data received from the serial port, first determine if the data is a serial port command type. If the data matches the command type, proceed to the next step to compare the data with the registered commands. If a matching command is found, execute the corresponding function of the registered command. If no matching command is found, print "Incorrect serial port format".
5. The method for implementing Shell functionality in MCU Bare Metal operating mode according to claim 4, characterized in that... The serial port command parsing module includes the following modules: Sensor information parsing and printing module: Parses and prints the required sensor information; Configuration file parsing: Parses the configuration file on the user's end. Log parsing and printing module: Parses and prints the required log files; State switching command module: Switches from the current state to another specified state; Software and hardware information parsing module: Parses and prints local software and hardware version information and hardware configuration records; Serial port command viewer module: View all executable command-line commands; Control command module: Executes the corresponding control commands.
6. The method for implementing Shell functionality in MCU Bare Metal operating mode according to claim 4, characterized in that... The registration command is a member of the serial port command structure. The structure members contain the command, the execution function, and the description. The serial port command is represented in the form of a structure array, which contains string information, instruction functions, and formal parameter information.