[go: up one dir, main page]

CN110457215B - Cross-platform MCU debugging method - Google Patents

Cross-platform MCU debugging method Download PDF

Info

Publication number
CN110457215B
CN110457215B CN201910701812.1A CN201910701812A CN110457215B CN 110457215 B CN110457215 B CN 110457215B CN 201910701812 A CN201910701812 A CN 201910701812A CN 110457215 B CN110457215 B CN 110457215B
Authority
CN
China
Prior art keywords
module
debugging
instruction
mcu
log
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910701812.1A
Other languages
Chinese (zh)
Other versions
CN110457215A (en
Inventor
肖文平
王子祥
陈柱
张航
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Heqian Automotive Technology (Shenzhen) Co.,Ltd.
Original Assignee
Shanghai Hinge Electronic Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Hinge Electronic Technologies Co Ltd filed Critical Shanghai Hinge Electronic Technologies Co Ltd
Priority to CN201910701812.1A priority Critical patent/CN110457215B/en
Publication of CN110457215A publication Critical patent/CN110457215A/en
Application granted granted Critical
Publication of CN110457215B publication Critical patent/CN110457215B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/34Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
    • G06F11/3466Performance evaluation by tracing or monitoring
    • G06F11/3476Data logging
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/362Debugging of software
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/36Prevention of errors by analysis, debugging or testing of software
    • G06F11/362Debugging of software
    • G06F11/3648Debugging of software using additional hardware
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/12Digital output to print unit, e.g. line printer, chain printer
    • G06F3/1201Dedicated interfaces to print systems
    • G06F3/1223Dedicated interfaces to print systems specifically adapted to use a particular technique
    • G06F3/1237Print job management
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F8/00Arrangements for software engineering
    • G06F8/60Software deployment
    • G06F8/65Updates

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Hardware Design (AREA)
  • Quality & Reliability (AREA)
  • Software Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Human Computer Interaction (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The invention provides a cross-platform MCU debugging method, which comprises an upper computer and an MCU and is characterized by at least comprising the following steps: the upper computer starts a debugging instruction module according to debugging requirements to send a debugging instruction to the MCU, and the MCU starts a corresponding debugging functional module to debug the MCU after receiving the debugging instruction; the debugging instruction module is configured to call a corresponding debugging instruction according to debugging requirements to debug the MCU; and the debugging functional module is configured to correspond to the debugging instruction module and start the corresponding debugging functional module to debug the MCU according to the debugging instruction transmitted by the debugging instruction module. Compared with the existing MCU debugging method, the method has the advantages that the MCU and the upper computer are directly adopted for assembling and debugging, a special debugging tool is not adopted as an intermediate medium, the debugging cost is reduced, and the debugging method is flexible and variable.

Description

一种跨平台的MCU调试方法A Cross-platform MCU Debugging Method

技术领域technical field

本发明涉及微处理控制器(Microcontroller Unit,MCU)领域,尤其涉及一种对汽车MCU开发过程中或已开发完成的MCU故障进行调试的方法。The invention relates to the field of microprocessor controllers (Microcontroller Unit, MCU), in particular to a method for debugging the faults of the MCU in the development process of the automobile MCU or which has been developed.

背景技术Background technique

随着汽车的普及,越来越多的汽车进入千家万户,现在信息技术的飞速发展使得人们对汽车智能化提出了更高的要求,希望智能化汽车能够给人们的实用带来便利。智能车辆是一个集环境感知、规划决策、多等级辅助驾驶等功能于一体的综合系统,它集中运用了计算机、现代传感、信息融合、通讯、人工智能及自动控制等技术,是典型的高新技术综合体。目前对智能车辆的研究主要致力于提高汽车的安全性、舒适性,以及提供优良的人车交互界面。近年来,智能车辆己经成为世界车辆工程领域研究的热点和汽车工业增长的新动力,很多发达国家都将其纳入到各自重点发展的智能交通系统当中。智能汽车的发展对车身控制系统各个方面提出了严格的要求,包括软件和硬件,而软件和硬件的处理都离不开MCU。而功能强大的MCU开发周期较长,在开发过程中需要不断的对MCU进行调试,传统的调试方法如图1所示,其包括上位机、调试工具、MCU,MCU调试需要专门的调试工具,其调试过程中,通过上位机控制调试工具进而对MCU进行调试,一方面,需要专门的调试工具,而调试工具一旦完成,其很难进行更改,只能应用于特定型号的MCU调试,不够灵活,具有较大的局限性。只能获取到MCU的内部信息,比如寄存器,变量,内存区域的数值。但现阶段的MCU集成较多的功能,仅知道寄存器,变量,内存区域的数值是远远不够的,从这几个数据无法获取系统的运行状态,也无法获取系统运行流程和各模块之间的相互依赖关系。With the popularization of automobiles, more and more automobiles have entered thousands of households. Now the rapid development of information technology has made people put forward higher requirements for intelligent automobiles. It is hoped that intelligent automobiles can bring convenience to people's practicality. An intelligent vehicle is a comprehensive system that integrates functions such as environmental perception, planning and decision-making, and multi-level assisted driving. It uses technologies such as computers, modern sensing, information fusion, communication, artificial intelligence, and automatic control. technology complex. At present, the research on intelligent vehicles is mainly devoted to improving the safety and comfort of automobiles, and providing an excellent human-vehicle interaction interface. In recent years, intelligent vehicles have become a research hotspot in the field of vehicle engineering in the world and a new driving force for the growth of the automobile industry. Many developed countries have incorporated them into their respective intelligent transportation systems. The development of smart cars puts forward strict requirements on all aspects of the body control system, including software and hardware, and the processing of software and hardware cannot be separated from the MCU. However, the powerful MCU has a long development cycle, and the MCU needs to be continuously debugged during the development process. The traditional debugging method is shown in Figure 1, which includes the host computer, debugging tools, and MCU. MCU debugging requires special debugging tools. In the debugging process, the host computer controls the debugging tool to debug the MCU. On the one hand, a special debugging tool is required. Once the debugging tool is completed, it is difficult to change it. It can only be used for debugging of a specific type of MCU, which is not flexible enough. , has great limitations. Only the internal information of the MCU can be obtained, such as the values of registers, variables, and memory areas. However, the current MCU integrates many functions. It is far from enough to only know the values of registers, variables, and memory areas. From these data, it is impossible to obtain the operating status of the system, and it is also impossible to obtain the operating process of the system and the relationship between each module. of interdependence.

为了方便开发人员的调试,及时对MCU开发过程中的各个功能模块以及与MCU相关的相匹配的功能进行调试,需要开发一种新的MCU调试装置对MCU进行调试。In order to facilitate the debugging of developers and timely debug each functional module in the MCU development process and the matching functions related to the MCU, it is necessary to develop a new MCU debugging device to debug the MCU.

发明内容Contents of the invention

基于现有技术中存在的缺陷,本发明要解决的技术问题在于一种跨平台的MCU调试方法,应用于包括上位机和MCU的系统调试,其特征在于,至少包括以下步骤:Based on the defects in the prior art, the technical problem to be solved in the present invention is a cross-platform MCU debugging method, which is applied to system debugging including a host computer and an MCU, and is characterized in that it at least includes the following steps:

上位机根据调试需求启动调试指令模块发送调试指令给MCU,MCU接收到调试指令后启动相应的调试功能模块对MCU进行调试;The upper computer starts the debugging command module according to the debugging requirements and sends the debugging command to the MCU, and the MCU starts the corresponding debugging function module to debug the MCU after receiving the debugging command;

调试指令模块,被配置为根据调试需求调用相应的调试指令程序对MCU进行调试;The debugging instruction module is configured to call the corresponding debugging instruction program to debug the MCU according to the debugging requirements;

调试功能模块,被配置为与调试指令模块相对应并根据调试指令模块下发的调试指令启动相应的特定功能模块对MCU进行调试。The debugging function module is configured to correspond to the debugging instruction module and start a corresponding specific function module to debug the MCU according to the debugging instruction issued by the debugging instruction module.

本发明提供一种跨平台的MCU调试方法,进一步地,还包括:MCU调试产生的数据发送给上位机进行显示,所述MCU调试产生的数据包括日志,日志根据类型划分为多个日志等级;在对MCU调试过程中,将需要输出的数据暂存于存储器中,等待系统空闲时候对外输出;或包括当发现MCU中调试功能模块没有内置预设的功能模块或根据调试结果,需要增加额外的功能模块,此时通过上位机直接将含有所需的功能模块写入MCU中。The present invention provides a cross-platform MCU debugging method, further comprising: the data generated by MCU debugging is sent to the host computer for display, the data generated by the MCU debugging includes logs, and the logs are divided into multiple log levels according to types; In the process of debugging the MCU, temporarily store the data that needs to be output in the memory, and wait for the external output when the system is idle; or include when it is found that the debugging function module in the MCU does not have a built-in preset function module or according to the debugging results, it is necessary to add additional Functional modules, at this time, directly write the required functional modules into the MCU through the host computer.

本发明提供一种跨平台的MCU调试方法,进一步地,所述调试指令发给MCU之前需要将调试指令进行封装,所述MCU需要对接收到的封装数据包进行解包后获得调试指令;The present invention provides a cross-platform MCU debugging method. Further, the debugging instruction needs to be encapsulated before being sent to the MCU, and the MCU needs to unpack the received packaged data packet to obtain the debugging instruction;

所述MCU调试产生的数据发送给上位机之前需要将数据进行封装,所述上位机需要对接收到的封装数据包进行解包后获得调试产生的数据包。The data generated by the MCU debugging needs to be encapsulated before being sent to the upper computer, and the upper computer needs to unpack the received encapsulated data packets to obtain the data packets generated by debugging.

本发明提供一种跨平台的MCU调试方法,进一步地,所述数据进行封装至少包括以下步骤:The present invention provides a cross-platform MCU debugging method, further, said data encapsulation at least includes the following steps:

步骤S701,获取需要封包的有效载荷(payload)并从中获取有效载荷的地址、长度、数据包类型;Step S701, obtaining the payload (payload) that needs to be packaged and obtaining the address, length, and data packet type of the payload therefrom;

步骤S702,判断地址是否有效,若地址无效,则执行步骤S707,结束封包过程;若地址有效,则执行步骤S703;Step S702, judging whether the address is valid, if the address is invalid, execute step S707, and end the packaging process; if the address is valid, execute step S703;

步骤S703,判断有效载荷命令类型,若有效载荷的命令类型有效,则执行步骤S704,若有效载荷的命令类型无效,则执行步骤S707,结束封包过程;Step S703, judging the command type of the payload, if the command type of the payload is valid, then perform step S704, if the command type of the payload is invalid, then perform step S707, and end the packaging process;

步骤S704,判断有效载荷的数据长度是否有效,若数据长度无效,则执行步骤S707,结束封包过程,若数据长度有效,则执行步骤S705;Step S704, judging whether the data length of the payload is valid, if the data length is invalid, then execute step S707, end the packaging process, if the data length is valid, then execute step S705;

步骤S705,给有效载荷进行赋值;Step S705, assigning a value to the payload;

步骤S706,将封包好的数据存入待发送的数据区;Step S706, storing the packaged data into the data area to be sent;

步骤S707,结束封包过程。Step S707, end the packaging process.

本发明提供一种跨平台的MCU调试方法,进一步地,所述对接收到的封装数据包进行解包包括以下步骤:The present invention provides a cross-platform MCU debugging method, further, said unpacking the received encapsulated data packet includes the following steps:

步骤S800,检测帧字头是否包含高字节,若含有高字节,则执行步骤S801,若没有高字节,回到步骤S800,对下一帧进行检测;Step S800, detecting whether the frame header contains a high byte, if it contains a high byte, then execute step S801, if there is no high byte, return to step S800, and detect the next frame;

步骤S801,检测帧字头是否包含低字节,若包含低字节,则执行步骤S802;若不包含低字节,则回到步骤S800,对下一帧数据进行检测;Step S801, detecting whether the frame header contains a low byte, if it contains a low byte, then execute step S802; if it does not contain a low byte, then return to step S800, and detect the next frame data;

步骤S802,获取数据包的长度;Step S802, obtaining the length of the data packet;

步骤S803,解析包类型,判断数据包是属于哪一类;Step S803, analyzing the packet type to determine which category the data packet belongs to;

步骤S804,获取解包后有效载荷;Step S804, obtaining the unpacked payload;

本发明提供一种跨平台的MCU调试方法,进一步地,所述调试指令模块至少包括日志打印指令模块、日志等级过滤指令模块、进程交互指令模块、固件获取指令模块、内容写入指令模块、内容读取指令模块、在线升级指令模块、工具自适应识别指令模块中的一种或多种;The present invention provides a cross-platform MCU debugging method, further, the debugging instruction module at least includes a log printing instruction module, a log level filtering instruction module, a process interaction instruction module, a firmware acquisition instruction module, a content writing instruction module, a content One or more of the reading instruction module, the online upgrade instruction module, and the tool adaptive identification instruction module;

调试功能模块至少包括日志打印模块、日志等级过滤模块、进程交互模块、固件获取模块、内容写入模块、内容读取模块、在线升级模块、工具自适应识别模块中的一种或多种The debugging function module includes at least one or more of the log printing module, log level filtering module, process interaction module, firmware acquisition module, content writing module, content reading module, online upgrade module, and tool adaptive identification module

进一步地,日志打印指令模块,被配置为根据调试需求启动日志打印指令并下发给MCU中的日志打印模块;Further, the log printing instruction module is configured to start the log printing instruction according to the debugging requirement and send it to the log printing module in the MCU;

日志等级过滤指令模块,被配置为根据调试需求启动日志等级过滤指令并下发给MCU中的日志等级过滤模块;The log level filtering command module is configured to start the log level filtering command according to the debugging requirements and send it to the log level filtering module in the MCU;

进程交互指令模块,被配置为根据调试需求启动各个进程之间的进程交互指令并下发给MCU的进程交互模块;The process interaction instruction module is configured to start the process interaction instructions between various processes according to the debugging requirements and send them to the process interaction module of the MCU;

固件获取指令模块,被配置为根据调试需求启动获取固件的指令下发给MCU中的固件获取模块;The firmware acquisition instruction module is configured to start and issue the instruction to acquire firmware to the firmware acquisition module in the MCU according to the debugging requirements;

内容写入指令模块,被配置为根据调试需求启动内容写入的指令下发给MCU中的内容写入模块;The content writing command module is configured to send the content writing command to the content writing module in the MCU according to the debugging requirements to start the content writing;

内容读取指令模块,被配置为根据调试需求启动内容读取的指令下发给MCU中的内容读取模块;The content reading instruction module is configured to issue an instruction to start content reading according to the debugging requirements to the content reading module in the MCU;

在线升级指令模块,被配置为根据调试需求启动在线升级的指令下发给MCU中的在线升级模块。The online upgrade instruction module is configured to issue an instruction to start the online upgrade to the online upgrade module in the MCU according to the debugging requirement.

工具自适应识别指令模块,被配置为根据需求启动工具自适应指令并下发给MCU中的工具自适应识别模块;A tool adaptive recognition command module configured to start a tool adaptive command according to requirements and send it to the tool adaptive recognition module in the MCU;

应用层指令模块,被配置为根据需求启动应用层指令下发给MCU中的应用层功能定制模块。The application layer instruction module is configured to start the application layer instruction and send it to the application layer function customization module in the MCU according to requirements.

本发明提供一种跨平台的MCU调试方法,进一步地,所述调试功能模块至少包括日志打印模块、日志等级过滤模块、进程交互模块、固件获取模块、内容写入模块、内容读取模块、在线升级模块、工具自适应识别模块中的一种或多种;The present invention provides a cross-platform MCU debugging method. Further, the debugging function module at least includes a log printing module, a log level filtering module, a process interaction module, a firmware acquisition module, a content writing module, a content reading module, an online One or more of upgrade modules and tool adaptive identification modules;

进一步地,日志打印模块,被配置为实现日志打印,其根据日志打印指令模块的指令将日志(log)消息通过进行打印输出,用来告知开发人员程序的运行状态;Further, the log printing module is configured to realize log printing, which prints out the log (log) message according to the instruction of the log printing instruction module, and is used to inform the developer of the running status of the program;

日志等级过滤模块,被配置为实现日志等级过滤,其根据日志等级过滤指令模块的指令,有选择的实现动态过滤不同等级的日志能力;The log level filtering module is configured to implement log level filtering, and selectively implements the ability to dynamically filter logs of different levels according to the instructions of the log level filtering instruction module;

进程交互模块,被配置为实时记录多个任务之间的信息传递,其根据进程交互指令启动多个任务之间的信息传递记录;The process interaction module is configured to record the information transmission between multiple tasks in real time, and it starts the information transmission recording between multiple tasks according to the process interaction instruction;

固件获取模块,被配置为获取固件的信息,其根据固件获取指令获取固件信息;A firmware acquisition module configured to acquire firmware information, which acquires firmware information according to a firmware acquisition instruction;

内容写入模块,被配置为对接收到需要写入存储器的信息进行写入,其根据内容写入指令将相应的数据写入MCU的存储器中;The content writing module is configured to write the received information that needs to be written into the memory, and writes the corresponding data into the memory of the MCU according to the content writing instruction;

内容读取模块,被配置为对需要读取的信息进行读取,其根据内容读取指令对相应的内容进行读取;The content reading module is configured to read the information to be read, and reads the corresponding content according to the content reading instruction;

在线升级模块,被配置为对MCU进行升级,其根据接收到来自上位机的升级指令对MCU进行升级;The online upgrade module is configured to upgrade the MCU, which upgrades the MCU according to the upgrade instruction received from the host computer;

工具自适应识别模块,被配置为根据上位机的工具自适应识别指令对上位机是否具有配套的串口工具进行识别;The tool adaptive identification module is configured to identify whether the upper computer has a supporting serial port tool according to the tool adaptive identification instruction of the upper computer;

应用层功能定制模块,被配置为根据上位机的应用层指令对应用程序的功能进行定制。The application layer function customization module is configured to customize the functions of the application program according to the application layer instructions of the upper computer.

本发明提供一种跨平台的MCU调试方法,进一步地,调试过程中的日志是通过日志打印指令模块通过下发指令控制日志打印模块进行打印的,日志打印包括以下步骤:The present invention provides a cross-platform MCU debugging method. Further, the log in the debugging process is printed by the log printing instruction module and the log printing module is controlled by issuing instructions. The log printing includes the following steps:

步骤S901,判断日志等级是否匹配,若匹配,则执行步骤S902,若不匹配,则执行步骤S912;Step S901, judging whether the log level matches, if it matches, execute step S902, if not, execute step S912;

步骤S902,读取需要打印调试数据包中的字符串首地址的字符;Step S902, read the characters that need to print the first address of the character string in the debugging data packet;

步骤S903,判断该地址的首字符是否是“结束符”,若是地址首字符是结束符,则结束该过程。若首字符不是结束符,则继续下一步动作;Step S903, judging whether the first character of the address is a "terminator", if the first character of the address is a terminator, then end the process. If the first character is not an end character, continue to the next step;

步骤S904,判断字符是否为‘%’,若字符不是‘%’,则执行步骤S910,保存该字符;若字符是‘%’,则获取下一个字符;Step S904, judge whether the character is '%', if the character is not '%', then execute step S910, save the character; if the character is '%', then obtain the next character;

步骤S905,判断下一个字符是否为x或d,若为d,则执行步骤S906,若为x,则执行步骤S908;Step S905, judge whether the next character is x or d, if it is d, then execute step S906, if it is x, then execute step S908;

步骤S906,获取下一个参数;Step S906, obtaining the next parameter;

步骤S907,将获取的参数转化为十进制字符并执行步骤S910;Step S907, convert the obtained parameters into decimal characters and execute step S910;

步骤S908,获取下一个参数;Step S908, obtaining the next parameter;

步骤S909,将获取的参数转为十六进制字符并执行步骤S910;Step S909, converting the obtained parameters into hexadecimal characters and performing step S910;

步骤S910,保存该字符;Step S910, saving the character;

步骤S911,指向下一个字节,跳转重复步骤S903,直至所有的字符打印结束;Step S911, point to the next byte, jump to repeat step S903, until all characters are printed;

步骤S912,结束该过程。Step S912, end the process.

本发明提供一种跨平台的MCU调试方法,进一步地,实现打印日志等级过滤通过日志等级过滤模块来完成,The present invention provides a cross-platform MCU debugging method, and further, the printing log level filtering is completed through the log level filtering module,

步骤S601,接收上位机端的数据;Step S601, receiving data from the host computer;

步骤S602,检验数据包的完整性,若数据包是完整的,则执行步骤S603,若数据包不完整时,则结束该过程;Step S602, check the integrity of the data packet, if the data packet is complete, then perform step S603, if the data packet is incomplete, then end the process;

步骤S603,对数据包的类型进行解析并将数据包依据类型放入相应的等级内;Step S603, analyzing the type of the data packet and putting the data packet into the corresponding level according to the type;

步骤S604,对需要显示的日志选ON,不需要显示的日志选择OFF,然后进行打印;Step S604, select ON for the log that needs to be displayed, select OFF for the log that does not need to be displayed, and then print;

日志模块的等级显示ON时,则表示需要打印该等级出来,若日志模块的等级显示OFF时,则表示无须打印出该日志等级。When the level of the log module shows ON, it means that the level needs to be printed out; if the level of the log module shows OFF, it means that the level of the log does not need to be printed out.

本发明提供一种跨平台的MCU调试方法,进一步地,所述日志等级至少包括Debug日志、Info日志、OsMsg日志、Warn日志、ERROR日志、FATAL日志中的任意二种;The present invention provides a cross-platform MCU debugging method, further, the log levels include at least any two of Debug logs, Info logs, OsMsg logs, Warn logs, ERROR logs, and FATAL logs;

Debug日志:用来记录系统调试过程中命令状态;Debug log: used to record the command status during system debugging;

Info日志:用来记录当前系统的一个运行状态;Info log: used to record a running state of the current system;

OsMsg日志:用来记录进程之间的一个交互过程,只要是进程发出去的消息队列,都被打上OsMsg的标签,对外输出,能够根据源进程,目标进程,命令类型来过滤出关注的消息;OsMsg log: It is used to record an interaction process between processes. As long as the message queue sent by the process is marked with the OsMsg label and output externally, it can filter out the concerned messages according to the source process, target process, and command type;

Warn日志:用来警告开发人员,有可能发生了错误,或者进行了非法操作;Warn log: used to warn developers that errors may have occurred or illegal operations have been performed;

ERROR日志:告知开发人员程序运行过程中遇到了错误,但是这类错误在程序中已经做了相关的处理,对于功能可能失效了,但是系统运行不会受到影响;ERROR log: Inform the developer that an error has been encountered during the running of the program, but this type of error has been dealt with in the program, and the function may be invalid, but the system operation will not be affected;

FATAL日志:用来告知开发人员,系统遇到了严重的错误,导致的结果是程序崩溃,软件重启。FATAL log: It is used to inform developers that the system has encountered serious errors, resulting in program crashes and software restarts.

本发明还提供了一种跨平台的MCU调试装置,其特征在于,包括MCU,MCU包括CPU,调试功能模块,通信模块,存储模块,封装解包模块,CPU分别与调试功能模块、通信模块、存储模块、封装解包模块连接;The present invention also provides a cross-platform MCU debugging device, which is characterized in that it includes an MCU, and the MCU includes a CPU, a debugging function module, a communication module, a storage module, an encapsulation and unpacking module, and the CPU is respectively connected with the debugging function module, the communication module, Storage module, packaging and unpacking module connection;

CPU,被配置为用于负责系统各模块之间的调用以及运算;CPU, which is configured to be responsible for calls and calculations between modules of the system;

调试功能模块,被配置为根据接收到的调试指令启动相应的特定功能模块对MCU进行调试,调试功能模块能够根据调试需求进行增加或者减少调试功能;The debugging function module is configured to start the corresponding specific function module to debug the MCU according to the received debugging instruction, and the debugging function module can increase or decrease the debugging function according to the debugging requirements;

存储模块,被配置为用于存储调试过程中所需要用到的数据、产生的数据以及调试功能程序或者缓存数据;The storage module is configured to store data needed in the debugging process, generated data, and debugging function programs or cache data;

通信模块,被配置为用于MCU与上位机进行通信;A communication module configured to communicate between the MCU and the host computer;

封装解包模块,被配置为用于根据解包指令或封装指令进行相应的解包或封装。The encapsulation and unpacking module is configured to perform corresponding unpacking or encapsulation according to the unpacking instruction or the encapsulation instruction.

本发明还提供了一种跨平台的MCU调试装置,进一步地,还包括上位机,上位机至少包括CPU,存储模块,调试指令模块,通信模块,封装解包模块,CPU分别与存储模块、调试指令模块、通信模块、封装解包模块进行电连接;The present invention also provides a cross-platform MCU debugging device, further comprising a host computer, the host computer at least includes a CPU, a storage module, a debugging instruction module, a communication module, a packaging and unpacking module, and the CPU communicates with the storage module and the debugging module respectively. The instruction module, the communication module, and the packaging and unpacking module are electrically connected;

所述上位机的通信模块与MCU中的通信模块电连接,其中,上位机的通信模块与MCU中的通信模块采用无线通信或有线通信进行通信连接;The communication module of the upper computer is electrically connected to the communication module in the MCU, wherein the communication module of the upper computer and the communication module in the MCU are connected by wireless communication or wired communication;

CPU,被配置为用于负责系统各模块之间的调用以及运算;CPU, which is configured to be responsible for calls and calculations between modules of the system;

存储模块,被配置为用于存储调试过程中所需要用到的数据以及调试指令程序;The storage module is configured to store the data needed in the debugging process and the debugging instruction program;

调试指令模块,被配置为于根据调试需求调用相应的调试指令程序对MCU进行调试;The debugging instruction module is configured to call the corresponding debugging instruction program to debug the MCU according to the debugging requirements;

封装解包模块,被配置为用于根据解包指令或封装指令进行相应的解包或封装;An encapsulation and unpacking module configured to perform corresponding unpacking or encapsulation according to an unpacking instruction or an encapsulation instruction;

通信模块,被配置为用于上位机与外部设备进行通信。The communication module is configured for the host computer to communicate with external devices.

本发明还提供了一种跨平台的MCU调试装置,进一步地,所述调试功能模块至少包括日志打印模块、日志等级过滤模块、进程交互模块、固件获取模块、内容写入模块、内容读取模块、在线升级模块、工具自适应识别模块中的一种;The present invention also provides a cross-platform MCU debugging device, further, the debugging function module at least includes a log printing module, a log level filtering module, a process interaction module, a firmware acquisition module, a content writing module, and a content reading module , online upgrade module, tool self-adaptive identification module;

日志打印模块,被配置为实现日志打印,其根据日志打印指令模块的指令将日志(log)消息通过进行打印输出,用来告知开发人员程序的运行状态;日志等级过滤模块,被配置为实现日志等级过滤,其根据日志等级过滤指令模块的指令,有选择的实现动态过滤不同等级的日志能力;进程交互模块,被配置为实时记录多个任务之间的信息传递,其根据进程交互指令启动多个任务之间的信息传递记录;固件获取模块,被配置为获取固件的信息,其根据固件获取指令获取固件信息;内容写入模块,被配置为对接收到需要写入存储器的信息进行写入,其根据内容写入指令将相应的数据写入MCU的存储器中;内容读取模块,被配置为对需要读取的信息进行读取,其根据内容读取指令对相应的内容进行读取;在线升级模块,被配置为对MCU进行升级,其根据接收到来自上位机的升级指令对MCU进行升级;工具自适应识别模块,被配置为根据上位机的工具自适应识别指令对上位机是否具有配套的串口工具进行识别。The log printing module is configured to implement log printing, and it prints out log (log) messages according to the instructions of the log printing instruction module to inform developers of the running status of the program; the log level filtering module is configured to implement log printing. Level filtering, which selectively implements the ability to dynamically filter logs of different levels according to the instructions of the log level filtering command module; the process interaction module is configured to record the information transfer between multiple tasks in real time, and it starts multiple tasks according to the process interaction command. Information transfer records between tasks; the firmware acquisition module is configured to acquire firmware information, and it acquires firmware information according to the firmware acquisition instruction; the content writing module is configured to write the received information that needs to be written into the memory , which writes corresponding data into the memory of the MCU according to the content writing instruction; the content reading module is configured to read the information to be read, and reads the corresponding content according to the content reading instruction; The online upgrade module is configured to upgrade the MCU, which upgrades the MCU according to the upgrade instruction received from the upper computer; the tool adaptive identification module is configured to determine whether the upper computer has Supporting serial tool for identification.

本发明还提供了一种跨平台的MCU调试装置,进一步地,所述调试指令模块至少包括日志打印指令模块、日志等级过滤指令模块、进程交互指令模块、固件获取指令模块、内容写入指令模块、内容读取指令模块、在线升级指令模块、工具自适应识别指令模块中的一种:The present invention also provides a cross-platform MCU debugging device, further, the debugging instruction module at least includes a log printing instruction module, a log level filtering instruction module, a process interaction instruction module, a firmware acquisition instruction module, and a content writing instruction module , content reading command module, online upgrade command module, and tool adaptive recognition command module:

日志打印指令模块,被配置为根据调试需求启动日志打印指令并下发给MCU中的日志打印模块;日志等级过滤指令模块,被配置为根据调试需求启动日志等级过滤指令并下发给MCU中的日志等级过滤模块;进程交互指令模块,被配置为根据调试需求启动各个进程之间的进程交互指令并下发给MCU的进程交互模块;固件获取指令模块,被配置为根据调试需求启动获取固件的指令下发给MCU中的固件获取模块;内容写入指令模块,被配置为根据调试需求启动内容写入的指令下发给MCU中的内容写入模块;内容读取指令模块,被配置为根据调试需求启动内容读取的指令下发给MCU中的内容读取模块;在线升级指令模块,被配置为根据调试需求启动在线升级的指令下发给MCU中的在线升级模块。工具自适应识别指令模块,被配置为根据需求启动工具自适应指令并下发给MCU中的工具自适应识别模块。The log printing instruction module is configured to start the log printing instruction according to the debugging requirements and send it to the log printing module in the MCU; the log level filtering instruction module is configured to start the log level filtering instruction according to the debugging requirements and send it to the MCU The log level filtering module; the process interaction instruction module is configured to start the process interaction instructions between each process according to the debugging requirements and sends them to the process interaction module of the MCU; the firmware acquisition instruction module is configured to start the acquisition of the firmware according to the debugging requirements The command is issued to the firmware acquisition module in the MCU; the content writing command module is configured to start content writing according to the debugging requirements and is sent to the content writing module in the MCU; the content reading command module is configured to The instruction for starting content reading according to the debugging requirement is sent to the content reading module in the MCU; the online upgrade instruction module is configured to send the instruction for starting online upgrading according to the debugging requirement to the online upgrading module in the MCU. The tool adaptive recognition instruction module is configured to start the tool adaptive instruction according to requirements and issue it to the tool adaptive recognition module in the MCU.

本发明还提供了一种跨平台的MCU调试装置,进一步地,所述封装解包模块用于根据解包指令或封装指令进行相应的解包或封装,所述封装包括以下步骤:The present invention also provides a cross-platform MCU debugging device. Further, the packaging and unpacking module is used to perform corresponding unpacking or packaging according to the unpacking instruction or packaging instruction, and the packaging includes the following steps:

步骤S701,获取需要封包的有效载荷(payload)并从中获取有效载荷的地址、长度、数据包类型;Step S701, obtaining the payload (payload) that needs to be packaged and obtaining the address, length, and data packet type of the payload therefrom;

步骤S702,判断地址是否有效,若地址无效,则执行步骤S707,结束封包过程;若地址有效,则执行步骤S703;Step S702, judging whether the address is valid, if the address is invalid, execute step S707, and end the packaging process; if the address is valid, execute step S703;

步骤S703,判断有效载荷命令类型,若有效载荷的命令类型有效,则执行步骤S704,若有效载荷的命令类型无效,则执行步骤S707,结束封包过程;Step S703, judging the command type of the payload, if the command type of the payload is valid, then perform step S704, if the command type of the payload is invalid, then perform step S707, and end the packaging process;

步骤S704,判断有效载荷的数据长度是否有效,若数据长度无效,则执行步骤S707,结束封包过程,若数据长度有效,则执行步骤S705;Step S704, judging whether the data length of the payload is valid, if the data length is invalid, then execute step S707, end the packaging process, if the data length is valid, then execute step S705;

步骤S705,给有效载荷进行赋值;Step S705, assigning a value to the payload;

步骤S706,将封包好的数据存入待发送的数据区;Step S706, storing the packaged data into the data area to be sent;

步骤S707,结束封包过程。Step S707, end the packaging process.

本发明还提供了一种跨平台的MCU调试装置,进一步地,所述解包包括以下步骤:The present invention also provides a cross-platform MCU debugging device, further, the unpacking includes the following steps:

步骤S800,检测帧字头是否包含高字节,若含有高字节,则执行步骤S801,若没有高字节,回到步骤S800,对下一帧进行检测;Step S800, detecting whether the frame header contains a high byte, if it contains a high byte, then execute step S801, if there is no high byte, return to step S800, and detect the next frame;

步骤S801,检测帧字头是否包含低字节,若包含低字节,则执行步骤S802;若不包含低字节,则回到步骤S800,对下一帧数据进行检测;Step S801, detecting whether the frame header contains a low byte, if it contains a low byte, then execute step S802; if it does not contain a low byte, then return to step S800, and detect the next frame data;

步骤S802,获取数据包的长度;Step S802, obtaining the length of the data packet;

步骤S803,解析包类型,判断数据包是属于哪一类;Step S803, analyzing the packet type to determine which category the data packet belongs to;

步骤S804,获取解包后有效载荷。Step S804, obtaining the unpacked payload.

本发明还提供了一种跨平台的MCU调试装置,进一步地,日志打印模块用于对调试过程中产生日志进行打印,日志打印包括以下步骤:The present invention also provides a cross-platform MCU debugging device, further, the log printing module is used to print the log generated during the debugging process, and the log printing includes the following steps:

步骤S901,判断日志等级是否匹配,若匹配,则执行步骤S902,若不匹配,则执行步骤S912;Step S901, judging whether the log level matches, if it matches, execute step S902, if not, execute step S912;

步骤S902,读取需要打印调试数据包中的字符串首地址的字符;Step S902, read the characters that need to print the first address of the character string in the debugging data packet;

步骤S903,判断该地址的首字符是否是“结束符”,若地址首字符是结束符,则结束该过程;若首字符不是结束符,则继续下一步动作;Step S903, judging whether the first character of the address is a "terminator", if the first character of the address is a terminator, then end the process; if the first character is not a terminator, continue to the next step;

步骤S904,判断字符是否为‘%’,若字符不是‘%’,则执行步骤S910,保存该字符;若字符是‘%’,则获取下一个字符;Step S904, judge whether the character is '%', if the character is not '%', then execute step S910, save the character; if the character is '%', then obtain the next character;

步骤S905,判断下一个字符是否为x或d,若为d,则执行步骤S906,若为x,则执行步骤S908;Step S905, judge whether the next character is x or d, if it is d, then execute step S906, if it is x, then execute step S908;

步骤S906,获取下一个参数;Step S906, obtaining the next parameter;

步骤S907,将获取的参数转化为十进制字符并执行步骤S910;Step S907, convert the obtained parameters into decimal characters and execute step S910;

步骤S908,获取下一个参数;Step S908, obtaining the next parameter;

步骤S909,将获取的参数转为十六进制字符并执行步骤S910;Step S909, converting the obtained parameters into hexadecimal characters and performing step S910;

步骤S910,保存该字符;Step S910, saving the character;

步骤S911,指向下一个字节,跳转重复步骤S903,直至所有的字符打印结束;Step S911, point to the next byte, jump to repeat step S903, until all characters are printed;

步骤S912,结束该过程。Step S912, end the process.

或所述日志等级过滤模块用于实现打印日志等级过滤,日志等级过滤包括以下步骤:Or the log level filtering module is used to realize printing log level filtering, and the log level filtering includes the following steps:

步骤S601,接收上位机端的数据;Step S601, receiving data from the host computer;

步骤S602,检验数据包的完整性,若数据包是完整的,则执行步骤S603,若数据包不完整时,则结束该过程;Step S602, check the integrity of the data packet, if the data packet is complete, then perform step S603, if the data packet is incomplete, then end the process;

步骤S603,对数据包的类型进行解析并将数据包依据类型放入相应的等级内;Step S603, analyzing the type of the data packet and putting the data packet into the corresponding level according to the type;

步骤S604,对需要显示的日志选ON,不需要显示的日志选择OFF,然后进行打印。Step S604, select ON for the logs that need to be displayed, select OFF for the logs that do not need to be displayed, and then print.

本发明还提供了一种跨平台的MCU调试装置,进一步地,所述MCU还包括至少一个外设接口,外设接口被配置为用于MCU与外部测设备进行通信连接,所述外设接口类型包括SPI接口,USB接口,I2C接口、CAN接口、DOIP接口、UART接口、R232接口中的一种或多种。The present invention also provides a cross-platform MCU debugging device, further, the MCU also includes at least one peripheral interface, the peripheral interface is configured to communicate with the external testing equipment for the MCU, the peripheral interface The types include one or more of SPI interface, USB interface, I2C interface, CAN interface, DOIP interface, UART interface, and R232 interface.

本发明有益技术效果:Beneficial technical effect of the present invention:

1.本发明的调试方法相比现有技术,直接采用MCU与上位机进行组装调试,而不采用专门的调试工具作为中间介质,这样使得调试成本降低,调试方法灵活可变。使上位机与待调试的MCU直接通信,使得数据传输更可靠。而且可以根据调试需求随时的对MCU增加具有特殊调试需求的功能模块,从而实现不同平台的MCU调试。1. Compared with the prior art, the debugging method of the present invention directly adopts the MCU and the upper computer to assemble and debug without using a special debugging tool as an intermediate medium, so that the debugging cost is reduced and the debugging method is flexible and variable. Make the host computer communicate directly with the MCU to be debugged, making data transmission more reliable. Moreover, functional modules with special debugging requirements can be added to the MCU at any time according to the debugging requirements, so as to realize the MCU debugging of different platforms.

2.本发明的调试方法将所有的需要输出的信息放在存储器(缓存)中,等待系统空闲时候对外输出,这样避免了与其他高优先级的任务争夺时间,也充分利用了MCU资源。现有的调试工具,在调试过程中调用函数或者命令时产生的数据是不保存的,当函数调用完成后,其产生的数据在进行下一个函数调用时会将上一个函数产生的数据进行覆盖。本发明通过需要对外输出的数据存入缓存中,具有节省资源的效果,避免函数再次被调用。2. The debugging method of the present invention puts all the information that needs to be output in the memory (cache), and waits for the external output when the system is idle, which avoids competing for time with other high-priority tasks and makes full use of MCU resources. Existing debugging tools do not save the data generated when a function or command is called during the debugging process. After the function call is completed, the data generated by it will overwrite the data generated by the previous function when the next function call is made . The present invention has the effect of saving resources by storing the data to be outputted in the cache, and avoiding the function from being called again.

3.划分了日志等级,并设置日志等级过滤模块对日志进行过滤。因此本发明具备强大的过滤功能,支持Log记录。当产品交付于测试之后,测试时是需要断开仿真器的。也就是说传统的调试方式只适用于功能开发的时候使用。在测试阶段就无法知道程序的运行情况了。该工具添加的log追踪和过滤功能可以很好的解决这一问题。开发人员可以选择性过滤掉与bug不相干的log消息,快速追踪定位bug的位置。3. The log level is divided, and the log level filter module is set to filter the log. Therefore, the present invention has a powerful filtering function and supports Log records. After the product is delivered for testing, it is necessary to disconnect the emulator during testing. That is to say, the traditional debugging method is only suitable for function development. It is impossible to know how the program works during the testing phase. The log tracking and filtering functions added by this tool can solve this problem very well. Developers can selectively filter out log messages that are irrelevant to bugs, and quickly track and locate bugs.

4.程序方便移植,不同的厂家的MCU需要的调试器,和编译器是不同的,无法做到兼容。通过本发明提供的调试装置,仅需要将调试功能模块写入调试的MCU即可进行调试。因此,本发明的调试工具解除了平台的限制,解除的编译器的库限制,解除了对调试器的限制。4. The program is easy to transplant. The debuggers and compilers required by MCUs of different manufacturers are different and cannot be compatible. With the debugging device provided by the present invention, it is only necessary to write the debugging function module into the debugging MCU to carry out debugging. Therefore, the debugging tool of the present invention removes the restriction of the platform, removes the restriction of the library of the compiler, and removes the restriction of the debugger.

5.本发明能够实时打印调试日志,当对MCU进行调试时,可以通过日志打印模块对MCU调试后产生的日志进行打印。5. The present invention can print the debug log in real time, and when the MCU is debugged, the log generated after the MCU is debugged can be printed through the log printing module.

附图说明Description of drawings

以下附图仅对本发明做示意性说明和解释,并不限定本发明的范围。The following drawings only illustrate and explain the present invention schematically, and do not limit the scope of the present invention.

图1为现有技术中对MCU的调试流程示意图。FIG. 1 is a schematic diagram of a debugging process for an MCU in the prior art.

图2为本发明实施例中,MCU调试系统结构示意图。FIG. 2 is a schematic structural diagram of an MCU debugging system in an embodiment of the present invention.

图3为本发明实施例中调试指令模块包括具体的指令功能模块结构示意图。FIG. 3 is a schematic structural diagram of a debugging instruction module including specific instruction function modules in an embodiment of the present invention.

图4为本发明实施例中调试功能模块包括具体的功能模块结构示意图。FIG. 4 is a schematic structural diagram of debugging function modules including specific function modules in an embodiment of the present invention.

图5为本发明实施例中上位机根据调试需求启动调试指令下发给MCU并对MCU进行调试的流程图。FIG. 5 is a flow chart of the host computer in the embodiment of the present invention starting a debugging command to issue a debugging command to the MCU and debugging the MCU according to the debugging requirements.

图6为本发明实施例中MCU调试产生的数据发送给上位机进行显示的流程图。FIG. 6 is a flow chart of sending data generated by MCU debugging to a host computer for display in an embodiment of the present invention.

具体实施方式detailed description

为了对本发明的技术特征、目的和效果有更加清楚的理解,现对照附图2-6说明本发明的具体实施方式,在各图中相同的标号表示相同的部分。为使图面简洁,各图中的只示意性地表示出了与本发明相关部分,而并不代表其作为产品的实际结构。另外,以使图面简洁便于理解,在有些图中具有相同结构或功能的部件,仅示意性地绘示了其中的一个,或仅标出了其中的一个。In order to have a clearer understanding of the technical features, purposes and effects of the present invention, the specific implementation of the present invention will now be described with reference to accompanying drawings 2-6, and the same symbols in each figure represent the same parts. In order to make the drawings concise, the figures in each figure only schematically show the relevant parts of the present invention, and do not represent the actual structure of the product. In addition, to make the drawings concise and easy to understand, in some drawings, only one of the components having the same structure or function is schematically shown, or only one of them is marked.

关于控制系统,本领域技术人员熟知的是,其可以采用任何适当的形式,既可以是硬件也可以是软件,既可以是离散设置的多个功能模块,也可以是集成到一个硬件上的多个功能单元。作为最简单的形式,所述控制系统可以是控制器,例如组合逻辑控制器、微程序控制器等,只要能够实现本申请描述的操作即可。当然,控制系统也可以作为不同的模块集成到一个物理设备上,这些都不偏离本发明的基本原理和保护范围。Regarding the control system, as is well known to those skilled in the art, it can take any appropriate form, either hardware or software, multiple functional modules discretely set, or multiple functional modules integrated into one piece of hardware. a functional unit. In the simplest form, the control system can be a controller, such as a combination logic controller, a microprogram controller, etc., as long as it can realize the operations described in this application. Of course, the control system can also be integrated into one physical device as different modules, all of which do not deviate from the basic principle and protection scope of the present invention.

实施例1:Example 1:

本实施例提供一种跨平台的MCU调试装置,参见图2至图4,包括上位机1,MCU 2,上位机1包括CPU11,存储模块12,调试指令模块13,通信模块14,封装解包模块15,CPU11分别与存储模块12、调试模块13、通信模块14、封装解包模块15进行电连接,MCU2包括CPU21,调试功能模块22,通信模块24,存储模块23,封装解包模块25,至少一个外设接口26。This embodiment provides a cross-platform MCU debugging device, referring to Fig. 2 to Fig. 4, including a host computer 1, an MCU 2, and the host computer 1 includes a CPU 11, a storage module 12, a debugging command module 13, a communication module 14, packaging and unpacking Module 15, CPU11 are respectively electrically connected with storage module 12, debugging module 13, communication module 14, packaging and unpacking module 15, MCU2 includes CPU21, debugging function module 22, communication module 24, storage module 23, packaging and unpacking module 25, At least one peripheral interface 26 .

上位机1的通信模块14与MCU中的通信模块24连接,其中通信模块14与通信模块24都可以采用无线通信或有线通信方式,若采用无线通信方式,无线通信方式可以WIFI、蓝牙、超宽带、4G、5G通信等方式,或无线通信为T-box。也可以采用有线的通信方式,如上位机1和MCU2相互有匹配的接口,可以为以太网接口、I2C接口、USB接口、RS232接口、CAN接口、DOIP接口、UART接口等。如:上位机1的通信模块14具有I2C接口,MCU2的通信模块24具有I2C接口,则上位机1与MCU2通过I2C数据线进行有线连接。当采用无线通信时,上位机1的通信模块14含有无线通信组件,如具有Wifi,MCU2的通信模块24具有含有无线通信组件,为WIFI,上位机1可以通过WIFI与MCU2进行连接。或者当上位机1为远程计算机或者服务器时,可以通过T-box与MCU2进行连接。The communication module 14 of host computer 1 is connected with the communication module 24 in the MCU, and wherein communication module 14 and communication module 24 all can adopt wireless communication or wired communication mode, if adopt wireless communication mode, wireless communication mode can WIFI, bluetooth, ultra-wide band , 4G, 5G communication, etc., or wireless communication as T-box. Wired communication methods can also be used. For example, the host computer 1 and MCU2 have matching interfaces, which can be Ethernet interfaces, I2C interfaces, USB interfaces, RS232 interfaces, CAN interfaces, DOIP interfaces, UART interfaces, etc. For example, the communication module 14 of the upper computer 1 has an I2C interface, and the communication module 24 of the MCU2 has an I2C interface, then the upper computer 1 and the MCU2 are connected by wire through an I2C data line. When adopting wireless communication, the communication module 14 of host computer 1 contains wireless communication assembly, as has Wifi, and the communication module 24 of MCU2 has and contains wireless communication assembly, is WIFI, and upper computer 1 can be connected with MCU2 by WIFI. Or when the host computer 1 is a remote computer or server, it can be connected to the MCU2 through the T-box.

上位机1中,CPU11主要用于负责系统各模块之间的调用以及运算;In the upper computer 1, the CPU 11 is mainly used for invoking and computing among the various modules of the system;

存储模块12,被配置为用于存储调试过程中所需要用到的数据以及调试指令程序;The storage module 12 is configured to store the data needed in the debugging process and the debugging instruction program;

调试指令模块13,被配置为根据调试需求调用相应的调试指令程序对MCU进行调试;The debugging instruction module 13 is configured to call the corresponding debugging instruction program to debug the MCU according to the debugging requirements;

封装解包模块15,被配置为用于根据解包指令或封装指令进行相应的解包或封装;Encapsulation and unpacking module 15, configured to perform corresponding unpacking or encapsulation according to the unpacking instruction or encapsulation instruction;

通信模块14,被配置为用于上位机与外部设备进行通信;The communication module 14 is configured for the host computer to communicate with external devices;

MCU2中,MCU2可以为正在开发中的MCU,也可以为已经完成的MCU。In MCU2, MCU2 can be an MCU under development, or a completed MCU.

CPU21,被配置为用于负责系统各模块之间的调用以及运算;CPU21, which is configured to be responsible for calls and calculations among various modules of the system;

存储模块23,被配置为用于存储调试过程中所需要用到的数据、产生的数据以及调试功能程序或者缓存数据等;The storage module 23 is configured to store data needed in the debugging process, generated data, debugging function programs or cache data, etc.;

调试功能模块22,被配置为根据调试指令模块下发的调试指令启动相应的特定功能模块对MCU进行调试,调试功能模块22能够根据调试需求进行增加或者减少调试功能;The debugging function module 22 is configured to start a corresponding specific function module to debug the MCU according to the debugging instruction issued by the debugging instruction module, and the debugging function module 22 can increase or decrease the debugging function according to the debugging requirements;

通信模块24,被配置为用于MCU与上位机进行通信;The communication module 24 is configured to communicate with the upper computer for the MCU;

封装解包模块25,被配置为用于根据解包指令或封装指令进行相应的解包或封装;The packaging and unpacking module 25 is configured to perform corresponding unpacking or packaging according to the unpacking instruction or the packaging instruction;

外设接口26,被配置为用于MCU与外部测设备进行通信连接;The peripheral interface 26 is configured to communicate with the MCU and external testing equipment;

具体地,外设接口包括多个不同的接口,如SPI接口、USB,I2C接口、CAN接口、RS232接口,DOIP接口、UART接口,通过不同类型的接口,可以将不同的外接设备连接到MCU中,通过上位机的调试模块经MCU对外界设备进行调试。Specifically, the peripheral interface includes multiple different interfaces, such as SPI interface, USB, I2C interface, CAN interface, RS232 interface, DOIP interface, and UART interface. Through different types of interfaces, different external devices can be connected to the MCU. , through the debugging module of the upper computer to debug the external equipment through the MCU.

具体地,需要说明的是本发明中的电连接可以为直接电连接或者间接电连接。Specifically, it should be noted that the electrical connection in the present invention may be a direct electrical connection or an indirect electrical connection.

参见图3,调试指令模块包括:Referring to Figure 3, the debug command module includes:

日志打印指令模块,被配置为根据调试需求启动日志打印指令并下发给MCU中的日志打印模块;The log printing command module is configured to start the log printing command according to the debugging requirements and send it to the log printing module in the MCU;

日志等级过滤指令模块,被配置为根据调试需求启动日志等级过滤指令并下发给MCU中的日志等级过滤模块;The log level filtering command module is configured to start the log level filtering command according to the debugging requirements and send it to the log level filtering module in the MCU;

进程交互指令模块,被配置为根据调试需求启动各个进程之间的进程交互指令并下发给MCU的进程交互模块;The process interaction instruction module is configured to start the process interaction instructions between various processes according to the debugging requirements and send them to the process interaction module of the MCU;

固件获取指令模块,被配置为根据调试需求启动获取固件的指令下发给MCU中的固件获取模块;The firmware acquisition instruction module is configured to start and issue the instruction to acquire firmware to the firmware acquisition module in the MCU according to the debugging requirements;

内容写入指令模块,被配置为根据调试需求启动内容写入的指令下发给MCU中的内容写入模块;The content writing command module is configured to send the content writing command to the content writing module in the MCU according to the debugging requirements to start the content writing;

内容读取指令模块,被配置为根据调试需求启动内容读取的指令下发给MCU中的内容读取模块;The content reading instruction module is configured to issue an instruction to start content reading according to the debugging requirements to the content reading module in the MCU;

在线升级指令模块,被配置为根据调试需求启动在线升级的指令下发给MCU中的在线升级模块。The online upgrade instruction module is configured to issue an instruction to start the online upgrade to the online upgrade module in the MCU according to the debugging requirement.

工具自适应识别指令模块,被配置为根据需求启动工具自适应指令并下发给MCU中的工具自适应识别模块;A tool adaptive recognition command module configured to start a tool adaptive command according to requirements and send it to the tool adaptive recognition module in the MCU;

应用层指令模块,被配置为根据需求启动应用层指令下发给MCU中的应用层功能定制模块;The application layer instruction module is configured to start the application layer instruction and send it to the application layer function customization module in the MCU according to the requirements;

参见图4,调试功能模块包括See Figure 4, the debugging function modules include

日志打印模块,被配置为实现日志打印,其根据日志打印指令模块的指令将日志(log)消息进行打印输出,用来告知开发人员程序的运行状态;The log printing module is configured to realize log printing, which prints out the log (log) message according to the instruction of the log printing instruction module, and is used to inform the developer of the running status of the program;

日志等级过滤模块,被配置为实现日志等级过滤,其根据日志等级过滤指令模块的指令,有选择的实现动态过滤不同等级的日志能力。具体的,日志分为六个等级;The log level filtering module is configured to implement log level filtering, and selectively implements the ability to dynamically filter logs of different levels according to the instructions of the log level filtering instruction module. Specifically, the log is divided into six levels;

进程交互模块,被配置为实时记录多个任务之间的信息传递,其根据进程交互指令启动多个任务之间的信息传递记录;The process interaction module is configured to record the information transmission between multiple tasks in real time, and it starts the information transmission recording between multiple tasks according to the process interaction instruction;

固件获取模块,被配置为获取固件的信息,其根据固件获取指令获取固件信息;A firmware acquisition module configured to acquire firmware information, which acquires firmware information according to a firmware acquisition instruction;

内容写入模块,被配置为对接收到需要写入存储器的信息进行写入,其根据内容写入指令将相应的数据写入MCU的存储器中;The content writing module is configured to write the received information that needs to be written into the memory, and writes the corresponding data into the memory of the MCU according to the content writing instruction;

内容读取模块,被配置为对需要读取的信息进行读取,其根据内容读取指令对相应的内容进行读取;The content reading module is configured to read the information to be read, and reads the corresponding content according to the content reading instruction;

在线升级模块,被配置为对MCU进行升级,其根据接收到来自上位机的升级指令对MCU进行升级;The online upgrade module is configured to upgrade the MCU, which upgrades the MCU according to the upgrade instruction received from the host computer;

工具自适应识别模块,被配置为根据上位机的工具自适应识别指令对上位机是否具有配套的串口工具进行识别;The tool adaptive identification module is configured to identify whether the upper computer has a supporting serial port tool according to the tool adaptive identification instruction of the upper computer;

应用层功能定制模块,被配置为根据上位机的应用层指令对应用程序的功能进行定制。The application layer function customization module is configured to customize the functions of the application program according to the application layer instructions of the upper computer.

实施例2:Example 2:

本实施提供了一种对跨平台的MCU调试方法,参见图5和图6,其包括两个阶段,第一阶段包括上位机根据调试需求启动调试指令下发给MCU,MCU接收到调试指令后启动相应的调试功能模块对MCU进行调试;This implementation provides a cross-platform MCU debugging method, see Figure 5 and Figure 6, which includes two stages, the first stage includes the host computer according to the debugging requirements to start the debugging command and send it to the MCU, after the MCU receives the debugging command Start the corresponding debugging function module to debug the MCU;

第二阶段包括MCU调试产生的数据发送给上位机进行显示,MCU调试产生的数据至少包括日志,日志根据类型划分为多个日志等级。在对MCU调试过程中,将需要输出的数据暂存于存储器中,等待系统空闲时候对外输出。或包括当发现MCU中调试功能模块没有内置预设的功能模块或根据调试需求,需要增加特殊功能模块式,通过上位机直接将含有所需的功能模块写入MCU中。具体地如:如需要对MCU进行还原,现有的功能模块不具备这个功能,此时,可以通过上位机将该功能程序直接写入MCU中。The second stage includes sending the data generated by MCU debugging to the host computer for display. The data generated by MCU debugging includes at least logs, which are divided into multiple log levels according to the type. In the process of debugging the MCU, temporarily store the data that needs to be output in the memory, and wait for the external output when the system is idle. Or when it is found that the debugging function module in the MCU does not have a built-in preset function module or according to the debugging requirements, it is necessary to add a special function module, and directly write the required function module into the MCU through the host computer. Specifically, if the MCU needs to be restored, the existing functional modules do not have this function. At this time, the functional program can be directly written into the MCU through the host computer.

调试指令模块,被配置为根据调试需求调用相应的调试指令程序对MCU进行调试;The debugging instruction module is configured to call the corresponding debugging instruction program to debug the MCU according to the debugging requirements;

调试功能模块,被配置为与调试指令模块相对应并根据调试指令模块下发的调试指令启动相应的功能模块对MCU进行调试。The debugging function module is configured to correspond to the debugging instruction module and start the corresponding function module to debug the MCU according to the debugging instruction issued by the debugging instruction module.

第一阶段包括以下步骤:The first phase consists of the following steps:

步骤S101:根据调试需求通过上位机启动调试指令模块发送指令;Step S101: According to the debugging requirements, start the debugging instruction module to send instructions through the host computer;

具体地,调试需求是根据工程师制定的调试方案来进行,调试指令模块集成了常见的MCU调试指令,还可以根据需求自动通过上位机通过添加或删除具体的调试指令。调试指令是事先定义好的,当MCU端接收到相应的调试指令时,其调试功能模块会根据调试指令执行相应的动作。Specifically, the debugging requirements are carried out according to the debugging plan formulated by the engineer. The debugging instruction module integrates common MCU debugging instructions, and can also automatically add or delete specific debugging instructions through the host computer according to requirements. The debugging instructions are defined in advance, and when the MCU receives the corresponding debugging instructions, its debugging function module will execute corresponding actions according to the debugging instructions.

步骤S102,上位机的封装解包模块对接收到指令进行封装并形成数据包;Step S102, the encapsulation and unpacking module of the host computer encapsulates the received instruction and forms a data packet;

具体地,需要传送的数据包都需要进行封包,使其满足传输的标准协议才能够进行传输。此处,封装解包模块会对需要传输的指令按照预先定义的协议要求进行封包。Specifically, all data packets that need to be transmitted need to be packaged so that they can be transmitted only if they meet the standard transmission protocol. Here, the encapsulation and depacketization module encapsulates the instructions to be transmitted according to the predefined protocol requirements.

步骤S103,上位机中的通信模块将封装好的数据包发送给MCU;Step S103, the communication module in the host computer sends the encapsulated data packet to the MCU;

具体地,上位机中的通信模块发送数据包给MCU的过程是MCU的通信模块对上位机的发送的数据包进行接收。Specifically, the process of the communication module in the host computer sending the data packet to the MCU is that the communication module of the MCU receives the data packet sent by the host computer.

步骤S104,MCU的通信模块将接收到的数据包存入存储器中;Step S104, the communication module of the MCU stores the received data packets in the memory;

步骤S105,MCU中的封装解包模块对接收到的数据包进行解包并获得指令;Step S105, the encapsulation and unpacking module in the MCU unpacks the received data packet and obtains an instruction;

步骤S106,MCU中的调试功能模块根据指令调用相应的功能程序执行MCU的调试。Step S106, the debugging function module in the MCU invokes the corresponding function program according to the instruction to execute the debugging of the MCU.

具体地,调试功能模块是预先写入MCU中的,调试功能模块与上位机中的调试指令模块相对应,其可以根据调试指令进行相应的调试动作。若MCU中无相应的调试功能模块,其可以通过上位机将调试功能模块写入到MCU中在进行调试。Specifically, the debugging function module is pre-written into the MCU, and the debugging function module corresponds to the debugging instruction module in the host computer, and it can perform corresponding debugging actions according to the debugging instruction. If there is no corresponding debugging function module in the MCU, it can be debugged by writing the debugging function module into the MCU through the host computer.

调试功能模块包括封装好的程序,其可以直接将封装的程序直接写入到MCU即可,结果方便快捷。The debugging function module includes a packaged program, which can directly write the packaged program to the MCU, and the result is convenient and quick.

MCU调试产生的数据发送给上位机进行显示至少包括以下步骤:Sending the data generated by MCU debugging to the host computer for display includes at least the following steps:

步骤S201:根据调试需求将对MCU调试产生的数据进行发送;Step S201: Send the data generated by the MCU debugging according to the debugging requirements;

具体地,调试需求是根据第一阶段中下发的指令通过MCU中的调试功能启动相应的调试功能模块进行对MCU进行调试,调试过程会产生一系统的日志、调试结果、MCU运行状态等数据,需要将这些数据发送给上位机进行显示,从而工程师能够查看这些数据进而对MCU的调试结果进行分析。Specifically, the debugging requirement is to start the corresponding debugging function module through the debugging function in the MCU to debug the MCU according to the instructions issued in the first stage. The debugging process will generate a system of logs, debugging results, MCU running status and other data , These data need to be sent to the host computer for display, so that engineers can view these data and analyze the debugging results of the MCU.

步骤S202,判断数据类型;Step S202, judging the data type;

具体地,调试过程中会产生数据包,也可以产生命令包,因此数据传送过程中需要判断数据包的类型。Specifically, a data packet may be generated during the debugging process, and a command packet may also be generated, so the type of the data packet needs to be determined during the data transmission process.

步骤S203,MCU中的封装解包模块根据需求进行封包并将数据包存入存储器中;Step S203, the encapsulation and unpacking module in the MCU performs encapsulation according to requirements and stores the data packets in the memory;

具体地,需要传送的数据包都需要进行封包,使其满足传输的标准协议才能够进行传输。此处,封装解包模块会对需要传输的指令按照预先定义的协议要求进行封包。Specifically, all data packets that need to be transmitted need to be packaged so that they can be transmitted only if they meet the standard transmission protocol. Here, the encapsulation and depacketization module encapsulates the instructions to be transmitted according to the predefined protocol requirements.

步骤S204,MCU中的通信模块将存储器中的数据包发送给上位机;Step S204, the communication module in the MCU sends the data packet in the memory to the host computer;

具体地,MCU中发送数据给上位机是通过通信模块进行的。Specifically, sending data from the MCU to the host computer is carried out through the communication module.

步骤S205,上位机中的封装解包模块对接收的数据包进行解包;Step S205, the encapsulation and unpacking module in the host computer unpacks the received data packet;

步骤S206,上位机将解包的数据进行显示。Step S206, the host computer displays the unpacked data.

具体地,将MCU调试产生的数据在上位机上进行显示,工程是可以显示的内容检查MCU是否存在问题,若存在问题,数据会显示出产生问题的原因,然后工程能够比较方便地对数据进行修改。Specifically, the data generated by MCU debugging is displayed on the host computer. The project can display the content to check whether there is a problem with the MCU. If there is a problem, the data will show the cause of the problem, and then the project can modify the data more conveniently. .

调试功能模块包括封装好的程序,其可以直接将封装的程序直接写入到MCU,结果方便快捷。The debugging function module includes a packaged program, which can directly write the packaged program to the MCU, and the result is convenient and fast.

实施例3Example 3

本实施例提供了数据封装以及数据解包的方法,其通过封装解包模块完成。This embodiment provides a data encapsulation and data unpacking method, which is completed by an encapsulation and unpacking module.

数据封装方法包括以下步骤:The data encapsulation method includes the following steps:

步骤S701,获取需要封包的有效载荷(payload)并从中获取有效载荷的地址、长度、数据包类型;Step S701, obtaining the payload (payload) that needs to be packaged and obtaining the address, length, and data packet type of the payload therefrom;

具体地,需要传送的有效载荷已经存在了,在传送的时候需要进行封包,依据数据包的类型将有效载荷加上报头才能进行传送;Specifically, the payload that needs to be transmitted already exists, and it needs to be packaged when transmitting, and the payload can be transmitted according to the type of the data packet by adding a header;

步骤S702,判断地址是否有效,若地址无效,则执行步骤S707,结束封包过程;若地址有效,则执行步骤S703;Step S702, judging whether the address is valid, if the address is invalid, execute step S707, and end the packaging process; if the address is valid, execute step S703;

具体地,由于载荷数据存储是分段,根据获得的地址在存储区域进行查找是否存在该地址,若存在该地址,则说明该地址有效。若不存在该地址,则地址无效。Specifically, since the load data is stored in segments, it is searched in the storage area according to the obtained address whether the address exists, and if the address exists, it means that the address is valid. If the address does not exist, the address is invalid.

步骤S703,判断有效载荷命令类型,若有效载荷的命令类型有效,则执行步骤S704,若有效载荷的命令类型无效,则执行步骤S707,结束封包过程;Step S703, judging the command type of the payload, if the command type of the payload is valid, then perform step S704, if the command type of the payload is invalid, then perform step S707, and end the packaging process;

具体地,有效载荷的类型需要进行判断,本发明中的有效载荷包括四种类型,分别定义如下:第一类:0x01:Log message packet.第二类:0x02:CMD message packet。第三类:0x03:Firmware packet。第四类:0x04:OS Msg packet。若有效载荷是上述四种类型,则认为有效,若有效载荷不是上述四种类型,则认为无效。Specifically, the type of the payload needs to be judged. The payload in the present invention includes four types, which are respectively defined as follows: the first type: 0x01: Log message packet. The second type: 0x02: CMD message packet. The third type: 0x03: Firmware packet. The fourth category: 0x04: OS Msg packet. If the payload is of the above four types, it is considered valid, and if the payload is not of the above four types, it is considered invalid.

步骤S704,判断有效载荷的数据长度是否有效,若数据长度无效,则执行步骤S707,结束封包过程,若数据长度有效,则执行步骤S705;Step S704, judging whether the data length of the payload is valid, if the data length is invalid, then execute step S707, end the packaging process, if the data length is valid, then execute step S705;

步骤S705,给有效载荷进行赋值;Step S705, assigning a value to the payload;

具体地,赋值包括对有效载荷根据判断的数据包类型,数据包长度,再加上校验信息、加密信息等等。Specifically, the assignment includes the type of the data packet judged based on the payload, the length of the data packet, plus verification information, encryption information, and the like.

步骤S706,将封包好的数据存入待发送的数据区;Step S706, storing the packaged data into the data area to be sent;

步骤S707,结束封包过程。Step S707, end the packaging process.

数据解包方法至少包括以下步骤:The data unpacking method at least includes the following steps:

步骤S800,检测帧字头是否为包含高字节,若含有高字节,则执行步骤S801,若没有高字节,回到步骤S800,对下一帧进行检测;Step S800, detecting whether the frame header contains a high byte, if it contains a high byte, then execute step S801, if there is no high byte, return to step S800, and detect the next frame;

具体地,通过封装的数据包通过包括帧字头(head)和有效载荷(payload),帧字头(即报头)定义了一些规则,若可以用两个字节作为这个数据包的开始标志,一个就是帧头高字节,一个是帧头低字节。解包时,首要就是要对帧字头进行分析,数据是以帧进行传送,因此对帧字头进行检测,查看是否包含高字节。Specifically, the encapsulated data packet includes a frame header (head) and a payload (payload), and the frame header (ie header) defines some rules. If two bytes can be used as the start flag of this data packet, One is the high byte of the frame header, and the other is the low byte of the frame header. When unpacking, the first thing is to analyze the header of the frame. The data is transmitted in frames, so the header of the frame is checked to see if it contains high bytes.

步骤S801,检测帧字头时有包含低字节,若包含低字节,则执行步骤S802;若不包含低字节,则回到步骤S800,对下一帧数据进行检测;Step S801, when the frame header is detected, the low byte is included, if the low byte is included, then step S802 is performed; if the low byte is not included, then return to step S800, and the next frame data is detected;

具体地,通过封装的数据包通过包括帧字头(head)和有效载荷(payload),帧字头(即报头)定义了一些规则,若可以用两个字节作为这个数据包的开始标志,一个就是帧头高字节,一个是帧头低字节。解包时,首要就是要对帧字头进行分析,数据是以帧进行传送,因此对帧字头进行检测,查看是否包含低字节。Specifically, the encapsulated data packet includes a frame header (head) and a payload (payload), and the frame header (ie header) defines some rules. If two bytes can be used as the start flag of this data packet, One is the high byte of the frame header, and the other is the low byte of the frame header. When unpacking, the first thing is to analyze the frame header. The data is transmitted in frames, so the frame header is checked to see if it contains low bytes.

步骤S802,获取数据包的长度;Step S802, obtaining the length of the data packet;

具体地,数据传送过来,一帧数据总体上分为两段,分别为帧头(head)和payload(有效载荷),数据包长度信息放在帧头中,因此通过分析帧子头,就能够知晓数据包的长度。Specifically, when the data is transmitted, a frame of data is generally divided into two sections, namely the frame header (head) and payload (payload), and the data packet length information is placed in the frame header, so by analyzing the frame subheader, you can Know the length of the packet.

步骤S803,解析包类型,判断数据包是属于哪一类。Step S803, analyzing the packet type to determine which type the data packet belongs to.

在本发明中的有效载荷包括四种类型,分别定义如下:第一类:0x01:Log messagepacket.第二类:0x02:CMD message packet.第三类:0x03:Firmware packet.第四类:0x04:OS Msg packet。在数据封包过程中,已经对数据类型进行了定义,因此通过对帧字头进行分析,就能够知晓数据包的类型。The payload in the present invention includes four types, respectively defined as follows: the first type: 0x01: Log messagepacket. The second type: 0x02: CMD message packet. The third type: 0x03: Firmware packet. The fourth type: 0x04: OS Msg packet. In the data packet process, the data type has been defined, so the type of the data packet can be known by analyzing the frame header.

步骤S804,获取解包后有效载荷;Step S804, obtaining the unpacked payload;

具体地,通过分析数据包的帧字头后,获取相关信息,将帧字头去掉,剩下有效载荷。Specifically, after analyzing the frame header of the data packet, relevant information is obtained, the frame header is removed, and the payload remains.

实施例4:Example 4:

开发人员在开发程序的过程中,可以调用Log接口,将Log分布在自己编写的程序的任何位置。用来离线的检测系统的运行状态。在调试过程中也可以将程序员关心的一些变量,按照各种格式打印出来,Log可以理解为脱机之后的唯一一个检测系统的窗口。调试过程中的日志是通过日志打印指令模块通过下发指令控制日志打印模块进行打印的,具体的日志打印流程如下所述:During the process of developing the program, the developer can call the Log interface to distribute the Log anywhere in the program he writes. It is used to detect the running status of the system offline. During the debugging process, some variables that programmers care about can also be printed out in various formats. Log can be understood as the only window of the detection system after offline. The logs in the debugging process are printed through the log printing command module to control the log printing module by issuing commands. The specific log printing process is as follows:

步骤S901,判断日志等级是否匹配,若匹配,则执行步骤S902,若不匹配,则执行步骤S912;Step S901, judging whether the log level matches, if it matches, execute step S902, if not, execute step S912;

具体地,本发明将日志等级划分为多个等级,若打印的等级为已定义的等级中的内容以及过滤模块中时打开的,则认为是匹配的,若打印的内容并不在预定义的等级范围内或者过滤模块中等级范围是关闭状态,则为不匹配。Specifically, the present invention divides the log level into multiple levels, if the printed level is the content in the defined level and opened in the filter module, it is considered to be a match, if the printed content is not in the predefined level If it is within the range or the grade range in the filter module is off, then it is a mismatch.

步骤S902,读取需要打印调试数据包中的字符串首地址的字符;Step S902, read the characters that need to print the first address of the character string in the debugging data packet;

步骤S903,判断该地址的首字符是否是“结束符”,若是地址首字符是结束符,则结束该过程。若首字符不是结束符,则继续下一步动作。Step S903, judging whether the first character of the address is a "terminator", if the first character of the address is a terminator, then end the process. If the first character is not an end character, continue to the next step.

具体地,结束符可以自己定义,通常为“\0”。Specifically, the terminator can be defined by itself, usually "\0".

步骤S904,判断字符是否为‘%’,若字符不是‘%’,则执行步骤S910,保存该字符;若字符是‘%’,则获取下一个字符;Step S904, judge whether the character is '%', if the character is not '%', then execute step S910, save the character; if the character is '%', then obtain the next character;

步骤S905,判断下一个字符是否为x或d,若为d,则执行步骤S906,若为x,则执行步骤S908;Step S905, judge whether the next character is x or d, if it is d, then execute step S906, if it is x, then execute step S908;

步骤S906,获取下一个参数;Step S906, obtaining the next parameter;

步骤S907,将获取的参数转化为十进制字符并执行步骤S910;Step S907, convert the obtained parameters into decimal characters and execute step S910;

步骤S908,获取下一个参数;Step S908, obtaining the next parameter;

步骤S909,将获取的参数转为十六进制字符并执行步骤S910;Step S909, converting the obtained parameters into hexadecimal characters and performing step S910;

步骤S910,保存该字符;Step S910, saving the character;

步骤S911,指向下一个字节,跳转重复步骤S903,直至所有的字符打印结束;Step S911, point to the next byte, jump to repeat step S903, until all characters are printed;

步骤S912,结束该过程。Step S912, end the process.

例如:打印一行调试日志,logPintf(LOG_INFO,“this is test%d\0”,cnt1,cnt2,cnt3),For example: print a line of debug log, logPintf(LOG_INFO,"this is test%d\0", cnt1, cnt2, cnt3),

LOG_INFO为预先定义的多个等级中一个,若LOG_INFO的打印中,日志等级过滤模块,如果打开状态,则LOG_INFO等级是匹配的。若不是定义的等级类型或日志等级过滤模块时关闭的,则不匹配。LOG_INFO is one of multiple predefined levels. If LOG_INFO is printing, the log level filter module, if it is turned on, the LOG_INFO level is matched. Does not match if it is not a defined level type or when the log level filter module is turned off.

若匹配,显示字符“t”并不是“%”,则保存“t”,直至保存this is test,此时程序执行到%,该字符为%,查看下一步字符,为d,获取下一个参数cnt1,将cnt1转为十进制数显示。需要说明的是“\0”是系统自动加载的,实际上并不显示。因此,默认“%”的内容是不显示的,认为“%”之后的字符是cnt1。If it matches, the displayed character "t" is not "%", then save "t" until this is test is saved, at this time, the program executes to %, the character is %, check the next character, it is d, and get the next parameter cnt1, convert cnt1 to decimal number display. It should be noted that "\0" is automatically loaded by the system and is not actually displayed. Therefore, the content of "%" is not displayed by default, and the character after "%" is considered to be cnt1.

在日志打印过程中,可以通过日志等级过滤指令下发给日志等级过滤模块进行执行等级过滤,日志等级过滤模块会将日志分为多个等级,本实施例中,等级包括6个,配合上位机实现动态过滤不同等级log的能力。During the log printing process, the log level filtering module can be sent to the log level filtering module to perform level filtering through the log level filtering command. The log level filtering module will divide the log into multiple levels. Realize the ability to dynamically filter logs of different levels.

Log模块定义了6个等级,分别为debug(调试消息),info(信息),OsMsg(类型消息),Warn(警告),Error(错误),Fatal(致命),每一个等级日志都设置有显示(on)或关闭(off),通过选择显示或关闭选型,可以将需要的日志快速的查找出来,过滤掉相关的模块。例如:如果我们需要显示debug日志,则debug需要选择On debug消息,如果要过滤掉debug日志,则debug需要选择OFF debug消息,其它依次类推。The Log module defines 6 levels, namely debug (debugging message), info (information), OsMsg (type message), Warn (warning), Error (error), Fatal (fatal), each level of log is set to display (on) or off (off), by choosing to display or close the selection, you can quickly find the required logs and filter out the relevant modules. For example: if we need to display the debug log, then debug needs to select On debug message, if we want to filter out debug log, then debug needs to select OFF debug message, and so on.

实现打印日志等级过滤通过日志等级过滤模块来完成,具体包括以下步骤:The realization of printing log level filtering is accomplished through the log level filtering module, which specifically includes the following steps:

步骤S601,接收上位机端的数据;Step S601, receiving data from the host computer;

步骤S602,检验数据包的完整性,若数据包是完整的,则执行步骤S603,若数据包是不完整的,则结束该过程;Step S602, check the integrity of the data packet, if the data packet is complete, then perform step S603, if the data packet is incomplete, then end the process;

步骤S603,对数据包的类型进行解析并将数据包依据类型放入相应的等级内;Step S603, analyzing the type of the data packet and putting the data packet into the corresponding level according to the type;

步骤S604对需要显示的日志选ON,不需要显示的日志选择OFF,然后进行打印;Step S604 selects ON for the log that needs to be displayed, selects OFF for the log that does not need to be displayed, and then prints;

具体地,日志模块的等级显示ON时,则表示需要打印该等级出来,若日志模块的等级显示OFF时,则表示无须打印出该日志等级;Specifically, when the level of the log module shows ON, it means that the level needs to be printed out; if the level of the log module shows OFF, it means that the level of the log does not need to be printed out;

Debug日志用来记录系统调试过程中命令状态,主要是在某个单一功能调试的时候使用,可以不用考虑整个系统。因为在软件释放的时候,这个等级的Log默认是关闭的。当这个程序开发完毕之后,debug类型的log会被删除。比如我们在调试车速的时候,可以实时的将当前从CAN网络上采集的车速值打印出来。等待此功能完全做好了,再把这段Log删除。因为这种等级的Log对系统而言没有太大意义,但是对于当前功能的开发和调试非常有用。The Debug log is used to record the command status during system debugging. It is mainly used when debugging a single function without considering the entire system. Because when the software is released, the Log of this level is turned off by default. When the program is developed, the debug type log will be deleted. For example, when we debug the vehicle speed, we can print out the current vehicle speed value collected from the CAN network in real time. Wait for this function to be fully completed, and then delete this Log. Because this level of Log is not very meaningful to the system, but it is very useful for the development and debugging of the current function.

Info日志类型的Log主要是用来记录当前系统的一个运行状态。阶段性,标志性的动作已经执行之后会使用这一类型的消息。比如外设上电完成,外设初始化成功。这些消息可以监控系统的运行状态,告知调试人员有当前程序运行到哪一阶段。如果发现本该打印的info消息却没有打印出来,则说明对应区域的功能可能出现故障。The Info log type Log is mainly used to record a running status of the current system. This type of message is used after a phased, iconic action has been performed. For example, the peripheral device is powered on and the peripheral device initialization is successful. These messages can monitor the running status of the system and inform the debugger what stage the current program is running at. If it is found that the info message that should be printed is not printed, it means that the function of the corresponding area may be faulty.

OsMsg日志类型的消息是用来记录进程之间的一个交互过程。只要是进程发出去的消息队列,都被打上OsMsg的标签,对外输出。可以根据源进程,目标进程,命令类型来过滤出关注的消息。一方面可以检测负担重的进程,可以给这一类进程分配更多的资源用来保障其正常运行。也可以过滤出一些关键性的命令来更加深入的了解系统的运行过程。OsMsg log type messages are used to record an interaction process between processes. As long as the message queue sent by the process is marked with the OsMsg label, it will be output to the outside world. Messages of interest can be filtered out based on the source process, target process, and command type. On the one hand, it can detect heavy-duty processes, and allocate more resources to such processes to ensure their normal operation. You can also filter out some key commands to gain a deeper understanding of the system's running process.

Warn日志类型主要是用来警告开发人员,有可能发生了错误,或者进行了非法操作。The Warn log type is mainly used to warn developers that errors may have occurred or illegal operations have been performed.

ERROR日志类型的消息主要告知开发人员程序运行过程中遇到了错误,但是这类错误在程序中已经做了相关的处理,对于功能可能失效了,但是系统运行不会受到影响。The ERROR log type message mainly informs the developer that an error has been encountered during the running of the program, but this type of error has been dealt with in the program, and the function may be invalid, but the system operation will not be affected.

FATA日志类型的消息用来告知开发人员,系统遇到了严重的错误,导致的结果是程序崩溃,软件重启等严重的后果。FATA log type messages are used to inform developers that the system has encountered a serious error, resulting in program crashes, software restarts and other serious consequences.

实施例5:Example 5:

开发人员在对MCU进行调试的过程中,通过上位机中调试指令模块,如日志打印、进程交互、内容读取等指令,将这些指令下发到MCU中调试功能模块,通过启动相应的功能模块产生的调试数据,将这些数据存储于存储器中,优选的,存储于缓存中,而不立即清除等待系统空闲时候对外输出,这样避免了与其他高优先级的任务争夺时间,也充分利用了MCU资源。In the process of debugging the MCU, developers send these instructions to the MCU to debug the functional modules through the debugging instruction modules in the host computer, such as log printing, process interaction, and content reading, and start the corresponding functional modules. The generated debugging data is stored in the memory, preferably in the cache, instead of being cleared immediately and waiting for the external output when the system is idle, so as to avoid competing for time with other high-priority tasks and make full use of the MCU resource.

Claims (9)

1. A cross-platform MCU debugging method is applied to debugging of an upper computer and an MCU, and is characterized by at least comprising the following steps:
the upper computer starts a debugging instruction module according to debugging requirements to send a debugging instruction to the MCU, and the MCU starts a corresponding debugging functional module to debug the MCU after receiving the debugging instruction;
the debugging instruction module is configured to call a corresponding debugging instruction program according to debugging requirements to debug the MCU;
the debugging functional module is configured to correspond to the debugging instruction module and start a corresponding specific functional module to debug the MCU according to a debugging instruction issued by the debugging instruction module;
the debugging instruction needs to be packaged before being sent to the MCU, and the packaging of the debugging instruction at least comprises the following steps:
step S701, acquiring a payload to be packaged and acquiring an address, a length and a data packet type of the payload from the payload;
step S702, judging whether the address is valid, if the address is invalid, executing step S707 to end the packaging process; if the address is valid, go to step S703;
step S703 of determining the command type of the payload, if the command type of the payload is valid, executing step S704, and if the command type of the payload is invalid, executing step S707, and ending the packetizing process;
step S704, determining whether the data length of the payload is valid, if the data length is invalid, executing step S707, ending the encapsulation process, if the data length is valid, executing step S705;
step S705, assigning values to the effective loads;
step S706, storing the packaged data into a data area to be sent;
in step S707, the packaging process is ended.
2. The cross-platform MCU debugging method of claim 1, further comprising: data generated by MCU debugging are sent to an upper computer for displaying, the data generated by MCU debugging at least comprise logs, and the logs are divided into a plurality of log grades according to types;
in the process of debugging the MCU, temporarily storing data to be output in a memory, and outputting the data to the outside when a system is idle;
or when the debugging functional module in the MCU is found not to be internally provided with a preset functional module or an additional functional module is required to be added according to the debugging requirement, the required functional module is directly written into the MCU through the upper computer.
3. The cross-platform MCU debugging method of claim 2,
the MCU needs to unpack the received encapsulated data packet to obtain a modulation instruction;
the data generated by MCU debugging need to be packaged before being sent to the upper computer, and the upper computer needs to unpack the received packaged data packet to obtain the data packet generated by debugging.
4. The cross-platform MCU debugging method according to claim 3,
the unpacking of the received encapsulated data packet comprises the following steps:
step S800, detecting whether the frame header contains high byte, if so, executing step S801, if not, returning to step S800 to detect the next frame;
step S801, detecting whether the frame header includes a low byte, if so, executing step S802; if the low byte is not included, returning to step S800, and detecting next frame data;
step S802, acquiring the length of a data packet;
step S803, analyze the packet type, judge which kind of packet belongs to;
and step S804, acquiring the unpacked effective load.
5. The cross-platform MCU debugging method according to claim 1, wherein the debugging instruction module at least comprises one or more of a log printing instruction module, a log level filtering instruction module, a process interaction instruction module, a firmware acquisition instruction module, a content writing instruction module, a content reading instruction module, an online upgrading instruction module, a tool adaptive identification instruction module, and an application layer instruction module;
the debugging functional module at least comprises one or more of a log printing module, a log grade filtering module, a process interaction module, a firmware acquisition module, a content writing module, a content reading module, an online upgrading module, a tool self-adaptive identification module and an application layer function formulation module.
6. The cross-platform MCU debugging method according to claim 5,
the log printing instruction module is configured to start a log printing instruction according to debugging requirements and issue the log printing instruction to the log printing module in the MCU;
the log grade filtering instruction module is configured to start a log grade filtering instruction according to debugging requirements and issue the log grade filtering instruction to the log grade filtering module in the MCU;
the process interaction instruction module is configured to start process interaction instructions among the processes according to debugging requirements and issue the process interaction instructions to the MCU;
the firmware acquisition instruction module is configured to start an instruction for acquiring firmware according to debugging requirements and issue the instruction to the firmware acquisition module in the MCU;
the content writing instruction module is configured to start a content writing instruction according to the debugging requirement and issue the content writing instruction to the content writing module in the MCU;
the content reading instruction module is configured to start a content reading instruction according to the debugging requirement and send the content reading instruction to the content reading module in the MCU;
the online upgrading instruction module is configured to start an online upgrading instruction according to debugging requirements and send the online upgrading instruction to the online upgrading module in the MCU;
the tool self-adaptive identification instruction module is configured to start a tool self-adaptive instruction according to the requirement and issue the tool self-adaptive identification instruction to the tool self-adaptive identification module in the MCU;
the application layer instruction module is configured to start an application layer instruction according to the requirement and send the application layer instruction to the application layer customizing function module in the MCU;
the log printing module is configured to realize log printing, and is used for printing and outputting log messages according to the instructions of the log printing instruction module so as to inform the operating state of the program to developers;
the log grade filtering module is configured to realize log grade filtering and selectively realize dynamic filtering of log capacities of different grades according to the instruction of the log grade filtering instruction module;
the process interaction module is configured to record information transmission among the tasks in real time and start the information transmission record among the tasks according to the process interaction instruction;
a firmware acquisition module configured to acquire information of firmware, which acquires firmware information according to a firmware acquisition instruction;
the content writing module is configured to write the received information needing to be written into the memory, and write corresponding data into the memory of the MCU according to the content writing instruction;
the content reading module is configured to read information to be read, and reads corresponding content according to a content reading instruction;
the online upgrading module is configured to upgrade the MCU and upgrade the MCU according to an upgrading instruction received from the upper computer;
the tool self-adaptive identification module is configured to identify whether the upper computer has a matched serial port tool or not according to a tool self-adaptive identification instruction of the upper computer;
and the application layer function customizing module is configured to customize the functions of the application program according to the application layer instruction of the upper computer.
7. The cross-platform MCU debugging method of claim 6, wherein the log in the debugging process is printed by a log printing instruction module issuing an instruction to control a log printing module, and the log printing comprises the following steps:
step S901, determining whether the log grades are matched, if so, executing step S902, and if not, executing step S912;
step S902, reading the character of the character string head address in the debugging data packet to be printed;
step S903, determining whether the first character of the address is an "end character", and if the first character of the address is an end character, ending the process; if the first character is not the end character, continuing the next action;
step S904, determining whether the character is '%', if the character is not '%', executing step S910 to save the character; if the character is '%', acquiring the next character;
step S905, determining whether the next character is x or d, if so, performing step S906, and if so, performing step S908;
step S906, acquiring the next parameter;
step S907, converting the acquired parameters into decimal characters and executing step S910;
step S908, acquiring a next parameter;
step S909, converting the acquired parameters into hexadecimal characters and executing step S910;
step S910, saving the character;
step S911, pointing to the next byte, skipping and repeating step S903 until all characters are printed;
step S912, the process ends.
8. The cross-platform MCU debugging method of claim 6, wherein implementing print log level filtering is accomplished by a log level filtering module, comprising the steps of:
step S601, receiving data of an upper computer end;
step S602, the integrity of the data packet is checked, if the data packet is complete, the step S603 is executed, and if the data packet is incomplete, the process is ended;
step S603, analyzing the type of the data packet and putting the data packet into a corresponding grade according to the type;
step S604, selecting ON the log needing to be displayed and selecting OFF the log not needing to be displayed, and then printing;
when the level display of the log module is ON, the log module indicates that the level needs to be printed, and when the level display of the log module is OFF, the log module indicates that the log level does not need to be printed.
9. The cross-platform MCU debugging method of claim 2,
the log grade at least comprises any two of a Debug log, an Info log, an OsMsg log, a Warn log, an ERROR log and an FATAL log;
a Debug log: the system is used for recording the command state in the system debugging process;
the Info log: used for recording an operation state of the current system;
OsMsg log: the system is used for recording an interactive process among processes, and the OsMsg label is marked on a message queue sent by the processes for outputting, so that concerned messages can be filtered out according to a source process, a target process and a command type;
the Warn log: used for warning developers that errors may occur or illegal operations are performed;
ERROR log: informing developers that errors are encountered in the program running process, but the errors are processed in the program, and the functions may be invalid, but the system running is not influenced;
FATAL Log: the system is used for informing a developer that the system encounters serious errors, and the result is program crash and software restart.
CN201910701812.1A 2019-07-31 2019-07-31 Cross-platform MCU debugging method Active CN110457215B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910701812.1A CN110457215B (en) 2019-07-31 2019-07-31 Cross-platform MCU debugging method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910701812.1A CN110457215B (en) 2019-07-31 2019-07-31 Cross-platform MCU debugging method

Publications (2)

Publication Number Publication Date
CN110457215A CN110457215A (en) 2019-11-15
CN110457215B true CN110457215B (en) 2023-01-10

Family

ID=68484288

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910701812.1A Active CN110457215B (en) 2019-07-31 2019-07-31 Cross-platform MCU debugging method

Country Status (1)

Country Link
CN (1) CN110457215B (en)

Families Citing this family (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111505977B (en) * 2020-03-11 2022-05-10 浙江吉利汽车研究院有限公司 Function auxiliary debugging method, device, system and medium
CN112084142B (en) * 2020-08-10 2024-07-12 广州汽车集团股份有限公司 Log storage method and device and T-BOX
CN112685066B (en) * 2020-12-25 2023-07-07 英博超算(南京)科技有限公司 MCU software agent mode development method of heterogeneous platform
CN113297217B (en) * 2021-05-20 2021-12-17 广州光点信息科技有限公司 Data transmission method, device and system
CN114356629B (en) * 2021-12-27 2025-01-28 重庆长安汽车股份有限公司 A method and system for reading controller data based on DoIP
CN114416593A (en) * 2022-01-31 2022-04-29 重庆长安汽车股份有限公司 An Ethernet-based vehicle MCU debugging method
CN114546701B (en) * 2022-02-27 2025-01-14 重庆长安汽车股份有限公司 A method for locating problems in MCU on-site software debugging
CN115221042A (en) * 2022-06-21 2022-10-21 重庆长安汽车股份有限公司 Software debugging method and device for vehicle, electronic equipment and storage medium
CN115481016A (en) * 2022-07-29 2022-12-16 重庆长安汽车股份有限公司 Debugging method, vehicle, communication terminal, debugging system and readable storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105260315A (en) * 2015-11-13 2016-01-20 上海斐讯数据通信技术有限公司 Method for debugging log in embedded system process
CN106568168A (en) * 2016-10-27 2017-04-19 珠海格力电器股份有限公司 Debugging method, debugger and system
CN107305526A (en) * 2016-04-22 2017-10-31 深圳市博巨兴实业发展有限公司 A kind of debugger for microcontroller
CN109902355A (en) * 2019-01-29 2019-06-18 中国航空无线电电子研究所 The method of load data processing unit is laid out in MCU cabinet

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
GB201621776D0 (en) * 2016-12-20 2017-02-01 Undo Ltd Debugging Method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN105260315A (en) * 2015-11-13 2016-01-20 上海斐讯数据通信技术有限公司 Method for debugging log in embedded system process
CN107305526A (en) * 2016-04-22 2017-10-31 深圳市博巨兴实业发展有限公司 A kind of debugger for microcontroller
CN106568168A (en) * 2016-10-27 2017-04-19 珠海格力电器股份有限公司 Debugging method, debugger and system
CN109902355A (en) * 2019-01-29 2019-06-18 中国航空无线电电子研究所 The method of load data processing unit is laid out in MCU cabinet

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
基于SOPC的M8051嵌入式调试器设计;王海光等;《单片机与嵌入式系统应用》;20120601(第06期);全文 *

Also Published As

Publication number Publication date
CN110457215A (en) 2019-11-15

Similar Documents

Publication Publication Date Title
CN110457215B (en) Cross-platform MCU debugging method
CN110457217B (en) A cross-platform MCU debugging device
CN104050080B (en) User space debugs the method and system of linux kernel
CN111756575A (en) Performance analysis method and device for storage server, and electronic equipment
CN109783342A (en) Script debugging method, equipment and computer storage medium
US20130007720A1 (en) Dynamic Isolated Debugging via Class Instrumentation
CN114138644B (en) BMC debugging method and monitoring method, system, device, equipment, and medium
CN108304175B (en) Code file isolation packaging method and device
CN111382048B (en) Management method and device for mobile equipment on true machine test platform
KR102141287B1 (en) Fault injection test method and system for vehicle software based on autosar
CN105589805A (en) Method and device for generating code coverage rate report
CN112729868A (en) Vehicle diagnosis method, device, equipment and medium
CN113342590A (en) NVMe device debugging function implementation method, device, equipment and storage medium
US20240319984A1 (en) Ecu upgrade method and device, and readable storage medium
CN104536870B (en) A kind of process monitoring method and device
CN102193860B (en) Microcontroller online debugging circuit and method as well as microcontroller
CN112230848A (en) A kind of NVM automatic configuration method, apparatus and equipment
CN115809076A (en) ECU software automation integration method and system
CN102063367A (en) Offline analysis method and device for crash program
CN118708488A (en) Virtual simulation method, device and equipment based on Autosar architecture
CN112506871A (en) Automated task management and log management method, system, electronic device and medium
CN108228314A (en) A kind of Virtual prototype error-detecting method based on equipment stipulations
CN110149344B (en) Instrument docking remote configuration system
JP3459898B2 (en) Fault information tracer for embedded systems
CN106897083A (en) A kind of method and device of security sweep

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant
CP03 Change of name, title or address
CP03 Change of name, title or address

Address after: Room 403, block a, 1018 dongsanliqiao Road, Pudong New Area, Shanghai 200125

Patentee after: Heqian Automotive Technology (Shenzhen) Co.,Ltd.

Country or region after: China

Address before: Room 403, block a, 1018 dongsanliqiao Road, Pudong New Area, Shanghai 200125

Patentee before: SHANGHAI HINGE ELECTRONIC TECHNOLOGIES Co.,Ltd.

Country or region before: China