Single-chip microcomputer firmware upgrading method and device of IAP protocol and storage medium

By customizing the IAP protocol and data verification mechanism, the problems of interface incompatibility, insufficient data verification and program damage in the existing IAP protocol firmware upgrade method are solved, and a stable, reliable and safe two-way upgrade of the microcontroller firmware is achieved.

CN118626121APending Publication Date: 2024-09-10CHINESE PEOPLES LIBERATION ARMY NO 6905 FACTORY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410752617.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-06-12
Publication Date
2024-09-10

AI Technical Summary

Technical Problem

The existing IAP protocol microcontroller firmware upgrade method has problems such as unsuitable upgrade interfaces, insufficient data verification, high risk of program damage, poor confidentiality, and single upgrade direction, resulting in unstable and unreliable firmware upgrades.

Method used

By customizing the IAP protocol, the frame format, command code, communication port cache data structure and FLASH address are defined to realize data verification and program package download, support two-way upgrade, and perform verification and solidification configuration in each download step to ensure Package correctness and security.

Benefits of technology

It improves the reliability, stability and interface versatility of microcontroller firmware upgrades, prevents program damage, supports two-way upgrades, enhances confidentiality and security, and avoids re-flashing problems caused by upgrade failures.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118626121A
    Figure CN118626121A
Patent Text Reader

Abstract

The invention relates to the technical field of single-chip microcomputers, in particular to a single-chip microcomputer firmware upgrading method and device based on an IAP protocol and a storage medium. According to the method, firmware upgrading of the single-chip microcomputer is carried out by adopting a self-defined IAP protocol, and specifically, a single-chip microcomputer starting program, an application program, an upper computer and a configuration environment during firmware upgrading under the IAP protocol are self-defined; when firmware upgrading is carried out, each step of downloading the starting program or the application program needs to be carried out after the previous step is verified to be correctly completed, and if downloading fails, downloading needs to be carried out again. When the starting program and the application program are skipped, the data of the FLASH address are erased in the application program address space range, so that the success can be ensured when the application program is downloaded for the second time. According to the method, the problem that program data are stolen or interfaces are abused can be effectively prevented, and the confidentiality, the safety, the reliability and the portability of application of the single-chip microcomputer are improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of single-chip microcomputer technology, and in particular to a single-chip microcomputer firmware upgrade method, device and storage medium of an IAP protocol. Background Art

[0002] With the mature application of single-chip microcomputers, various single-chip microcomputer-based devices have blossomed everywhere. However, due to the particularity of single-chip microcomputer systems, many single-chip microcomputer-based devices have already written solidified software (firmware) when they leave the factory. In the scenario where functional requirements are increasingly diverse, it is often necessary to update and upgrade the single-chip microcomputer firmware program. During the update and upgrade process, the firmware needs to be re-burned to achieve the purpose of updating the function. There are currently three main ways to upgrade the firmware of single-chip microcomputers, ICP, ISP, and IAP. Among them, ICP (in-circuit programming) is to use a downloader to directly download and upgrade through JTAG / SWD. ISP (in-system programming) is a method of updating the firmware of a single-chip microcomputer through a serial port. Generally, it is necessary to perform a hardware reset or software reset on the single-chip microcomputer to enter the boot program mode of the single-chip microcomputer system, and then download and upgrade the firmware of the single-chip microcomputer. IAP (in-application programming) is the current mainstream single-chip microcomputer firmware update method, which can remotely upgrade the firmware of the single-chip microcomputer through any communication method, such as serial port, CAN, Ethernet, USB, WIFI, etc.

[0003] ICP needs to use a downloader to download and update the firmware. Generally, it is necessary to disassemble the shell of the device to expose the download port of the microcontroller, or to lead the download port of the microcontroller through a connector and expose it to the shell, and then download it through a downloader. The former takes a long time to disassemble and assemble the device and affects the assembly performance. The latter exposes the download port of the microcontroller and is prone to damage to the microcontroller when encountering external sudden voltage. For ISP, it relies on a specific hardware reset circuit or software, which is not convenient, and the upgrade process is interrupted. The firmware needs to be re-burned before it can be updated using ISP again. The traditional IAP application programming method generally does not have port adaptation, data verification, and file verification functions. If the download fails, it will directly cause the application program (APP) area or the bootloader area of ​​the microcontroller to be damaged. At this time, it needs to be returned to the factory and the bootloader needs to be re-burned before it can be downloaded again. The shortcomings of the traditional IAP upgrade method in programming are mainly reflected in the following points: (1) The upgrade interface is universal. If the upgrade interface is abused by others, the firmware will be reflashed to unexpected results, and the confidentiality is poor; (2) There is no data validity check during the upgrade process, which may cause the microcontroller to crash; (3) There is no App validity check in the upgrade method. If the application is updated to a firmware without an upgrade interface, the startup program code must be reflashed if it is upgraded again; (4) The firmware upgrade interface is single. If the upgrade interface needs to be changed, the underlying code of the startup program can only be modified. (5) The firmware upgrade direction is single. Most of them can only upgrade the application under the startup program, or upgrade the application under the application. Few support two-way upgrades.

[0004] Therefore, in order to avoid the damage of the program of the single-chip microcomputer caused by the traditional IAP upgrade method, the present invention aims to improve the traditional IAP upgrade method to improve the reliability, stability and interface versatility of the single-chip microcomputer firmware upgrade. Summary of the invention

[0005] In view of the deficiencies in the prior art, the present invention provides a single-chip microcomputer firmware upgrade method, device and storage medium based on the IAP protocol, which implements the single-chip microcomputer firmware upgrade through a customized IAP protocol, and has the characteristics of high reliability, good stability and strong interface versatility.

[0006] The present invention discloses a single-chip microcomputer firmware upgrade method of an IAP protocol, comprising the following steps:

[0007] S1. Define the configuration environment based on the IAP protocol when the MCU is upgrading the firmware, and initialize the MCU;

[0008] S2. Run the MCU under the configuration environment. If the interrupt receives data under the configuration environment, determine whether the data passes the IAP protocol verification. If it passes the IAP protocol verification, execute the package download;

[0009] S3. Determine whether the downloaded program package can receive the debugging frame after installation. If so, fix the configuration. Otherwise, repeat step S2.

[0010] Furthermore, the configuration environment under the IAP protocol includes: defining the frame format of the IAP download protocol, the command code of the IAP download protocol, the communication port buffer data structure, the FLASH address and the starting address of the interrupt vector table.

[0011] Specifically, the frame format of the IAP download protocol includes a frame header, a command code, a data area, a check area and a frame tail; the instruction code of the IAP download protocol includes a download program, a check program, a jump program, a clear configuration, a fixed configuration and a software reset; the communication port cache data structure includes a cache data structure of a communication port type, a port number, a data length, a data content and a transmission identifier; the FLASH address includes a boot program address and an application program address, which are used for the boot program and the application program respectively; the interrupt vector table starting address includes the interrupt vector table starting address of the boot program and the interrupt vector table starting address of the application program, wherein the interrupt vector table starting address of the boot program points to the boot program starting address, and the interrupt vector table starting address of the application program points to the application program starting address.

[0012] Further, in step S1, when initializing the single-chip microcomputer, it includes: initializing all ports of the single-chip microcomputer, including but not limited to serial ports, CAN ports or Ethernet ports, each port is instantiated accordingly according to the communication port cache data structure, and then a public communication port cache address is instantiated; a pointer to a default IAP communication port cache address is defined to point to the public communication port cache address.

[0013] Furthermore, in step S2, running the single-chip microcomputer under the configuration environment includes: downloading a self-defined startup program under the IAP protocol to the single-chip microcomputer in advance through the ICP or ISP mode, and running the single-chip microcomputer from the starting address of the startup program.

[0014] Further, the program package in step S2 includes: a startup program update package of the startup program, an application program and an application program update package of the application program. It is worth noting that the application program update package can only be downloaded after the application program has completed the solidification configuration, that is, the application program must exist before subsequent application program upgrades are possible.

[0015] Further, in step S2, if the interrupt receives data in the configuration environment, it is determined whether the data passes the IAP protocol verification, and if the data passes the IAP protocol verification, the program package download is executed, including:

[0016] S21. During the operation of the single-chip microcomputer, the data received by the interruption is copied to the public communication port buffer address, and the transmission flag is set to 1.

[0017] S22, instantiate the current IAP communication port cache address of a data, and synchronize the current IAP communication port cache address with the default IAP communication port cache address; if the data comes from different ports and is data under the configuration environment, point the default IAP communication port cache address to the current IAP communication port cache address. It is worth noting here that the data here in the main loop task not only needs to satisfy that the port type or port number in the current IAP communication port cache data is inconsistent with the port type or port number of the default IAP communication port cache data, but also needs to satisfy that it is data under the IAP protocol, otherwise the default IAP communication port cache address cannot be pointed to the current IAP communication port cache address.

[0018] S23, polling the data identifier of the default IAP communication port cache address in real time, if the transmission flag is 1, copying the data content in the default IAP communication port cache address to the current IAP communication port cache address, and clearing the transmission flag.

[0019] S24, determine whether the data is a protocol frame for upgrading the firmware of the single-chip microcomputer, if so, execute one or more instructions in the software reset, clear configuration or jump program according to the type of program package to be downloaded. It is worth noting here that the judgment of whether the data is a protocol frame for upgrading the firmware of the single-chip microcomputer means that the content corresponding to the protocol frame is one of the download startup program update package, application program or application program update package. When judging, one or more instructions in the execution software reset, clear configuration or jump program are executed according to the final direction of the protocol frame. Among them, if the program package to be downloaded is an application program, execute the clear configuration instruction: the single-chip microcomputer clears the value saved in the application configuration address, and completely clears the program segment starting from the application program address in the FLASH address. If the program package to be downloaded is a startup program update package, execute the software reset and clear configuration instructions, clear the value saved in the application configuration address, and completely clear the program segment starting from the startup program address in the FLASH address; if the program package to be downloaded is an application program update package, it is necessary to clear the application configuration address, then jump the program to the application program, then clear the value of the application configuration address, and clear the program segment starting from the application program start address.

[0020] S25, execute the download program instruction, the single chip microcomputer receives the program package under the IAP protocol from the host computer in sequence, and writes the program package under the IAP protocol into the FLASH address space. If the program package is a startup program or a startup program update package, it is written to the startup program address, and if it is an application or an application update package, it is written to the application address.

[0021] Further, in step S3, it is determined whether the downloaded program package can receive the debugging frame after installation, and if so, the configuration is solidified, otherwise, step S2 is repeated, including:

[0022] S31, read out the data contents of the program package written into the FLASH address space in sequence, and perform data verification under the IAP protocol by the host computer. If the data verification passes, proceed to step S32; if the data verification fails, repeat step S2;

[0023] S32, if the verified program package can be executed and receive the debugging signal after jumping to the program corresponding to the downloaded program package, then the configuration is solidified, otherwise step S2 is repeated. It is worth noting here that if the solidified program package is an application program at this time, and the solidification configuration operation is successfully executed, it means that the application program has an interface for providing secondary in-application programming, and the single-chip microcomputer automatically jumps from the startup program to the application program after powering off and powering on again.

[0024] Furthermore, in step S31, the data contents of the program package written into the FLASH address space are read out in sequence, and the host computer performs data verification under the IAP protocol, including: reading out the data contents of the program package written into the FLASH address space in sequence, returning corresponding data to the host computer according to the frame format under the IAP protocol, and performing verification by the host computer.

[0025] In order to achieve the above object, the present invention also provides a single-chip microcomputer firmware upgrade device of IAP protocol, which comprises:

[0026] The IAP protocol definition module is used to define the IAP protocol for the environment configuration when the MCU upgrades the firmware and initialize the MCU;

[0027] The first judgment module is used to judge whether the data passes the IPA protocol verification, and if it passes the IAP protocol verification, the program package is downloaded;

[0028] The second judgment module is used to judge whether the downloaded program package can receive the debugging frame after installation.

[0029] In order to achieve the above object, the present invention also provides a storage medium storing a plurality of computer instructions for executing the above-mentioned single-chip microcomputer firmware upgrade method of the IAP protocol.

[0030] The technical principle of the present invention is: first customize the MCU firmware upgrade environment under the IAP protocol, and then customize the bootloader, application (APP) and host computer under the IAP protocol. When performing a firmware upgrade, each download bootloader or application step needs to be verified after the previous step is completed correctly before proceeding to the next step. If the download fails, it needs to be re-downloaded. When jumping to the bootloader and application, the data of the FLASH address is erased within the application address space range, so that when the application is downloaded for the second time, success can be ensured.

[0031] Compared with the prior art, the present invention has the following beneficial effects: a startup program, an application program and a host computer using a custom protocol can effectively prevent the problem of program data being stolen or the interface being abused; an IAP port adaptation method that automatically adapts to port types and port numbers can be adopted, and when the startup program detects that the port type or port number has changed, the port currently receiving the IAP protocol can be automatically directed to the default port, so as to achieve the purpose of dynamically identifying the valid IAP communication port; bidirectional upgrades from the startup program to the application program, the application program to the application program, and the application program to the startup program are supported, and the upgrade process is controllable. After an upgrade fails, it can be directly upgraded again without re-downloading the startup program, thereby improving the confidentiality, security, reliability and portability of the single-chip microcomputer application. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] In order to more clearly illustrate the technical solution of the present invention and facilitate further understanding of the technical effects, technical features and purposes of the present invention, the present invention is described in detail below in conjunction with the accompanying drawings. The accompanying drawings constitute an essential part of the specification and are used together with the embodiments of the present invention to illustrate the technical solution of the present invention, but do not constitute a limitation to the present invention.

[0033] Figure 1 A flow chart of the method described in the present invention;

[0034] Figure 2 This is a schematic diagram of the frame format of the IAP download protocol in the method described in the present invention;

[0035] Figure 3 A schematic diagram of a flow chart of an embodiment of the present invention;

[0036] Figure 4 This is a schematic diagram of the steps in the first embodiment of the present invention;

[0037] Figure 5 This is a schematic diagram of the steps in the second embodiment of the present invention;

[0038] Figure 6 This is a schematic diagram of the steps in Example 3 of the present invention. DETAILED DESCRIPTION

[0039] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. Of course, the specific embodiments described below are only intended to explain the technical solutions of the present invention, rather than to limit the present invention. In addition, the parts described in the embodiments or the accompanying drawings are only examples of the relevant parts of the present invention, rather than the entirety of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those of ordinary skill in the art should naturally belong to the protection scope of the present invention.

[0040] Embodiment 1

[0041] like Figure 1-4 As shown in the present invention, a single-chip microcomputer firmware upgrade method of the IAP protocol is proposed through the following embodiments, including:

[0042] S1. Define the configuration environment based on the IAP protocol when the MCU is upgrading the firmware, and initialize the MCU;

[0043] S2. Run the MCU under the configuration environment. If the interrupt receives data under the configuration environment, determine whether the data passes the IAP protocol verification. If it passes the IAP protocol verification, execute the package download;

[0044] S3. Determine whether the downloaded program package can receive the debugging frame after installation. If so, fix the configuration. Otherwise, repeat step S2.

[0045] In this embodiment, the configuration environment under the IAP protocol includes: defining the frame format of the IAP download protocol, the command code of the IAP download protocol, the communication port buffer data structure, the FLASH address and the starting address of the interrupt vector table.

[0046] In this embodiment, if Figure 2As shown, the frame format of the IAP download protocol includes a frame header, which is used to distinguish other normal protocols; a command code, which distinguishes the operation commands of the download protocol; a data area, which encapsulates the key data frame of the Bin file of the program package; a check area, which verifies the frame data; and a frame tail, which marks the end of the protocol frame. The instruction codes of the IAP download protocol include download program, check program, jump program, clear configuration, solidify configuration and software reset. The communication port cache data structure includes the cache data structure of the communication port type, port number, data length, data content, and transmission identifier. The FLASH address includes the startup program address and the application program address, which are used for the startup program and the application program respectively; specifically, a space of appropriate size is opened at the entry address of the microcontroller and divided into two sub-areas, one of which is used as the startup program and the other is used as the application program. The application start address is defined in the startup program, which is used as the jump entry address of the application. The offset size of the application start address is determined by the size of the startup program and the sector size of the microcontroller FLASH. The fixed configuration parameter address is defined, which is used to read the parameter address that is fixed after the application successfully runs. The startup program start address is defined in the application, which is used as the jump entry address of the startup program, and the fixed configuration parameter address is defined. This address is used to write the parameter address that is fixed after the application successfully runs. Optionally, a software reset address is defined, which is used to write the address of whether the software reset instruction is received. The interrupt vector table start address includes the interrupt vector table start address of the startup program and the interrupt vector table start address of the application, where the interrupt vector table start address of the startup program points to the startup program start address, and the interrupt vector table start address of the application points to the application start address.

[0047] In this embodiment, in step S1, when initializing the single-chip microcomputer, it includes: initializing all ports of the single-chip microcomputer, including but not limited to serial ports, CAN ports or Ethernet ports, each port is instantiated accordingly according to the communication port cache data structure, and then a public communication port cache address is instantiated; a pointer to a default IAP communication port cache address is defined to point to the public communication port cache address.

[0048] In step S2 of this embodiment, running the single-chip microcomputer under the configuration environment includes: downloading a self-defined startup program under the IAP protocol to the single-chip microcomputer in advance through the ICP or ISP method, and running the single-chip microcomputer from the starting address of the startup program,

[0049] It is worth noting that the program package in step S2 includes: a startup program update package of a startup program, an application program, and an application program update package of the application program. However, in this embodiment, the program package is an application program.

[0050] In step S2 of this embodiment, if the data in the configuration environment is received, it is determined whether the data passes the IAP protocol verification. If the data passes the IAP protocol verification, the program package download is executed, including:

[0051] S21. During the operation of the single-chip microcomputer, the data received by the interruption is copied to the public communication port buffer address, and the transmission flag is set to 1.

[0052] S22, instantiate the current IAP communication port cache address of a data, and synchronize the current IAP communication port cache address with the default IAP communication port cache address; if the data comes from different ports and is data under the configuration environment, point the default IAP communication port cache address to the current IAP communication port cache address. It is worth noting here that the data here in the main loop task not only needs to satisfy that the port type or port number in the current IAP communication port cache data is inconsistent with the port type or port number of the default IAP communication port cache data, but also needs to satisfy that it is data under the IAP protocol, otherwise the default IAP communication port cache address cannot be pointed to the current IAP communication port cache address.

[0053] S23, polling the data identifier of the default IAP communication port cache address in real time, if the transmission flag is 1, copying the data content in the default IAP communication port cache address to the current IAP communication port cache address, and clearing the transmission flag.

[0054] S24, determine whether the data is a protocol frame for upgrading the firmware of the single-chip microcomputer. If so, execute one or more instructions in the software reset, clear configuration or jump program according to the type of program package to be downloaded. It is worth noting here that the judgment of whether the data is a protocol frame for upgrading the firmware of the single-chip microcomputer means that the content corresponding to the protocol frame is one of the download startup program update package, application program or application program update package. When judging, execute one or more instructions in the software reset, clear configuration or jump program according to the final direction of the protocol frame. Of course, in the present embodiment, the downloaded program package is an application program. At this time, the clear configuration instruction is executed: the single-chip microcomputer clears the value saved in the application program configuration address, and completely clears the program segment starting from the application program address in the FLASH address.

[0055] S25, execute the download program instruction, the single chip microcomputer sequentially receives the program packages under the IAP protocol from the host computer, and writes the program packages under the IAP protocol into the FLASH address space. In this embodiment, it is written into the application program address.

[0056] In step S3 of this embodiment, it is determined whether the downloaded program package can receive the debugging frame after installation. If so, the configuration is fixed. Otherwise, step S2 is repeated, including:

[0057] S31, read out the data contents of the program package written into the FLASH address space in sequence, and perform data verification under the IAP protocol by the host computer. If the data verification passes, proceed to step S32; if the data verification fails, repeat step S2;

[0058] S32, if the verified program package can be executed and receive the debugging signal after jumping from the startup program to the application program, then the configuration is solidified, otherwise repeat step S2. It is worth noting here that the successful execution of the solidification configuration operation indicates that the application program has an interface for providing secondary in-application programming, and the single-chip microcomputer automatically jumps from the startup program to the application program after power-off and power-on reset.

[0059] In step S31 of the present embodiment, the data contents of the program package written into the FLASH address space are read out in sequence, and the host computer performs data verification under the IAP protocol, including: reading out the data contents of the program package written into the FLASH address space in sequence, returning the corresponding data to the host computer according to the frame format under the IAP protocol, and the host computer performs verification.

[0060] Embodiment 2

[0061] like Figure 1 , 3 5, the following description is made by taking the downloaded program package as the startup program update package as an example. The difference between this embodiment and the first embodiment is that in step S24, after determining whether the data is a protocol frame for upgrading the single-chip firmware, the program package to be downloaded is different.

[0062] In step S24, if the data is determined to be a protocol frame for upgrading the MCU firmware, and the content corresponding to the protocol frame is to update the startup program. At this time, the MCU executes the software reset and clear configuration instructions. Specifically, the MCU clears the value saved in the software reset address and writes the value of 1 to the software reset address; the MCU reads the value of the software reset address, and if the value of the software reset address is 1, the program segment starting from the startup program start address in the FLASH address is cleared, and the value of 0 is written to the software reset address.

[0063] Then execute the download program instruction in step S25: the single-chip microcomputer receives program packages under the IAP protocol from the host computer in sequence, and writes them into the startup program address space of the single-chip microcomputer FLASH.

[0064] After downloading is completed, the verification program instructions in step S31 are executed: the data contents of the program package written into the FLASH address space are read out in sequence, and the host computer performs data verification under the IAP protocol. If the data verification passes, step S32 is performed; if the data verification fails, step S2 is repeated.

[0065] Step S32, jump from the application to the startup program. After the program jumps, if the program is executed normally and a debug frame can be received, it means that the startup program jumps successfully and the startup program is upgraded successfully. Otherwise, the operation of step S2 is re-executed.

[0066] Embodiment 3

[0067] like Figure 1 , 3 6, the following is an example of the downloaded program package being an application program update package. The difference between this embodiment and the first or second embodiment is that in step S24, after determining whether the data is a protocol frame for upgrading the single-chip firmware, the program package to be downloaded is different.

[0068] In step S24, if the data is judged to be a protocol frame for upgrading the firmware of the single-chip microcomputer, and the content corresponding to the protocol frame is to update the application. At this time, the single-chip microcomputer needs to clear the application configuration address, then jump the program to the application, then clear the value of the application configuration address, and clear the program segment starting from the application start address. Specifically, execute the clear configuration instruction: clear the value saved in the application configuration address; execute the jump program instruction: the application jumps to the startup program. After the jump program, if the program executes normally and can receive the debugging signal, it means that the startup program jumps successfully; execute the clear configuration instruction: clear the value saved in the application configuration address, and completely clear the program segment starting from the application start address in the FLASH address.

[0069] Then execute the download program instruction in step S25: the single-chip microcomputer sequentially receives program packages under the IAP protocol from the host computer, and writes them into the application program address space of the single-chip microcomputer FLASH.

[0070] After downloading is completed, the verification program instructions in step S31 are executed: the data contents of the program package written into the FLASH address space are read out in sequence, and the host computer performs data verification under the IAP protocol. If the data verification passes, step S32 is performed; if the data verification fails, step S2 is repeated.

[0071] Step S32, jump from the startup program to the application program. After the jump, if the program is executed normally and the debugging signal can be received, it means that the application program is updated successfully. Finally, the solidification configuration instruction is executed, otherwise the operation of step S2 is repeated.

[0072] On the other hand, in order to achieve the above-mentioned purpose, the present invention also provides a single-chip microcomputer firmware upgrade device of the IAP protocol, which includes: an IAP protocol definition module, used to define the IAP protocol of the environment configuration when the single-chip microcomputer upgrades the firmware, and initialize the single-chip microcomputer; a first judgment module, used to determine whether the data passes the IPA protocol verification, and if it passes the IAP protocol verification, execute the program package download; a second judgment module, used to determine whether the downloaded program package can receive a debug frame after installation.

[0073] On the other hand, in order to achieve the above-mentioned purpose, the present invention also provides a storage medium storing a number of computer instructions for executing the above-mentioned single-chip microcomputer firmware upgrade method of the IAP protocol.

[0074] It should be noted that the above embodiments are only for more clearly illustrating the technical solutions of the present invention. Those skilled in the art will understand that the implementation methods of the present invention are not limited to the above contents, and obvious changes, replacements or substitutions based on the above contents do not exceed the scope of the technical solutions of the present invention; other implementation methods will naturally fall within the scope of the present invention without departing from the concept of the present invention.

Claims

1. A method for upgrading the firmware of a single-chip microcomputer using an IAP protocol, characterized in that: include: S1. Define the configuration environment based on the IAP protocol when the MCU is upgrading the firmware, and initialize the MCU; S2, running the single-chip microcomputer under the configuration environment, if the interrupt receives the data under the configuration environment, determining whether the data passes the IAP protocol verification, and executing the program package download if the data passes the IAP protocol verification; S3. Determine whether the downloaded program package can receive a debugging frame after installation. If so, fix the configuration. Otherwise, repeat step S2.

2. The method for upgrading the MCU firmware of the IAP protocol according to claim 1, characterized in that: The IAP protocol includes: The frame format of the IAP download protocol, the command code of the IAP download protocol, the communication port cache data structure, the FLASH address and the starting address of the interrupt vector table; The frame format of the IAP download protocol includes a frame header, a command code, a data area, a check area and a frame tail; The instruction codes of the IAP download protocol include downloading program, checking program, jumping program, clearing configuration, solidifying configuration and software reset; The communication port cache data structure includes a cache data structure of the communication port type, port number, data length, data content, and transmission identifier; The FLASH address includes a startup program address and an application program address; The interrupt vector table starting address includes the interrupt vector table starting address of the startup program and the interrupt vector table starting address of the application program, wherein the interrupt vector table starting address of the startup program points to the startup program starting address, and the interrupt vector table starting address of the application program points to the application program starting address.

3. The method for upgrading the firmware of a single-chip microcomputer using the IAP protocol as claimed in claim 2, characterized in that: The initialization of the single chip microcomputer comprises: Initialize the ports of the single-chip microcomputer, instantiate each port accordingly according to the communication port cache data structure, and then instantiate a common communication port cache address; define a pointer of a default IAP communication port cache address to point to the common communication port cache address.

4. The method for upgrading the firmware of a single-chip microcomputer using the IAP protocol as claimed in claim 3, characterized in that: Said running of the single-chip microcomputer under said configuration environment comprises: The self-defined startup program under the IAP protocol is downloaded to the single-chip microcomputer through the ICP or ISP mode, and the single-chip microcomputer is run from the starting address of the startup program.

5. The method for upgrading the MCU firmware of the IAP protocol according to claim 4, characterized in that: The package includes: A startup program update package of the startup program, an application program, and an application program update package of the application program; The application update package can be downloaded only after the application has completed solidification configuration.

6. The method for upgrading the MCU firmware of the IAP protocol according to claim 5, characterized in that: The interruption of receiving data under the configuration environment determines whether the data passes the IPA protocol verification, and if the data passes the IAP protocol verification, executes the program package download, including: S21, copying the data received by the interruption to the common communication port buffer address, and setting the transmission flag to 1; S22, instantiate a current IAP communication port cache address of the data, and synchronize the current IAP communication port cache address with the default IAP communication port cache address; if the data comes from different ports and is data under the configuration environment, point the default IAP communication port cache address to the current IAP communication port cache address; S23, polling the data identifier of the default IAP communication port cache address in real time, and if the transmission flag is 1, copying the data content in the default IAP communication port cache address to the current IAP communication port cache address, and clearing the transmission flag; S24, determining whether the data is a protocol frame for upgrading the firmware of the single-chip microcomputer, and if so, executing one or more instructions in software reset, clear configuration or jump program according to the type of program package to be downloaded; S25, execute the download program instruction, the single chip microcomputer receives the program packages under the IAP protocol from the host computer in sequence, and writes the program packages under the IAP protocol into the FLASH address space.

7. The method for upgrading the MCU firmware of the IAP protocol according to claim 6, characterized in that: The step of determining whether the downloaded program package can receive a debugging frame after installation, and if so, solidifying the configuration, otherwise, repeating step S2, comprises: S31, the data contents of the program package written into the FLASH address space are read out in sequence, and the host computer performs data verification under the IAP protocol. If the data verification passes, step S32 is performed; if the data verification fails, step S2 is repeated; S32: If the verified program package can be executed and receive debugging signals after jumping to the program corresponding to the downloaded program package, the configuration is solidified; otherwise, step S2 is repeated.

8. The method for upgrading the MCU firmware of the IAP protocol according to claim 7, characterized in that: The data contents of the program packages written into the FLASH address space are read out in sequence, and the host computer performs data verification under the IAP protocol, including: The data contents of the program packages written into the FLASH address space are read out in sequence, and the corresponding data are returned to the host computer according to the frame format under the IAP protocol, and verified by the host computer.

9. A single-chip microcomputer firmware upgrade device based on the IAP protocol, characterized in that: include: The IAP protocol definition module is used to define the IAP protocol for the environment configuration when the MCU upgrades the firmware and initialize the MCU; A first judgment module is used to judge whether the data passes the IPA protocol verification, and if it passes the IAP protocol verification, execute the program package download; The second judgment module is used to judge whether the downloaded program package can receive a debugging frame after installation.

10. A storage medium, characterized in that: A plurality of computer instructions are stored, and are used to execute the single-chip computer firmware upgrade method of the IAP protocol according to any one of claims 1 to 8.