System and method for online upgrading firmware of mcu

By dividing the MCU's FLASH memory into multiple independent program memory areas and using backup RAM and batteries to save state information during power failure, the problem of update interruption caused by power failure during MCU online upgrades is solved, and reliable firmware upgrades are achieved.

CN105740034BActive Publication Date: 2026-05-29SHENZHEN HIGHGREAT TECH DEV CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
SHENZHEN HIGHGREAT TECH DEV CO LTD
Filing Date
2016-04-13
Publication Date
2026-05-29

AI Technical Summary

Technical Problem

In existing technologies, power failures during online MCU firmware upgrades can prevent the update from completing properly, resulting in low reliability.

Method used

The MCU's FLASH storage area is divided into an IAP program storage area and at least two APP program storage areas, which store the currently running program and update data packages respectively. Backup RAM and backup battery are used. When the system loses power, the firmware upgrade status information is written to the backup RAM. After the system is powered on again, the status information is used to determine whether the update is complete and to perform the corresponding operation.

Benefits of technology

This technology enables firmware upgrades to continue even when power is lost, ensuring normal system operation and improving the reliability of firmware upgrades.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN105740034B_ABST
    Figure CN105740034B_ABST
Patent Text Reader

Abstract

The application provides a system and method for MCU online firmware upgrade, comprising an MCU, a backup RAM and a backup battery, wherein the backup RAM is connected with the MCU, and the backup battery is connected with the backup RAM; a FLASH storage area of the MCU comprises an IAP program storage area and at least two APP program storage areas, the two APP program storage areas store a currently running APP program and an update data packet respectively; the backup RAM stores state information of firmware upgrade, and the state information comprises a state flag and a firmware version number. The running program and the update data packet are stored in different APP program storage areas, the codes in each APP program storage area are independent of each other and will not interfere with each other; the program interrupted in updating is continuously updated according to the state information of firmware upgrade in the backup RAM, so that the online firmware upgrade is not affected by system power failure.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of firmware upgrade technology for MCU products, and in particular to a system and method for online firmware upgrade of MCUs. Background Technology

[0002] During the MCU firmware update process, it is necessary to overwrite the MCU code storage area. If the update process is unexpectedly interrupted (such as power failure or cable connection interruption), the MCU will not be able to run the code normally when it restarts.

[0003] Chinese invention patent CN 1752933 A discloses a chip system and its online firmware upgrade method that support online firmware upgrades. The system includes firmware, a program memory storing firmware upgrade programs, a service module, and a data memory connected to the service module that stores service module data. The data memory is also connected to the program memory and is used to store the firmware upgrade program copied from the program memory. The method involves: after receiving an online upgrade command, the firmware copies the online firmware upgrade program stored in the program memory to the data memory; mapping the program space of the MCU in the chip to the data memory; running the online firmware upgrade program in the data memory, and writing the new firmware version into the program memory. This solution utilizes existing RAM or register sets on the chip for online firmware upgrades. However, during the online firmware upgrade process, both the data memory and the program memory cannot function properly. If a power outage occurs during the update process, the firmware upgrade process must be restarted upon the next power-on, resulting in low reliability of the firmware upgrade. Summary of the Invention

[0004] The technical problem to be solved by the present invention is to provide a system and method for online firmware upgrade of MCU with high reliability and the ability to complete firmware upgrade even after power failure.

[0005] To solve the above-mentioned technical problems, the technical solution adopted by the present invention is as follows:

[0006] A system for online firmware upgrade of an MCU includes an MCU, a backup RAM, and a backup battery, wherein the backup RAM is connected to the MCU and the backup battery is connected to the backup RAM;

[0007] The FLASH storage area of ​​the MCU includes an IAP program storage area and at least two APP program storage areas, the two APP program storage areas storing the currently running APP program and the update data package, respectively; the backup RAM stores firmware upgrade status information, the status information including status flags and firmware version number.

[0008] The beneficial effects of the MCU online firmware upgrade system of the present invention are as follows: the FLASH storage area includes multiple APP program storage areas, so that the currently running program and update data package can be stored in different APP program storage areas, and the code in each APP program storage area is independent of each other and will not interfere with each other; the system also includes a backup RAM connected to the MCU and a backup battery connected to the backup RAM, so that the backup battery can be used for temporary power supply when the system loses power; after the system is powered on again, the interrupted program is updated according to the firmware upgrade status information in the backup RAM, so that the firmware online upgrade is not affected by the system power failure.

[0009] A method for online firmware upgrade of an MCU includes:

[0010] The MCU's FLASH is divided into one IAP program storage area and at least two APP program storage areas, with the APP program storage area storing the running APP program.

[0011] The MCU obtains the update data packet, stores the update data packet in the storage area of ​​another APP program, and performs firmware upgrade based on the update data packet;

[0012] If the system loses power, the MCU writes the firmware upgrade status information into the backup RAM through the backup power supply. The status information includes a status flag and a firmware version number.

[0013] After the system power is restored, the MCU queries the backup RAM and determines whether the update is complete based on the status flag;

[0014] If so, then run the latest version of the APP program according to the firmware version number;

[0015] If not, then obtain the update data package again to upgrade the firmware.

[0016] The beneficial effects of the MCU online firmware upgrade method of the present invention are as follows: The FLASH memory is divided into multiple APP program storage areas, allowing the currently running program and update data packages to be stored in different APP program storage areas. This ensures that the code in each APP program storage area is independent and does not interfere with each other, achieving reliable code jumps. After a system power failure, the firmware upgrade status information is written to backup RAM. Upon system power restoration, this status information can be used to determine whether the update is complete. If the update is complete, the latest version of the program is run; if the update is incomplete, the firmware upgrade is performed again. Therefore, the firmware upgrade is not affected by system power failure, achieving reliable firmware upgrades. Attached Figure Description

[0017] Figure 1 The structure of the MCU online firmware upgrade system according to Embodiment 1 of the present invention Figure 1 ;

[0018] Figure 2 The structure of the MCU online firmware upgrade system according to Embodiment 1 of the present invention Figure 2 ;

[0019] Figure 3 The flowchart of the MCU online firmware upgrade method according to Embodiment 2 of the present invention is as follows. Figure 1 ;

[0020] Figure 4 The flowchart of the MCU online firmware upgrade method according to Embodiment 2 of the present invention is as follows. Figure 2 .

[0021] Label Explanation:

[0022] 1. MCU; 11. IAP program storage area; 12. APP program storage area; 13. APP1 program storage area; 14. APP2 program storage area; 2. Backup RAM; 3. Backup battery; 4. Power failure detection circuit; 5. MPU; 6. Host computer. Detailed Implementation

[0023] To explain in detail the technical content, objectives, and effects of the present invention, the following description is provided in conjunction with the embodiments and accompanying drawings.

[0024] The most crucial concept of this invention is to divide the MCU's FLASH into two APP program storage areas, one for storing the currently running program and the other for storing update data packages. After a power failure, a backup power supply is used to power the system, and the firmware upgrade status information is written into the backup RAM. After the system is powered on, the latest version of the firmware is run according to the status information, or if the update fails, the data update package is retrieved again for firmware upgrade.

[0025] The technical terms involved in this invention are explained in Table 1:

[0026] Table 1

[0027]

[0028]

[0029] Please refer to Figure 1 as well as Figure 2 The present invention provides:

[0030] A system for online firmware upgrade of an MCU includes an MCU1, a backup RAM2, and a backup battery3. The backup RAM2 is connected to the MCU1, and the backup battery3 is connected to the backup RAM2. The FLASH storage area of ​​the MCU1 includes an IAP program storage area 11 and at least two APP program storage areas 12, which respectively store the currently running APP program and the update data package. The backup RAM2 stores firmware upgrade status information, including a status flag and a firmware version number.

[0031] Furthermore, it also includes a power-down detection circuit 4, which is connected to the MCU1.

[0032] As can be seen from the above description, the power failure detection circuit 4 detects power failure events and notifies MCU1, thereby enabling timely countermeasures such as starting the backup battery 3 to provide power and writing the firmware upgrade status information into the backup RAM 2.

[0033] Furthermore, it also includes an MPU5, which is connected to the MCU1 via UART transmission.

[0034] Furthermore, it also includes a host computer 6, which is connected to the MCU1 via UART transmission.

[0035] Furthermore, it also includes a host computer 6 and an MPU5. The host computer 6 is connected to the MPU5 via USB transmission, and the MPU5 is connected to the MCU1 via UART transmission.

[0036] As can be seen from the above description, MCU1 can directly obtain data update packets from MPU5 or host computer 6, or it can obtain update data packets from host computer 6 through MPU5.

[0037] Please refer to Figure 3 as well as Figure 4 The present invention also provides:

[0038] A method for online firmware upgrade of an MCU includes:

[0039] S1. Divide the MCU's FLASH into one IAP program storage area and at least two APP program storage areas. The APP program storage area stores the running APP program.

[0040] S2. The MCU obtains the update data packet, stores the update data packet in another APP program storage area, and performs firmware upgrade based on the update data packet;

[0041] S3. If the system loses power, the MCU writes the firmware upgrade status information into the backup RAM through the backup power supply. The status information includes a status flag and a firmware version number.

[0042] S4. After the system power is restored, the MCU queries the backup RAM and determines whether the update is complete based on the status flag.

[0043] S5. If so, run the latest version of the APP program according to the firmware version number;

[0044] S6. If not, then obtain the update data package again to upgrade the firmware.

[0045] Furthermore, the statement "S3. If the system loses power, the MCU writes the firmware upgrade status information into the backup RAM via backup power" specifically means:

[0046] S31. After the power failure detection circuit detects a system power failure, it sends the system power failure information to the MCU.

[0047] S32. After receiving the system power failure information, the MCU writes the firmware upgrade status information into the backup RAM through the backup power supply.

[0048] As can be seen from the above description, the MCU detects power failure information through the power failure detection circuit, thereby activating the backup battery and writing the firmware upgrade status information into the backup RAM. As a result, after the system restores power, it can perform corresponding processing based on the status information in the backup RAM.

[0049] Furthermore, after the S7 firmware upgrade is completed, the APP program storage area for storing update data packets is set to the currently used APP program storage area, and the information of the currently used APP program storage area is stored in the IAP program storage area.

[0050] As can be seen from the above description, when performing the firmware upgrade next time, the update data package can be determined to be placed in which storage area by using the information of the currently used APP program storage area in the IAP program storage area.

[0051] Furthermore, the update data packet is sent from the host computer to the MCU.

[0052] Furthermore, the update data packet and update request are sent from the host computer to the MPU; the MCU obtains the update data packet from the MPU.

[0053] As can be seen from the above description, the MCU can obtain data update packets directly from the MPU or the host computer, or it can obtain update data packets from the host computer through the MPU.

[0054] Please refer to Figure 1 as well as Figure 2Embodiment 1 of the present invention is as follows:

[0055] A system for online firmware upgrade of MCU1 includes MCU1, backup RAM2, power failure detection circuit 4, backup battery 3, MPU5, and host computer 6. The backup RAM2 and power failure detection circuit 4 are both connected to the MCU1, and the backup battery 3 is connected to the backup RAM2. The FLASH storage area of ​​the MCU1 includes an IAP program storage area 11, an APP1 program storage area 13, and an APP2 program storage area 14. The program storage areas are not limited to three; the specific allocation can be adjusted according to actual needs and the size of the FLASH. The APP1 program storage area 13 stores the currently running APP program, and the APP2 program storage area 14 stores update data packets. The backup RAM2 stores firmware upgrade status information. The status information includes: an update flag: set when MCU1 receives external information prompting a firmware update, and reset upon completion; a detection flag: set via an interrupt service routine when a power failure is detected during the update process, and reset upon completion; a status flag: a flag that counts the currently transmitted data, starting from 0 and incrementing by 1 for each received byte, until it equals the update data packet size, at which point the update is considered complete; the program version number in each APP program storage area 12: when the system receives an update command, the version number is first written as 0xffffffff, and the correct version number is filled in after the update (the normal version number is not equal to 0xffffffff); and the size of the update data packet in each APP program storage area 12, etc. The MPU5 is connected to the MCU1 via UART; the host computer 6 is connected to the MPU5 via USB. The host computer 6 can also be directly connected to the MCU1 via UART. Preferably, MCU1 uses the STM32F4 series microcontroller from STMicroelectronics. This series of chips has up to 1MB of on-chip FLASH for storing executable code and up to 4KB of on-chip backup SRAM for storing backup information when power is off. MPU 5 refers to the microprocessor unit, specifically the master device for updating the firmware of the MCU (using RK3288 as an example). It is responsible for sending the data packets received from the host computer to the MCU for firmware upgrade according to the transmission mechanism of this invention. In actual use, it can be any processor capable of this function. The MCU can even directly perform firmware upgrades through the host computer without the need for an intermediate forwarding link. Backup battery 3 is a button battery.

[0056] The working principle of the above-mentioned MCU online firmware upgrade system is as follows: Under normal power supply, MPU5 or host computer 6 sends an update request to MCU1. After receiving the update request, MCU1 requests the update data packet from MPU5 or host computer 6 and stores the obtained update data packet in the APP2 program storage area 14. Then, the firmware upgrade is performed in the APP2 program storage area 14 according to the update data packet. After the firmware upgrade is completed, the APP2 program storage area 14 is set as the currently used APP program storage area 12, and the information of the currently used APP program storage area 12 is stored in the IAP program storage area 11. When the system loses power, that is, when the power supply voltage drops to a certain threshold, the power loss detection circuit 4 outputs a low level to notify MCU1. MCU1 controls the backup power supply to start and writes the firmware upgrade status information into the backup RAM2. After the system restores power supply, MCU1 determines whether the update before the power loss was completed according to the status information in the backup RAM2. If the update is completed, it directly finds the storage address of the latest version of the program and runs the latest version of the program. If the update is not completed, it requests MPU5 or host computer 6 to resend the update data packet and performs the firmware upgrade according to the above-mentioned normal power supply situation.

[0057] Please refer to Figure 3 as well as Figure 4 Embodiment two of the present invention is as follows:

[0058] A method corresponding to the MCU online firmware upgrade system of Embodiment 1 above includes:

[0059] The FLASH of MCU1 is divided into an IAP program storage area 11, an APP1 program storage area 13 and an APP2 program storage area 14. The APP1 program storage area 13 stores the running APP program.

[0060] MCU1 obtains an update request and requests an update program from the host computer 6 or MPU5 based on the update request;

[0061] MCU1 acquires the update data packet and stores it in the APP2 program storage area 14; then it performs a firmware upgrade based on the update data packet; the update request and update data packet can be sent to MCU1 by the host computer 6, or by the MPU5, or by the host computer 6 to the MPU5, and then by the MPU5 to MCU1; specifically, when performing a firmware upgrade, the APP2 program storage area 14 is first erased, then the update data packet is continuously received and verified. If the verification is successful, the update data packet is written to the corresponding location, and the corresponding program is installed to complete the firmware upgrade;

[0062] If the system loses power, the MCU1 writes the firmware upgrade status information into the backup RAM2 via the backup power supply. This status information includes a status flag and a firmware version number. Specifically, after the power failure detection circuit 4 detects a system power failure, it sends the system power failure information to the MCU1. Upon receiving the system power failure information, the MCU1 writes the firmware upgrade status information into the backup RAM2 via the backup power supply. The status information includes: an update flag (set when the MCU1 receives external information indicating a firmware update is needed, reset upon completion); a detection flag (set via an interrupt service routine when a power failure is detected during the update process, reset upon completion); a status flag (a flag that counts the currently transmitted data, starting from 0 and incrementing by 1 for each received byte until it equals the update data packet size, at which point the update is considered complete); program version numbers in each APP program storage area 12 (first write the version number as 0xffffffff when the system receives an update command, then fill in the correct version number after the update is complete; and the size of the update data packet in each APP program storage area 12).

[0063] After the system power is restored, MCU1 queries the backup RAM2 and determines whether the update is complete based on the status flag. Specifically, it executes the program in IAP program storage area 11 and queries whether the program code in APP1 program storage area 13 and APP2 program storage area 14 is complete. If there is any incomplete program code, it is determined that the update is not complete.

[0064] If so, query the version numbers of the programs in APP1 program storage area 13 and APP2 program storage area 14, and run the latest version of the APP program according to the firmware version number;

[0065] If not, the update data packet is retrieved again from MPU5 or host computer 6 for firmware upgrade. Specifically, when MPU5 or host computer 6 retransmits the update data packet, the first data packet in the update data packet contains the current ROM size and version number, and the size is written into the status flag. When transmitting the update data packet, the status flag is incremented by 1 for each byte that is correctly received and successfully written into FLASH, until the status flag is equal to the corresponding ROM size, at which point the update is considered complete.

[0066] After the firmware upgrade is completed, the APP2 program storage area 14 is set as the currently used APP program storage area 12, and the information of the currently used APP program storage area 12 is stored in the IAP program storage area 11.

[0067] In summary, the MCU online firmware upgrade system and method provided by this invention stores the currently running program and the updated program in different APP program memories, ensuring that each program code is independent and does not interfere with the others. Even if an update anomaly occurs, the old program can still run normally. Furthermore, by setting a backup power supply to provide temporary power for a period after a power outage and writing emergency information such as firmware upgrade status information into the backup RAM, the writing of emergency information can be completed before the backup power supply also fails. After the system is powered on again, the status information in the backup RAM can be used to determine whether the firmware update is complete. For firmware that has not been updated, the update data package can be retrieved again for firmware upgrade. Therefore, firmware upgrades are not affected by power outages and can always ensure the normal operation of the program, achieving reliable online firmware upgrades.

[0068] The above description is merely an embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent modifications made based on the content of the present invention specification and drawings, or direct or indirect applications in related technical fields, are similarly included within the patent protection scope of the present invention.

Claims

1. A method for online firmware upgrade of an MCU, applied to a system for online firmware upgrade of an MCU, the system comprising an MCU, a backup RAM, a backup battery, and a power failure detection circuit, wherein the backup RAM is connected to the MCU, the backup battery is connected to the backup RAM, and the power failure detection circuit is connected to the MCU; The FLASH storage area of ​​the MCU includes an IAP program storage area and at least two APP program storage areas, wherein the two APP program storage areas respectively store the currently running APP program and the update data packet; The backup RAM stores firmware upgrade status information, including a status flag, a detection flag, and a firmware version number. The status flag is used to count the currently transmitted data, and the detection flag is used to receive a set instruction from the interrupt service routine during the update process and a reset instruction upon completion of the update. It also includes a host computer and an MPU, the host computer being connected to the MPU via USB transmission, and the MPU being connected to the MCU via UART transmission. The feature is that it includes: The MCU's FLASH is divided into one IAP program storage area and at least two APP program storage areas, with the APP program storage area storing the running APP program. The MCU obtains the update data packet and stores the update data packet in the storage area of ​​another APP program; And perform firmware upgrades based on the updated data package; If the system loses power, the MCU writes the firmware upgrade status information into the backup RAM via the backup battery. Specifically, after the power failure detection circuit detects a system power failure, it sends the system power failure information to the MCU. Upon receiving the system power failure information, the MCU writes the firmware upgrade status information into the backup RAM via the backup battery. The status information includes a status flag, a detection flag, and a firmware version number. When a power failure event is detected during the update process, the detection flag is set by an interrupt service routine and reset when the update is complete. After the system power is restored, the MCU queries the backup RAM and determines whether the update is complete based on the status flag; If so, then run the latest version of the APP program according to the firmware version number; If not, then obtain the update data package again to upgrade the firmware; The update data packet is sent from the host computer to the MPU; The MCU obtains the update data packet from the MPU; after the firmware upgrade is completed, the APP program storage area storing the update data packet is set to the currently used APP program storage area, and the information of the currently used APP program storage area is stored in the IAP program storage area.

2. The method for online firmware upgrade of an MCU according to claim 1, characterized in that, The update data packet is sent from the host computer to the MCU.