Remote debugging method for embedded equipment
By introducing Ethernet communication modules and remote debug modules in embedded devices, periodic receiving and processing control instructions sent by the hosting host, and transmitting and commissioning data during the CPU idle, solving the normal operation of the existing technology transfer data transmission device running normally The problem ensures the real time of the task.
Patent Information
- Application Number
- CN202411479904.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-23
- Publication Date
- 2025-01-24
AI Technical Summary
In the prior art, the debugging data transmission generated after debugging of embedded devices occupies CPU memory, interferes with the normal operation of the device, and affects the real-time requirements of tasks.
By introducing an Ethernet communication module and a remote debugging module into the embedded device, it periodically receives control instructions sent by the host, determines the instruction type, and performs corresponding operations. Debugging data is transmitted when the CPU is idle, using priority queues and preset transmission duration strategies to minimize interference with tasks.
Effectively avoid the interference of frequent debugging operations on embedded equipment tasks, ensure the real -time requirements of tasks, and minimize the impact of data transmission on the task.
Smart Images

Figure CN119356908A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of data transmission, and in particular to a remote debugging method for an embedded device. Background Art
[0002] Embedded devices usually adopt the host / target board model during the software development process, that is, the software and hardware resources, development environment and debugging tools on the host machine (usually a PC) are used to develop the software on the target board, and then the target code and executable files are generated through the cross-compilation environment, downloaded to the target machine through Ethernet, USB, etc. After debugging is completed, the program is downloaded and solidified on the target machine to complete the entire development process.
[0003] In the prior art, after debugging an embedded device, debugging data is generated and transmitted directly. If the device is running at this time, the transmission of the debugging data occupies the CPU memory and causes interference with the normal operation of the device, which affects the real-time requirements of the embedded device's tasks. Summary of the invention
[0004] In view of the above defects or deficiencies in the prior art, the present application aims to provide a remote debugging method for an embedded device, wherein the embedded device is interconnected with a host machine via Ethernet, the embedded device comprising an Ethernet communication module and a remote debugging module, the Ethernet communication module being configured to implement Ethernet initialization and provide an Ethernet input / output interface; the remote debugging module at least comprising a remote debugging submodule;
[0005] The method comprises the following steps:
[0006] The embedded device periodically receives control instructions transmitted by Ethernet and sent by the host machine, and determines the instruction type of the control instruction; the instruction type includes a debugging instruction and a file transfer instruction;
[0007] If the instruction type of the control instruction is the debugging instruction, triggering the embedded device to execute a corresponding debugging behavior through the remote debugging submodule to generate debugging data;
[0008] The debugging data is placed into a debugging queue according to a specific priority, the data length of the debugging data in the debugging queue is obtained, and the CPU idle state is periodically detected to obtain the idle time length;
[0009] Acquire a transmission rate, and obtain a first preset transmission duration according to the transmission rate and the data length; the transmission rate is a rate at which the debugging data is transmitted to the host machine through the Ethernet communication module;
[0010] If the first preset transmission duration is less than or equal to the idle duration, the debugging data is transmitted to the host machine via Ethernet.
[0011] According to the technical solution provided in the embodiment of the present application, after obtaining the first preset transmission duration according to the transmission rate and the data length, the following steps are also included:
[0012] If the first preset transmission duration is greater than the idle duration, processing part of the debugging data in the debugging queue, the part of the debugging data having a data length less than the data length;
[0013] The data in the debugging queue except the partial debugging data is the remaining debugging data, and the data length of the remaining debugging data is the remaining data length;
[0014] Obtaining a second preset transmission duration according to the remaining data length and the transmission rate;
[0015] If the second preset transmission duration is less than or equal to the remaining idle time of the CPU, the part of the debugging information is transmitted to the host machine through the remote debugging submodule.
[0016] According to the technical solution provided in the embodiment of the present application, if the first preset transmission duration is greater than the idle duration, processing part of the debugging data in the debugging queue specifically includes the following steps:
[0017] If the first preset transmission duration is greater than the idle duration, the debugging data in the debugging queue having half the data length is processed.
[0018] According to the technical solution provided in the embodiment of the present application, after the embedded device periodically receives the control instruction transmitted by Ethernet and sent by the host machine, the following steps are also included:
[0019] Identify the header of the data packet of the control instruction, and read the termination byte data based on the header according to the length of the data packet, wherein the termination byte data is the last byte data starting with the header and having the length of the data packet;
[0020] According to the termination byte data, determining whether the data of the data packet of the control instruction is complete;
[0021] If the data of the data packet is complete, verifying the data content of the data packet;
[0022] Determining the instruction type of the control instruction specifically includes the following steps:
[0023] If the result of the data content verification is normal, the instruction type of the control instruction is determined.
[0024] According to the technical solution provided in the embodiment of the present application, the data content verification of the data packet specifically includes the following steps:
[0025] An XOR sum is performed on a specific byte range, and if the result of the XOR sum is equal to the check bit, it indicates that the result of the data content check is normal, otherwise the result of the data content check is abnormal.
[0026] According to the technical solution provided by the embodiment of the present application, the remote debugging module further includes a file check submodule, and the file transfer instruction is for the host machine to send a specific file to the embedded device;
[0027] After determining the instruction type of the control instruction, the following steps are also included:
[0028] If the instruction type of the control instruction is the file transfer instruction, downloading and verifying the specific file through the file verification submodule;
[0029] If the verification result is normal, the specific file is transferred to the designated storage location.
[0030] According to the technical solution provided in the embodiment of the present application, after the verification result is normal, the following steps are also included:
[0031] Feedback confirmation information to the host machine, wherein the confirmation information is used to inform the host machine that the specific file is successfully received and verified.
[0032] According to the technical solution provided in the embodiment of the present application, the transferring of the specific file to the designated storage location specifically includes the following steps:
[0033] Determine the file type of the specific file, where the file type at least includes first transmission and repeated transmission;
[0034] If the file type of the specific file is the first transmission, a buffer area is created according to the total number of data groups of the specific file, and the size of the buffer area is the product of the data content length and the total number of groups;
[0035] According to the group sequence number of the data of the specific file, the data content of the specific file is placed into the buffer of the corresponding group sequence number;
[0036] If the total number of data groups in the buffer matches the update count, and the update flags corresponding to each group of data are set to be valid, the data in the buffer is stored in the flash location of the specified path for storage.
[0037] According to the technical solution provided in the embodiment of the present application, after storing the data in the buffer to the flash location of the specified path for storage, the following steps are also included:
[0038] Destroys the buffer to free up memory resources.
[0039] According to the technical solution provided in the embodiment of the present application, after determining the file type of the specific file, the following steps are also included:
[0040] If the file type of the specific file is repeated transmission, the data content of the specific file is directly placed into a buffer corresponding to the group number according to the group number of the data of the specific file.
[0041] Compared with the prior art, the beneficial effect of the present application is that the present application adopts a method of periodically receiving Ethernet control commands to avoid frequent interruption of tasks for debugging. When there is no control command, the embedded device can execute the task normally without being disturbed by the debugging operation, thereby ensuring the real-time requirements of the task. In addition, the remote debugging processing submodule periodically queries the idle state of the current CPU of the system, making full use of the idle time of the CPU. When the first preset transmission duration is less than or equal to the idle duration, the debugging data will be transmitted, thereby minimizing the impact of data transmission on the ongoing task and effectively reducing the interference with the real-time performance of the task. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 A flowchart of the steps of the remote debugging system method for an embedded device provided in an embodiment of the present application;
[0043] Figure 2 A schematic diagram of the structure of a remote debugging system for an embedded device provided in an embodiment of the present application;
[0044] Figure 3 A schematic diagram of the structure of the data packet content provided in an embodiment of the present application.
[0045] The text annotations in the figure represent:
[0046] 1. Embedded device; 2. Host machine; 3. Airborne device. DETAILED DESCRIPTION
[0047] The present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It is also necessary to explain that, for ease of description, only the parts related to the invention are shown in the accompanying drawings.
[0048] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0049] Example 1
[0050] As mentioned in the background technology, in view of the problems in the prior art, this application proposes a remote debugging method for an embedded device, which is based on a remote debugging system for an embedded device. Figure 2 As shown, the embedded device 1 is interconnected with the host machine 2 via Ethernet, and the embedded device 1 includes an Ethernet communication module and a remote debugging module. The Ethernet communication module is configured to implement Ethernet initialization and provide an Ethernet input / output interface; the remote debugging module includes at least a remote debugging sub-module; the embedded device 1 is also interconnected with other onboard devices 3 via an onboard bus.
[0051] The method comprises the following steps:
[0052] S1, the embedded device 1 periodically receives a control instruction transmitted by Ethernet and sent by the host machine 2, and determines the instruction type of the control instruction; the instruction type includes a debugging instruction and a file transfer instruction;
[0053] Furthermore, after the periodic reception of the control instruction transmitted by the Ethernet and sent by the host machine 2, the following steps are also included:
[0054] Identify the header of the data packet of the control instruction, and read the termination byte data based on the header according to the length of the data packet, wherein the termination byte data is the last byte data starting with the header and having the length of the data packet;
[0055] According to the termination byte data, determining whether the data of the data packet of the control instruction is complete;
[0056] If the data of the data packet is complete, verifying the data content of the data packet;
[0057] Furthermore, the data content verification of the data packet specifically includes the following steps:
[0058] An XOR sum is performed on a specific byte range, and if the result of the XOR sum is equal to the check bit, it indicates that the result of the data content check is normal, otherwise the result of the data content check is abnormal.
[0059] Further, the determining the instruction type of the control instruction specifically comprises the following steps:
[0060] If the result of the data content verification is normal, the instruction type of the control instruction is determined.
[0061] Specifically, please refer to Figure 3 As shown, the content of the data packet includes a packet header, a packet length, a data type, a total number of data groups, a group sequence number, data content, a verification bit and a packet tail. The process of verifying the control instruction is: first, the packet header is identified, and len bytes of data starting from the packet length are read according to the packet length len, that is, len=1+2+2+n+1+1, and the data of the last byte is verified. If the last byte of data read according to the packet length len is 0xbb55, the packet data is considered to be complete data, otherwise the packet data is not processed; then the data content is verified, and the 0th to n-1th bytes are XORed and summed according to the received data content. If the result is equal to the check bit, the data is considered to be correct and content parsing can be performed, otherwise the packet data is not processed.
[0062] Specifically, the Ethernet communication module of the embedded device 1 monitors the data transmitted by the Ethernet at a fixed time interval (for example, every 100 milliseconds). Once data transmission is detected, the data validity verification is first performed to verify whether the format of the data header, packet tail, etc. is correct, and whether the data source is an authorized host machine 2. If the data verification passes, the data content is parsed to determine whether the instruction type of the control instruction is a debugging instruction. If it is ordinary non-debugging data (such as a device status query instruction, etc.), it is processed according to the corresponding business logic and the result is returned to the host machine 2.
[0063] S2. If the instruction type of the control instruction is the debugging instruction, triggering the embedded device to execute a corresponding debugging behavior through the remote debugging submodule to generate debugging data;
[0064] S3, arranging the debugging data into a debugging queue according to a specific priority, obtaining the data length of the debugging data in the debugging queue, and periodically detecting the CPU idle state to obtain the idle duration;
[0065] Exemplarily, the debugging instructions with a specific priority level related to the core functions of the device have a higher priority level and are placed at the front of the queue. After being placed in the queue, the data length of the debugging data is calculated immediately to calculate the transmission duration. The CPU's operating status is detected every 50 milliseconds, and the length of time the current CPU is in an idle state is counted. By reading the system's CPU occupancy-related parameters, when the occupancy rate is 0% or close to 0%, the CPU is considered to be in an idle state, and the idle time that the CPU will be idle is predicted based on the results of periodic detection of the CPU's idle state.
[0066] S4, obtaining a transmission rate, and obtaining a first preset transmission duration according to the transmission rate and the data length; the transmission rate is a rate at which the debugging data is transmitted to the host machine 2 through the Ethernet communication module;
[0067] Specifically, if the embedded device 1 receives a control instruction transmitted by the host machine 2 and the instruction type is a debugging instruction, it executes the corresponding debugging behavior and generates debugging data. This debugging data needs to be transmitted back to the host machine 2 for analysis. At this time, the rate at which the debugging data is transmitted to the host machine 2 under the current Ethernet connection is obtained by handshake communication with the host machine 2 or according to a pre-set test mechanism. Exemplarily, this rate can be obtained by sending a test data packet and recording the transmission time to calculate the average value. According to the obtained transmission rate and the data length of the obtained debugging data, the formula: transmission time = data length / transmission rate is used to calculate the first preset transmission time. Exemplarily, if the data length is 1000 bytes and the transmission rate is 100 bytes / second, then the first preset transmission time is 10 seconds.
[0068] S5. If the first preset transmission duration is less than or equal to the idle duration, the debugging data is transmitted to the host machine 2 via Ethernet.
[0069] Specifically, if the first preset transmission duration is less than or equal to the idle duration, the remote debugging submodule starts to process the debugging data, and the obtained debugging data is transmitted to the host machine 2 in sequence according to the debugging data sequence in the debugging queue through the Ethernet communication module in accordance with the established communication protocol, for analysis and processing by developers or debuggers. If the first preset transmission duration is greater than the idle duration, continue to wait for the CPU to be idle or adjust the priority of data transmission according to the preset strategy, etc., until the transmission conditions are met.
[0070] In a preferred embodiment, after obtaining the first preset transmission duration according to the transmission rate and the data length, the method further includes the following steps:
[0071] If the first preset transmission duration is greater than the idle duration, processing part of the debugging data in the debugging queue, the part of the debugging data having a data length less than the data length;
[0072] The data in the debugging queue except the partial debugging data is the remaining debugging data, and the data length of the remaining debugging data is the remaining data length;
[0073] Obtaining a second preset transmission duration according to the remaining data length and the transmission rate;
[0074] Specifically, when the total data length and the selected part of the debugging data length are known, the remaining data length is obtained by a simple subtraction operation. Then, according to the transmission rate and the remaining data length, the second preset transmission duration is calculated in the same way as the first preset transmission duration.
[0075] If the second preset transmission duration is less than or equal to the remaining idle time of the CPU, the part of the debugging information is transmitted to the host machine 2 through the remote debugging submodule.
[0076] Specifically, the operating status of the CPU can be continuously monitored, and the time the CPU is occupied can be recorded during the processing of some debugging data, so as to calculate the remaining idle time.
[0077] Further, if the first preset transmission duration is greater than the idle duration, processing part of the debugging data in the debugging queue specifically includes the following steps:
[0078] If the first preset transmission duration is greater than the idle duration, the debugging data in the debugging queue having half the data length is processed.
[0079] Specifically, when it is detected that the first preset transmission duration is greater than the CPU idle duration, it is first necessary to select part of the debugging data from the debugging queue for processing. According to the rules, debugging data with half the data length is selected. This means that the data in the debugging queue needs to be segmented. Exemplarily, starting from the head of the queue, the data volume is calculated to reach the position of half the total data length. If the total data length is 2000 bytes, then the first 1000 bytes of data are selected as part of the debugging data. For the structure of the debugging data, if it is a queue composed of data packets in a fixed format, half of them are selected according to the number of data packets; if it is a continuous data stream, it is segmented according to the number of bytes.
[0080] Furthermore, if the second preset transmission duration is greater than the remaining idle time of the CPU, the processing is suspended and the CPU continues to wait for idleness, or according to the priority rules set by the system, it is decided whether to split the remaining debugging data again for processing, and the above process is repeated until the transmission and debugging conditions are met.
[0081] In a preferred embodiment, the remote debugging module further includes a file check submodule, and the file transfer instruction is for the host machine 2 to send a specific file to the embedded device 1;
[0082] After determining the instruction type of the control instruction, the following steps are also included:
[0083] If the instruction type of the control instruction is the file transfer instruction, downloading and verifying the specific file through the file verification submodule;
[0084] If the verification result is normal, the specific file is transferred to the designated storage location.
[0085] In a preferred embodiment, after the verification result is normal, the method further comprises the following steps:
[0086] Feedback confirmation information to the host machine 2, wherein the confirmation information is used to inform the host machine 2 that the specific file is successfully received and verified.
[0087] Specifically, feeding back confirmation information to the host machine 2 can facilitate guiding the host machine 2 to perform subsequent operations.
[0088] In a preferred embodiment, the transferring of the specific file to a designated storage location specifically comprises the following steps:
[0089] Determine the file type of the specific file, where the file type at least includes first transmission and repeated transmission;
[0090] If the file type of the specific file is the first transmission, a buffer area is created according to the total number of data groups of the specific file, and the size of the buffer area is the product of the data content length and the total number of groups;
[0091] According to the group sequence number of the data of the specific file, the data content of the specific file is placed into the buffer of the corresponding group sequence number;
[0092] If the total number of data groups in the buffer matches the update count, and the update flags corresponding to each group of data are set to be valid, the data in the buffer is stored in the flash location of the specified path for storage.
[0093] Specifically, the update count is a counter that records the number of written data groups during the data writing process. When the total number of data groups in the buffer matches the update count, and the update flag corresponding to each group of data is set to valid, it indicates that all data blocks have been correctly written into the buffer and meet the storage conditions.
[0094] In a preferred embodiment, after storing the data in the buffer to the flash location of the specified path for storage, the following steps are also included:
[0095] Destroys the buffer to free up memory resources.
[0096] Specifically, after the data in the buffer is successfully stored in the flash location of the specified path, in order to release memory resources, the embedded device 1 starts the memory recycling mechanism. The memory address space used by the cache area is traversed, and the relevant memory is marked as recyclable. The operating system or memory management module is notified to recycle this part of the memory resources so that other subsequent tasks or data processing can use this part of the memory, thereby improving the memory utilization efficiency and overall performance of the system. At the same time, the relevant cache management variables are reset so that the cache area can be re-created and used the next time the file is transferred.
[0097] In a preferred embodiment, after determining the file type of the specific file, the following steps are further included:
[0098] If the file type of the specific file is repeated transmission, the data content of the specific file is directly placed into a buffer corresponding to the group number according to the group number of the data of the specific file.
[0099] Specifically, when the file type is repeated transmission, since some data has been stored in the buffer or the storage medium of the device, according to the group number of the data of the specific file, the newly received data content is directly placed in the buffer of the corresponding group number, overwriting the original data block that may be incomplete or erroneous. During the writing process, the data integrity and correctness are also checked to ensure that the data is accurately written into the buffer.
[0100] This article uses specific examples to illustrate the principles and implementation methods of this application. The description of the above embodiments is only used to help understand the method and its core ideas of this application. The above is only the preferred implementation method of this application. It should be pointed out that due to the limitations of textual expression and the objective existence of infinite specific structures, ordinary technicians in this technical field can make several improvements, modifications or changes without departing from the principles of the present invention, and can also combine the above technical features in an appropriate manner; these improvements, modifications, changes or combinations, or the direct application of the inventive concept and technical solution to other occasions without improvement, should be regarded as the scope of protection of this application.
Claims
1. A remote debugging method for an embedded device, characterized in that: The embedded device (1) is interconnected with a host computer (2) via Ethernet, the embedded device (1) comprising an Ethernet communication module and a remote debugging module, the Ethernet communication module being configured to implement Ethernet initialization and provide an Ethernet input / output interface; The remote debugging module at least includes a remote debugging submodule; The method comprises the following steps: The embedded device (1) periodically receives control instructions transmitted by Ethernet and sent by the host machine (2), and determines the instruction type of the control instruction; the instruction type includes a debugging instruction and a file transfer instruction; If the instruction type of the control instruction is the debugging instruction, triggering the embedded device to execute a corresponding debugging behavior through the remote debugging submodule to generate debugging data; The debugging data is placed into a debugging queue according to a specific priority, the data length of the debugging data in the debugging queue is obtained, and the CPU idle state is periodically detected to obtain the idle time length; Acquire a transmission rate, and obtain a first preset transmission duration according to the transmission rate and the data length; the transmission rate is a rate at which the debugging data is transmitted to the host machine (2) through the Ethernet communication module; If the first preset transmission duration is less than or equal to the idle duration, the debugging data is transmitted to the host machine (2) via Ethernet.
2. The remote debugging method for an embedded device according to claim 1, characterized in that: After obtaining the first preset transmission duration according to the transmission rate and the data length, the following steps are also included: If the first preset transmission duration is greater than the idle duration, processing part of the debugging data in the debugging queue, wherein the partial data length of the part of the debugging data is less than the data length; The data in the debugging queue except the partial debugging data is the remaining debugging data, and the data length of the remaining debugging data is the remaining data length; Obtaining a second preset transmission duration according to the remaining data length and the transmission rate; If the second preset transmission duration is less than or equal to the remaining idle time of the CPU, the part of the debugging information is transmitted to the host machine (2) through the remote debugging submodule.
3. The remote debugging method for an embedded device according to claim 2, characterized in that: If the first preset transmission duration is greater than the idle duration, processing part of the debugging data in the debugging queue specifically includes the following steps: If the first preset transmission duration is greater than the idle duration, the debugging data in the debugging queue having half the data length is processed.
4. The remote debugging method for an embedded device according to claim 1, characterized in that: After the embedded device periodically receives the control instruction transmitted by the Ethernet and sent by the host machine (2), the following steps are also included: Identify the header of the data packet of the control instruction, and read the termination byte data based on the header according to the length of the data packet, wherein the termination byte data is the last byte data starting with the header and having the length of the data packet; According to the termination byte data, determining whether the data of the data packet of the control instruction is complete; If the data of the data packet is complete, verifying the data content of the data packet; Determining the instruction type of the control instruction specifically includes the following steps: If the result of the data content verification is normal, the instruction type of the control instruction is determined.
5. The method for remote debugging of an embedded device according to claim 4, characterized in that: The data content verification of the data packet specifically comprises the following steps: An XOR sum is performed on a specific byte range, and if the result of the XOR sum is equal to the check bit, it indicates that the result of the data content check is normal, otherwise the result of the data content check is abnormal.
6. The method for remote debugging of an embedded device according to claim 1, characterized in that: The remote debugging module also includes a file check submodule, and the file transfer instruction is for the host machine (2) to send a specific file to the embedded device (1); After determining the instruction type of the control instruction, the following steps are also included: If the instruction type of the control instruction is the file transfer instruction, downloading and verifying the specific file through the file verification submodule; If the verification result is normal, the specific file is transferred to the designated storage location.
7. The method for remote debugging of an embedded device according to claim 6, characterized in that: After the verification result is normal, the following steps are also included: Feedback confirmation information to the host machine (2), wherein the confirmation information is used to inform the host machine (2) that the specific file has been successfully received and verified.
8. The method for remote debugging of an embedded device according to claim 6, characterized in that: The transferring of the specific file to the designated storage location specifically comprises the following steps: Determine the file type of the specific file, where the file type at least includes first transmission and repeated transmission; If the file type of the specific file is the first transmission, a buffer area is created according to the total number of data groups of the specific file, and the size of the buffer area is the product of the data content length and the total number of groups; According to the group sequence number of the data of the specific file, the data content of the specific file is placed into the buffer of the corresponding group sequence number; If the total number of data groups in the buffer matches the update count, and the update flags corresponding to each group of data are set to be valid, the data in the buffer is stored in the flash location of the specified path for storage.
9. The method for remote debugging of an embedded device according to claim 8, characterized in that: After storing the data in the buffer to the flash location of the specified path for storage, the following steps are also included: Destroys the buffer to free up memory resources.
10. The method for remote debugging of an embedded device according to claim 8, characterized in that: After determining the file type of the specific file, the following steps are also included: If the file type of the specific file is repeated transmission, the data content of the specific file is directly placed into a buffer corresponding to the group number according to the group number of the data of the specific file.