Variable real-time tracking and debugging system and method and computer readable storage medium
By connecting the standard debugging interface and the serial interface of the host computer on the MCU, and using the memory mapping mechanism to find and read and write variables, the problems of high debugging costs and insufficient flexibility of MCU are solved, and efficient and flexible debugging methods are realized.
Patent Information
- Application Number
- CN202311643508.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-12-01
- Publication Date
- 2025-06-03
AI Technical Summary
In the prior art, MCU debugging costs are high, debugging methods are inflexible, occupying system resources, low communication speed, relying on source code, and not suitable for high-speed operation or formal use scenarios.
It provides a real-time variable tracking and debugging system, which is connected to the serial interface of the host computer through the standard debugging interface of the microcontroller, and uses the memory mapping mechanism to find the variable address in the preset storage space and perform read and write operations.
It reduces debugging costs, improves debugging flexibility, does not occupy microcontroller resources, and improves communication speed. It is suitable for high-speed operation or formal use scenarios. It does not require source code files, and realizes real-time reading and display of variable values.
Smart Images

Figure CN120085572A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of microprocessor controllers, and particularly to a variable real-time tracking and debugging system, method, and computer-readable storage medium. Background Art
[0002] Currently, in the fields of current automobiles, consumer electronics, industrial control, computer networks, and communications, etc., microcontroller units (MCUs) are widely used in various devices and systems. As the core component for controlling and executing various tasks, the stability and reliability of the software operation of the MCU become crucial. To ensure the normal operation and debugging of the MCU, developers usually need to use various debugging methods.
[0003] There are mainly two traditional MCU debugging methods: Method 1 is that the host computer is connected to the MCU through an emulator, and debugging is carried out by adding breakpoints with the help of existing specialized commercial debugging software (such as Keil, IAR, etc.); Method 2 generally does not use these specialized commercial software, but mainly connects the host computer and the MCU through a serial port or an I 2 C port. The host computer starts the debugging instruction module according to the debugging requirements, sends debugging instructions to the MCU through the communication module. After receiving the debugging instructions through the communication module, the MCU starts the corresponding debugging function module to debug the MCU; the debugging instruction module is configured to call corresponding debugging instructions to debug the MCU according to the debugging requirements; the debugging function module is configured to correspond to the debugging instruction module and start the corresponding debugging function module to debug the MCU according to the debugging instructions issued by the debugging instruction module. However, these methods all have certain limitations and deficiencies.
[0004] When using Method 1 for debugging, it is necessary to have source code files, the debugging method is relatively inflexible, and the debugging cost is relatively high. Method 2 requires installing a communication module and a debugging function module on the MCU, which will occupy the system resources of the MCU during debugging. Moreover, the communication speed of the serial port or I 2 C port is relatively slow, and some MCUs do not even have a serial port or I 2 C port. For example, when using an analog serial port, it will waste relatively many resources such as program memory and data memory. When diagnosing errors in high-speed operation or formal use scenarios, the performance of the MCU cannot be maximally exerted, which may affect the operation of the MCU, and it also needs to occupy the hardware resources of the serial port or I 2 C. Therefore, it is not suitable for high-speed operation or formal use scenarios.
[0005] Therefore, the technical problems of the prior art mainly include: (1) High debugging cost: The common debugging method in traditional methods is to use commercial debugging software and emulators, which requires purchasing additional dedicated hardware and software licenses. This increases the cost of the project, especially for small-scale development teams or projects with limited budgets. (2) Insufficient debugging flexibility: Debugging in traditional methods often requires pre-setting breakpoints or pre-defined debugging function modules. This fixed debugging method may not be able to adapt to complex and changing debugging requirements, limiting the flexibility of developers during the debugging process. (3) Occupying MCU resources: Some traditional methods require installing communication modules and debugging function modules on the MCU, which will occupy the system resources of the MCU, possibly leading to performance degradation or restricting the normal operation of the MCU. (4) Limited communication speed or interface: Traditional methods using serial ports or I2C ports for communication have a relatively slow communication speed. Especially in scenarios that require high-speed operation or real-time debugging, they cannot meet the actual needs. Moreover, some MCUs do not have serial ports or I2C ports, and even if they do, these resources are occupied, making it difficult for customers to use. (5) Dependence on source code: Some methods require obtaining source code files to conduct debugging. However, due to the particularity of the source code files themselves (such as trade secret protection), it is usually difficult to obtain source code files, thus limiting the scope and effect of debugging. Summary of the Invention
[0006] In view of the above-mentioned disadvantages of the prior art, the present application provides a variable real-time tracking and debugging system, method, and computer-readable storage medium, which are used to solve the problems in the prior art such as high debugging cost, inflexible debugging method, occupying system resources, low communication speed, dependence on source code, and inapplicability to high-speed operation or formal use scenarios.
[0007] To achieve the above object and other related objects, the first aspect of the present application provides a variable real-time tracking and debugging system, including: a microcontroller provided with a standard debugging interface; a host computer provided with a serial interface; the serial interface is electrically connected to the standard debugging interface after interface conversion; wherein, the host computer transmits variable operation address information to the standard debugging interface on the microcontroller through the serial interface; after receiving the variable operation address information, the microcontroller searches for the corresponding variable address in the preset storage space based on the memory mapping mechanism according to the variable operation address information, so as to perform corresponding read and write operations on the variable value stored in the variable address.
[0008] In some embodiments of the first aspect of the present application, the host computer includes: a first control module, a parsing module, and a reading and writing module; the first control module is electrically connected to the parsing module and the reading and writing module respectively; the reading and writing module is electrically connected to the serial interface.
[0009] In some embodiments of the first aspect of the present application, the variable operation address information includes: variable read operation address information; wherein: the first control module generates a corresponding parsing instruction in response to a first user operation instruction, and transmits the parsing instruction to the parsing module; the parsing module parses the pre-stored microcontroller execution file according to the parsing instruction to obtain the variable read operation address information, and transmits it to the serial interface through the first control module and the read-write module.
[0010] In some embodiments of the first aspect of the present application, the variable operation address information further includes: variable write operation address information; wherein: the first control module generates the variable write operation address information in response to a second user operation instruction, and transmits the variable write operation address information to the serial interface through the read-write module.
[0011] In some embodiments of the first aspect of the present application, the host computer further includes: a display module; the display module is electrically connected to the first control module and is used to display in real time the variable values stored in the variable address.
[0012] In some embodiments of the first aspect of the present application, the host computer further includes: a first storage module; the first storage module is electrically connected to the first control module and is used to store the variable values read and stored in the variable address.
[0013] In some embodiments of the first aspect of the present application, the microcontroller includes a second control module and a second storage module; the second control module is electrically connected to the second storage module; the second storage module is electrically connected to the standard debugging interface; the second control module is used to receive the variable operation address information through the second storage module, so as to control the second storage module to perform corresponding read and write operations on the variable values stored in the variable address according to the variable operation address information.
[0014] To achieve the above object and other related objects, the second aspect of the present application provides a method for real-time tracking and debugging of variables, which is applied to the host computer in the above-mentioned variable real-time tracking and debugging system; the method includes: transmitting the variable operation address information to the standard debugging interface on the microcontroller through the serial interface, so that after receiving the variable operation address information, the microcontroller searches for the corresponding variable address in the preset storage space based on the memory mapping mechanism according to the variable operation address information, so as to perform corresponding read and write operations on the variable values stored in the variable address.
[0015] In some embodiments of the second aspect of the present application, the method further includes: the host computer receives in real time the variable values obtained by the microcontroller performing corresponding read and write operations according to the variable operation address information, for display or storage.
[0016] To achieve the above object and other related objects, a third aspect of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the variable real-time tracking and debugging method is implemented.
[0017] As described above, the variable real-time tracking and debugging system, method and computer-readable storage medium of the present application have the following
[0018] Beneficial effects:
[0019] (1) Low-cost debugging: No need to use dedicated commercial debugging software, thus reducing the debugging cost;
[0020] (2) Flexible debugging method: Can flexibly select the variables to be tracked according to actual needs, without the need to preset breakpoints or use predefined debugging function modules, and can also dynamically adjust the variable values, facilitating error diagnosis and debugging;
[0021] (3) No microcontroller resource occupation: No need to install additional communication modules or function modules on the microcontroller. The reading process does not require the participation of the microcontroller's computing resources, does not occupy the microcontroller's system resources, does not affect the operation of the microcontroller, and does not require occupying the microcontroller's computing resources and communication interface resources;
[0022] (4) Improved communication speed: By directly using the standard debugging port, the communication speed is increased, which is suitable for high-speed operation or formal use scenarios, and maximizes the efficiency of the microcontroller;
[0023] (5) No source code dependence: No source code files are required, and debugging can be carried out without source code;
[0024] (6) Real-time performance: Realizes real-time reading and display of variable values, can understand the operation status of the microcontroller in real time, and is more efficient and convenient. BRIEF DESCRIPTION OF THE DRAWINGS
[0025] Figure 1 It shows a schematic structural diagram of a variable real-time tracking and debugging system in an embodiment of the present application.
[0026] Figure 2 It shows a schematic flowchart of a variable real-time tracking and debugging method in an embodiment of the present application.
[0027] Figure 3It shows a specific embodiment diagram of a variable real-time tracking and debugging system in an embodiment of the present application.
[0028] Figure 4 It shows a specific embodiment diagram of a variable real-time tracking and debugging method in an embodiment of the present application. Detailed implementation manners
[0029] The following uses specific specific examples to illustrate the implementation manners of the present application. Those skilled in the art can easily understand other advantages and effects of the present application from the content introduced in this specification. The present application can also be implemented or applied through other different specific implementation manners. Various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present application. It should be noted that, without conflict, the following embodiments and the features in the embodiments can be combined with each other.
[0030] It should be noted that in the following description, reference is made to the accompanying drawings, which describe several embodiments of the present application. It should be understood that other embodiments can also be used, and mechanical composition, structure, electrical, and operational changes can be made without departing from the spirit and scope of the present application. The following detailed description should not be considered restrictive, and the scope of the embodiments of the present application is only defined by the claims of the published patent. The terms used here are only for describing specific embodiments and are not intended to limit the present application. Spatially related terms, such as "upper", "lower", "left", "right", "below", "beneath", "lower part", "above", "upper part", etc., may be used in the text to facilitate the description of the relationship between one element or feature shown in the figure and another element or feature.
[0031] In the present application, unless otherwise clearly specified and defined, terms such as "install", "connect", "connection", "fix", "hold" should be understood in a broad sense. For example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be directly connected or indirectly connected through an intermediate medium, and it can be the communication inside two elements. For those of ordinary skill in the art, the specific meanings of the above terms in the present application can be understood according to specific situations.
[0032] Furthermore, as used herein, the singular forms "a", "an" and "the" are intended to include the plural forms as well, unless the context clearly dictates otherwise. It should be further understood that the terms "comprises", "comprising" indicate the presence of the stated features, operations, elements, components, items, species, and / or groups, but do not preclude the presence, occurrence or addition of one or more other features, operations, elements, components, items, species, and / or groups. The terms "or" and "and / or" used herein are to be construed as inclusive, or meaning any one or any combination. Thus, "A, B or C" or "A, B and / or C" means "any of the following: A; B; C; A and B; A and C; B and C; A, B and C". Exceptions to this definition occur only when the combination of elements, functions or operations are mutually exclusive in some manner.
[0033] In order to make the objectives, technical solutions and advantages of the present application more clear and understandable, the technical solutions in the embodiments of the present application will be further described in detail through the following embodiments in conjunction with the accompanying drawings. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0034] Before further elaborating on the present application, the nouns and terms involved in the embodiments of the present application are described. The nouns and terms involved in the embodiments of the present application are applicable to the following explanations:
[0035] <1> Microcontroller Unit (MCU, Micro Control Unit): Also known as Single Chip Microcomputer or microcontroller, it is a computer-on-a-chip that appropriately reduces the frequency and specifications of the Central Processing Unit (CPU), and integrates peripheral interfaces such as memory, timer, USB, A / D conversion, UART (Universal Asynchronous Receiver-Transmitter), PLC (Programmable Logic Controller), DMA (Direct Memory Access), and even LCD driver circuits on a single chip to provide different combinations of control for different application scenarios. It can be found in various applications such as mobile phones, PC peripherals, remote controls, automotive electronics, industrial stepper motors, and robotic arm control.
[0036] <2>ELF file (Executable and Linking Format): ELF is a commonly used binary file format for representing executable files, shared libraries, object files, and core dump files. There are mainly the following three types: Relocatable File, which contains code and data generated by the compiler. The linker will link it with other object files to create an executable file or a shared object file. In the Linux system, the suffix of this type of file is generally.o. Executable File, which is the program we usually execute in Linux. Shared Object File: It contains code and data. This type of file is what we call a library file, generally ending with.so. In general, it has the following two usage scenarios: Link Editor (ld) and Dynamic Linker. ELF files support embedding debugging information, including source code line numbers, variable names, function names, etc., providing necessary information for debuggers to facilitate program debugging and analysis.
[0037] <3>JTAG (Joint Test Action Group): It is an international standard test protocol (compatible with IEEE 1149.1), mainly used for in-chip testing. Now most advanced devices support the JTAG protocol, such as ARM, DSP, FPGA devices, etc. The standard JTAG interface has 4 lines, namely mode selection, clock input, data input, and data output. The definitions of related JTAG pins are as follows: TMS, Test Mode Selection, which is used to set the JTAG interface to a specific test mode; TCK, Test Clock Input; TDI, Test Data Input, and data is input into the JTAG interface through the TDI pin; TDO, Test Data Output, and data is output from the JTAG interface through the TDO pin.
[0038] <4> SWD (Serial Wire Debug): is a standard interface for debugging embedded systems. The SWD interface is usually used to connect a debugger / programmer and a target embedded device for debugging, programming, firmware update, etc. The following are some key features of the SWD interface: Simplified wiring: Compared with the traditional JTAG interface, the SWD interface has fewer connection wires, usually only two wires, one for the data line (SWDIO, Serial Wire Debug Input / Output, serial data input and output pins) and one for the clock line (SWCLK, Serial Wire Debug Clock, serial line clock pin), so the connection is simplified; High-speed debugging: The SWD interface supports high-speed debugging, allowing the internal registers and memory of the target device to be read and written in a shorter time; Low power consumption: The SWD interface usually has lower power consumption on the target device, which is very important for embedded systems because they usually need to run for a long time and rely on battery power; Suitable for small-size chips: Since the SWD interface has fewer lines, it is suitable for small-size embedded chips and situations where the PCB (Printed Circuit Board) layout is restricted; Standardization: The SWD interface is a standardized interface that is widely used in various embedded systems and microcontrollers, so it has wide compatibility.
[0039] like Figure 1 As shown, a structural diagram of a variable real-time tracking and debugging system in an embodiment of the present application is shown. The system includes: a microcontroller 200, which is provided with a standard debugging interface; a host computer 100, which is provided with a serial interface; the serial interface is electrically connected to the standard debugging interface after interface conversion; wherein, the host computer 100 transmits the variable operation address information to the standard debugging interface on the microcontroller 200 through the serial interface; after receiving the variable operation address information, the microcontroller 200 searches for the corresponding variable address in the preset storage space according to the variable operation address information based on the memory mapping mechanism, so as to perform corresponding read and write operations on the variable value stored in the variable address.
[0040] The serial interface of the host computer 100 includes interfaces such as USB, and the USB interface can be connected to the microcontroller 200 using a USB to standard debug port adapter, or a data line having two ends that can be connected to the USB interface and the standard debug interface can be used to communicate with the host computer 100 and the microcontroller 200. The standard debug interface of the microcontroller 200 includes, but is not limited to, an SWD interface and a JTAG interface.
[0041] The host computer 100 is directly connected to the standard debugging interface SWD interface or JTAG interface of the microcontroller through a serial interface to a standard debugging interface. This connection method can realize cross-domain data communication transmission. The variable operation address information of the host computer 100 can be transmitted to the microcontroller 200, and then through the memory mapping mechanism (memory-mapped), the host computer 100 can directly read and write the register of the microcontroller 200 or the variable address in the system memory to perform corresponding read and write operations on the variable value stored in the variable address, that is, the host computer 100 and the microcontroller 200 can be directly connected and debugged without using special commercial debugging software or communication modules, thereby reducing the debugging cost.
[0042] It should be noted that by adopting the memory mapping mechanism, the memory of the microcontroller 200 can be mapped to the host computer 100, and data memory sharing can be achieved by sharing the physical cache. After the memory is shared, the host computer 100 can share the memory in the microcontroller 200, and the host computer 100 can access the memory in the microcontroller 200 at any time. The host computer 100 can directly find the corresponding variable address in the microcontroller 200 according to the variable operation address information, so as to perform corresponding read and write operations on the variable value stored in the variable address.
[0043] In one embodiment, the host computer 100 includes: a first control module 110, a parsing module 120, and a read-write module 130; the first control module 110 is electrically connected to the parsing module 120 and the read-write module 130 respectively; the read-write module 130 is electrically connected to the serial interface. The first control module 110 can control the operation and calculation of each module in the host computer 100.
[0044] In one embodiment, the variable operation address information includes: variable read operation address information; wherein: the first control module 110 generates a corresponding parsing instruction in response to a first user operation instruction, and transmits the parsing instruction to the parsing module 120; the parsing module 120 parses the pre-stored microcontroller execution file according to the parsing instruction to obtain the variable read operation address information, and transmits it to the serial interface through the first control module 110 and the read-write module 130.
[0045] It should be noted that the first user operation instruction refers to a variable reading instruction for real-time tracking of variables in the microcontroller 200. After receiving the variable reading instruction, the first control module 110 generates a corresponding parsing instruction. The parsing module 120 receives the parsing instruction issued by the first control module 110 and parses the pre-stored microcontroller execution file to obtain the variable read operation address information corresponding to the variable in the variable reading instruction.
[0046] Specifically, on the host computer side, the pre-stored microcontroller execution file format is an ELF file. The parsing module 120 analyzes the ELF file format and uses a parsing algorithm to parse the ELF execution file of the microcontroller, and can find the corresponding addresses of variables in the execution file and variables during the execution of the file in the microcontroller, so as to determine the corresponding addresses of variables and runtime variables in the microcontroller memory in the variable reading instruction issued by the user.
[0047] Further, the specific process of parsing the ELF file includes:
[0048] Step 1: Open the ELF file, open the ELF file in binary reading mode and parse it.
[0049] Step 2: Parse the ELF file header to obtain the basic attributes and organizational structure of the ELF file. It mainly includes, for example, the machine type, entry point address, etc., and can also obtain information such as the file type, entry point address, positions of the section header table and program header table.
[0050] Step 3: Parse the program header table to obtain segment information; the segment information includes the position, size and access permission of the segment. By parsing the program header table, it is possible to obtain how the system creates a process image, including information about various segments, such as the starting addresses, positions, sizes, access permissions, etc. of each segment of the executable file in the microcontroller.
[0051] Step 4: Parse the section header table to obtain section information; the section information includes the name, size and position of the section. The section header table contains information describing the sections of the file. Each section has an entry in the table, and each entry gives information such as the section name, section size, section position, etc.
[0052] Step 5: Parse the string table to obtain section names, symbol names and segment names. The string table is usually a table composed of symbol names, section names or segment names. When other parts of the ELF file need to reference a certain string, only the serial number of the string in the string table needs to be provided.
[0053] Step 6: Parse the relocation table to obtain the addresses and related information that need to be relocated for each segment. When the linker processes the object file, it must relocate certain parts of the object file, that is, the positions of the references to absolute addresses in the code segment and data segment. This relocation information is all recorded in the ELF file table. For each code segment and data segment that must be relocated, there will be a corresponding relocation table, such as the.rel.text table corresponding to the.text segment. That is to say, the relocation table records the positions in the corresponding segments where the addresses that must be relocated are located.
[0054] Step 7: Parse the symbol table to obtain symbol information; the symbol information includes the name, type, size, and address of the symbol. The symbol table in an ELF file is a data structure used to store information about symbols (such as variables, functions, etc.) defined and referenced in a program. The symbol table is used to record information about symbols defined and referenced in a program, including symbol names, symbol values, symbol sizes, symbol types, etc. It provides a mapping relationship between symbols and addresses for tools such as linkers, loaders, and debuggers to perform symbol resolution and address relocation. The symbol table consists of a series of symbol table entries, with each entry corresponding to a symbol. The symbol table entry contains the name, value, size, symbol binding information, symbol type, etc. of the symbol.
[0055] Step 8: Integrate the above steps to obtain the read variable address information.
[0056] It should be explained that by parsing the ELF file through the parsing module 120, the host computer 100 can obtain the address information of the variable, thereby realizing the reading of the variable in the memory of the microcontroller 200. Therefore, by parsing the executable file through the parsing module in this embodiment, the microcontroller can be flexibly debugged, without being limited to commercial debugging software or communication modules, nor requiring the installation of a debugging function module, without occupying the system resources of the microcontroller, and at the same time, by directly parsing the executable file, the communication speed is improved.
[0057] In one embodiment, the variable operation address information further includes: variable write operation address information; wherein: the first control module 110 generates the variable write operation address information in response to a second user operation instruction, and transmits the variable write operation address information to the serial interface through the read / write module 120.
[0058] It should be noted that when the microcontroller 200 needs to be debugged, the user can issue a second user operation instruction according to actual needs, such as a variable write operation instruction. The first control module 110 generates variable write operation address information according to the variable write operation instruction and sends the variable write operation address information to the serial interface.
[0059] Specifically, at the host computer end, the variable read operation address information obtained by the parsing module 120 is sent to the read / write module 130 through the first control module 110. After receiving the variable read operation address information, the read / write module 130 determines whether it is legal. If it is legal, it proceeds to the next step to facilitate remote viewing of the internal logic. At the same time, the read / write module 130 also receives the variable write operation address information. The read / write module 130 can send the variable read operation address information and the variable write operation address information to the serial interface, and then send them to the microcontroller through the standard debugging interface connected to the serial interface.
[0060] Among them, the variable write operation address information is derived from the second user operation instruction. The variable write operation address information includes address information and write variable information, which means that according to the variable write operation address information, the variable at the corresponding address is found for modifying and debugging the write variable information. A command to modify a variable is directly issued at the host computer end to generate variable write operation address information for modifying the value of a variable at a certain address, so as to simulate various logics, judge whether the logic is correct, and reproduce the problem environment. The host computer can directly find the corresponding address in the microcontroller memory according to the variable read operation address information and the variable read operation address information and perform corresponding read and write operations on the variable at the address. At this time, this kind of read and write operation is real-time, indicating that the variable value can be obtained or modified in real time when the microcontroller is running.
[0061] In one embodiment, the host computer 100 further includes: a display module 140; the display module 140 is electrically connected to the first control module 110 and is used to display in real time the variable value stored in the variable address.
[0062] It should be noted that after the microcontroller 200 obtains the variable value at the corresponding position according to the variable read operation address information, the read variable value is sent back to the host computer 100. The host computer 100 can display the variable value. After the variable value in the microcontroller 200 is modified according to the variable write operation address information, if it conforms to the logic, the modified variable value can be transmitted to the host computer 100, and the modified variable value can also be displayed. At the same time, the obtained variable value can be displayed in real time on the host computer 100 in the form of a curve graph or a table, so that the change trend of the variable value can be observed more clearly, and thus the running state and debugging requirements of the microcontroller can be better understood.
[0063] In one embodiment, the host computer 100 further includes: a first storage module 150; the first storage module 150 is electrically connected to the first control module 110 and is used to store the variable value stored in the variable address read. The variable value of the microcontroller obtained by the host computer can be saved in the host computer for convenient subsequent direct calling or display.
[0064] In one embodiment, the microcontroller 200 includes a second control module 220 and a second storage module 210; the second control module 220 is electrically connected to the second storage module 210; the second storage module 210 is electrically connected to the standard debugging interface; the second control module 220 is configured to receive the variable operation address information through the second storage module 210, so as to control the second storage module 210 to perform corresponding read and write operations on the variable value stored in the variable address according to the variable operation address information. It should be noted that the microcontroller 200 receives the variable read operation address information or the variable write operation address information through the standard debugging interface connected to the host computer 100, and based on the memory mapping mechanism, finds the corresponding variable address in the second storage module of the microcontroller 200 according to the variable read operation address information or the variable write operation address information, so as to perform corresponding read or write operations on the variable value stored in the variable address. The host computer 100 can directly read the variable data from the memory of the microcontroller 200 according to the address corresponding to the variable, and can also modify the value of the variable in real time at the address corresponding to the variable in the microcontroller 200, and judge whether the subsequent service logic is correct, achieving the purpose of real-time tracking of variables and debugging of the microcontroller.
[0065] It should be emphasized that in this application, by innovatively using the method of connecting and parsing the execution file through the standard debugging port, the need for using a dedicated commercial debugging software or additional communication modules and debugging function modules in the traditional debugging method is avoided. This direct connection and file parsing method reduces the complexity and cost of debugging, and at the same time reduces the occupation of microcontroller resources, realizing a more efficient and flexible microcontroller debugging method.
[0066] It should be understood that the division of each module or unit of the above system is only a logical function division. In actual implementation, it can be fully or partially integrated into a physical entity, or physically separated. And these modules or units can all be implemented in the form of software called by a processing element; they can also all be implemented in the form of hardware; or some modules or units can be implemented in the form of software called by a processing element, and some modules or units can be implemented in the form of hardware.
[0067] For example, the above modules or units may be one or more integrated circuits configured to implement the above methods. For example: one or more Application Specific Integrated Circuits (ASICs), or, one or more digital signal processors (DSPs), or, one or more Field Programmable Gate Arrays (FPGAs), etc. Again, when a certain module above is implemented in the form of a processing element scheduler code, the processing element may be a general-purpose processor, such as a Central Processing Unit (CPU) or other processors that can call program code. Again, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
[0068] As Figure 2 shown, a flowchart of a method for real-time variable tracking and debugging in an embodiment of the present application is presented. It is applied to the host computer 100 in the variable real-time tracking and debugging system as described above; the method includes:
[0069] Step S21: Transmit the variable operation address information to the standard debugging interface on the microcontroller 200 through a serial interface. After receiving the variable operation address information, the microcontroller 200 searches for the corresponding variable address in the preset storage space based on the memory mapping mechanism according to the variable operation address information, so as to perform corresponding read and write operations on the variable value stored in the variable address.
[0070] Step S22: The host computer 100 receives in real time the variable value obtained by performing corresponding read and write operations according to the variable operation address information sent by the microcontroller 200, for display or storage.
[0071] It should be explained that in this embodiment, the host computer 100 is directly connected to the microcontroller 200 through the standard debugging port of the microcontroller 200. Then, the execution file of the microcontroller 200 is directly parsed in the host computer 100 to find the corresponding addresses of the variables in the execution file and the variables during the execution of the execution file in the microcontroller 200. Subsequently, the variable value at the corresponding address in the microcontroller 200 is directly read, and the obtained real-time variable data can be displayed or stored in the form of a curve or a table on the host computer 100, achieving the purpose of real-time variable tracking and microcontroller debugging.
[0072] It should be noted that in this application, by using the standard debugging port built in the microcontroller and parsing the execution file of the microcontroller, the host computer can realize the real-time reading and tracking of the variable values in the memory of the microcontroller, and the reading process does not require the computing resources of the lower-level microcontroller to participate. Therefore, the value of the variable can be monitored in real time without affecting the operation of the microcontroller and displayed in the form of a curve or a table, so as to realize efficient debugging of the microcontroller. Such a method not only avoids additional hardware and software costs, but also provides a more flexible debugging method. In addition, this method does not occupy the resources of the microcontroller, avoids the performance problems that may be caused by traditional methods, and does not rely on source code files, bringing a more efficient, practical and economical solution for the debugging of the microcontroller. Moreover, this method is applicable to high-speed operation or formal use scenarios without affecting the operation of the microcontroller.
[0073] As Figure 3 shown, a specific embodiment diagram of a variable real-time tracking and debugging system is presented to elaborate on a variable real-time tracking and debugging system provided in this application. That is, the main interaction process between the host computer and the microcontroller in the variable real-time tracking and debugging system includes the following:
[0074] Step S301: The host computer 100 transmits the variable operation address information to the standard debugging interface on the microcontroller 200 through the serial interface;
[0075] Step S302: After receiving the variable operation address information, the microcontroller 200 searches for the corresponding variable address in the preset storage space based on the memory mapping mechanism according to the variable operation address information to perform corresponding read and write operations on the variable value stored in the variable address;
[0076] Step S303: The host computer 100 receives in real time the variable value obtained by the microcontroller 200 performing corresponding read and write operations according to the variable operation address information for display or storage.
[0077] To facilitate the demonstration of the variable real-time tracking and debugging method of this application, the following specific embodiments are provided for illustration:
[0078] Embodiment 1: A variable real-time tracking and debugging method; As Figure 4 is the specific flowchart of the variable real-time tracking and debugging method in this embodiment. The method includes:
[0079] Step 1: Test whether the connection between the host computer and the microcontroller is normal;
[0080] Step 2: If the connection is normal, read and parse the ELF file; if the connection is abnormal, end the debugging;
[0081] Step 3: After reading and parsing the ELF file, find the variable corresponding address information;
[0082] Step 4: Whether to select a variable; if so, read the variable value at the corresponding address in the microcontroller; if not, end the debugging;
[0083] Step 5: After reading the variable value at the corresponding address in the microcontroller, display or store the variable value;
[0084] Step 6: Determine whether to write the variable to the microcontroller;
[0085] Step 7: If so, write the variable to the microcontroller and then end the debugging; if not, directly end the debugging.
[0086] The present application also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the variable real-time tracking and debugging method is implemented.
[0087] Those of ordinary skill in the art can understand that all or part of the steps of implementing the above method embodiments can be completed by hardware related to a computer program. The foregoing computer program can be stored in a computer-readable storage medium. When the program is executed, it executes the steps including the above method embodiments; and the foregoing storage medium includes: various media such as ROM, RAM, or optical discs that can store program codes.
[0088] In the embodiments provided by the present application, the computer-readable and writable storage medium may include a read-only memory, a random access memory, an EEPROM, a CD-ROM, or other optical disc storage devices, a magnetic disk storage device, or other magnetic storage devices, a flash memory, a USB flash drive, a mobile hard disk, or any other medium that can be used to store desired program codes in the form of instructions or data structures and can be accessed by a computer. Additionally, any connection can be appropriately referred to as a computer-readable medium. For example, if the instructions are sent from a website, a server, or other remote sources using coaxial cables, fiber optic cables, twisted pairs, digital subscriber lines (DSL), or wireless technologies such as infrared, radio, and microwave, then the coaxial cables, fiber optic cables, twisted pairs, DSL, or wireless technologies such as infrared, radio, and microwave are included in the definition of the medium. However, it should be understood that the computer-readable and writable storage medium and the data storage medium do not include connections, carrier waves, signals, or other transient media, but are intended to refer to non-transient, tangible storage media. As used in the application, magnetic disks and optical discs include compact discs (CDs), laser discs, optical discs, digital versatile discs (DVDs), floppy disks, and Blu-ray discs, where disks typically magnetically replicate data, while optical discs optically replicate data using lasers.
[0089] In summary, the present application provides a variable real-time tracking and debugging system, method and computer-readable storage medium, the present application includes a microcontroller, which is provided with a standard debugging interface; a host computer, which is provided with a serial interface; the serial interface is electrically connected to the standard debugging interface after interface conversion; wherein the host computer transmits the variable operation address information to the standard debugging interface on the microcontroller through the serial interface; after receiving the variable operation address information, the microcontroller searches for the corresponding variable address in a preset storage space based on the variable operation address information based on a memory mapping mechanism, so as to perform corresponding read and write operations on the variable value stored in the variable address. The host computer of the present application is directly connected to the microcontroller through the standard debugging port of the microcontroller, and then directly parses the execution file of the microcontroller in the host computer, finds the corresponding address of the variable in the execution file and the variable in the microcontroller when the execution file is running, and then directly reads the variable value of the corresponding address in the microcontroller, and the obtained variable real-time data can be displayed or stored in the host computer in a curve or table form, so as to achieve the purpose of real-time tracking variables and debugging microcontrollers. The present application has the following beneficial effects: no dedicated commercial debugging software is required, thereby reducing the debugging cost; the variables to be tracked can be flexibly selected according to actual needs, without pre-setting breakpoints or using pre-defined debugging function modules, and the variable values can be dynamically adjusted to facilitate error diagnosis and debugging; no additional communication modules or function modules need to be installed on the microcontroller, and the reading process does not require the participation of the microcontroller's computing resources, does not occupy the microcontroller's system resources, does not affect the operation of the microcontroller, and does not need to occupy the microcontroller's computing resources and communication interface resources; by directly using the standard debugging port, the communication speed is improved, which is suitable for high-speed operation or formal use scenarios, and the performance of the microcontroller is maximized; no source code file is required, and debugging can be performed without source code; the real-time reading and display of variable values is realized, and the running status of the microcontroller can be understood in real time, which is more efficient and convenient. Therefore, the present application effectively overcomes the various shortcomings in the prior art and has a high industrial utilization value.
[0090] The above embodiments are merely illustrative of the principles and effects of the present application and are not intended to limit the present application. Anyone familiar with the technology may modify or change the above embodiments without violating the spirit and scope of the present application. Therefore, all equivalent modifications or changes made by a person of ordinary skill in the art without departing from the spirit and technical ideas disclosed in the present application shall still be covered by the claims of the present application.
Claims
1. A variable real-time tracking and debugging system, characterized in that, it includes: A microcontroller with a standard debugging interface; A host computer with a serial interface; the serial interface is electrically connected to the standard debugging interface after interface conversion; Wherein, the host computer transmits variable operation address information to the standard debugging interface on the microcontroller through the serial interface; after receiving the variable operation address information, the microcontroller searches for the corresponding variable address in the preset storage space based on the memory mapping mechanism according to the variable operation address information, so as to perform corresponding read and write operations on the variable value stored in the variable address.
2. The variable real-time tracking and debugging system according to claim 1, characterized in that, The host computer includes: a first control module, a parsing module, and a reading and writing module; the first control module is electrically connected to the parsing module and the reading and writing module respectively; the reading and writing module is electrically connected to the serial interface.
3. The variable real-time tracking and debugging system according to claim 2, characterized in that, The variable operation address information includes: variable read operation address information; wherein: The first control module generates a corresponding parsing instruction in response to a first user operation instruction, and transmits the parsing instruction to the parsing module; the parsing module parses the pre-stored microcontroller execution file according to the parsing instruction to obtain the variable read operation address information, and transmits it to the serial interface through the first control module and the reading and writing module.
4. The variable real-time tracking and debugging system according to claim 2, characterized in that, The variable operation address information further includes: variable write operation address information; wherein: The first control module generates the variable write operation address information in response to a second user operation instruction, and transmits the variable write operation address information to the serial interface through the reading and writing module.
5. The variable real-time tracking and debugging system according to claim 2, characterized in that, The host computer further includes: a display module; the display module is electrically connected to the first control module, and is used to display the variable value stored in the variable address in real time.
6. The variable real-time tracking and debugging system according to claim 2, characterized in that, The host computer further includes: a first storage module; the first storage module is electrically connected to the first control module, and is used to store the variable value stored in the variable address read.
7. The variable real-time tracking and debugging system according to claim 1, characterized in that, The microcontroller includes a second control module and a second storage module; the second control module is electrically connected to the second storage module; the second storage module is electrically connected to the standard debugging interface; the second control module is used to receive the variable operation address information through the second storage module, so as to control the second storage module to perform corresponding read and write operations on the variable value stored in the variable address through the variable operation address information.
8. A variable real-time tracking and debugging method, characterized in that, A host computer applied to the variable real-time tracking and debugging system according to any one of claims 1 to 7; the method includes: Transmitting the variable operation address information to the standard debugging interface on the microcontroller through a serial interface, so that after receiving the variable operation address information, the microcontroller can, based on the memory mapping mechanism, find the corresponding variable address in the preset storage space according to the variable operation address information, so as to perform corresponding read and write operations on the variable value stored in the variable address.
9. The variable real-time tracking and debugging method according to claim 8, characterized in that the method further includes: The host computer receives in real time the variable value obtained by performing corresponding read and write operations according to the variable operation address information sent by the microcontroller, so as to display or store it.
10. A computer-readable storage medium, on which a computer program is stored, characterized in that when the computer program is executed by a processor, it implements the variable real-time tracking and debugging method according to any one of claims 8 or 9.