Effective embedded single-chip microcomputer software upgrading mechanism
By designing the startup module, upgrade module and recovery module in the embedded microcontroller, combining partition management and weighted average algorithm to dynamically evaluate the resource status, the stability problem of the embedded microcontroller in the case of resource tightness is solved, and a safe and reliable software upgrade and recovery is achieved.
Patent Information
- Application Number
- CN202510426020.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-07
- Publication Date
- 2025-08-08
AI Technical Summary
The existing embedded microcontroller software upgrade mechanism lacks flexibility and intelligence in the face of tight resources, which may lead to unstable and even crashes in equipment, especially when upgrading or recovery operations are performed when high loads or low battery power.
An embedded microcontroller software upgrade mechanism including start-up module, upgrade module and recovery module is designed. Through partition management and flag bit control program jump, combined with verification algorithm and weighted average algorithm, the device resource status is dynamically evaluated to ensure that the upgrade is carried out at low load and data is restored from the backup partition if necessary.
Improve the stability and recovery capabilities of embedded devices under limited resources, avoid system overload, and ensure the safety and reliability of upgrade and recovery operations.
Smart Images

Figure CN120447922A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of embedded single-chip computers, and more particularly to an effective embedded single-chip computer software upgrade mechanism. Background Art
[0002] With the widespread adoption of embedded microcontrollers in various smart devices, device stability and upgrade security have become key design considerations. Embedded systems often face resource constraints, such as battery life, CPU load, memory, and bandwidth. These resource constraints can lead to system performance degradation or even crashes, especially during software upgrades. Existing embedded system software upgrade mechanisms have limitations. In resource-constrained environments, blindly performing upgrades can disrupt device operation or even cause upgrade failures.
[0003] Most current solutions rely on fixed upgrade timings and simple rollback mechanisms, lacking flexibility and intelligence. When a device is under heavy load or has low battery, continuing with an upgrade or recovery operation often leads to system instability or even prevents the device from recovering to normal. Therefore, there is an urgent need for a mechanism that can intelligently assess device resource status and dynamically adjust upgrade timing.
[0004] In view of the above problems, the present invention proposes a solution. Summary of the Invention
[0005] In order to overcome the above-mentioned defects of the prior art, the embodiments of the present invention provide an effective embedded single-chip microcomputer software upgrade mechanism to solve the problems raised in the above-mentioned background technology.
[0006] To achieve the above object, the present invention provides the following technical solutions:
[0007] In a preferred embodiment, it includes: a startup module, an upgrade module, a recovery module and a data storage module, and the modules are signal-connected;
[0008] The data storage module is used to store all data in the processing process;
[0009] The startup module is mainly used to provide support for external communication interfaces, receive and identify external firmware data, and use flags to record the validity of the APP partition and BACKUP partition;
[0010] The upgrade module is mainly used to transmit data in blocks using the XMODEM communication protocol, and combines the CRC32 verification algorithm to ensure the integrity of the transmitted external firmware data. The flag bit is used to dynamically adjust the program running status. After the verification is completed, the FLASH erase and write operation is used to update the APP partition. An intelligent upgrade scheduling mechanism is designed to determine the optimal time for the upgrade.
[0011] The recovery module is mainly used to use the BACKUP partition as a backup area, copy device data from the BACKUP partition to the APP partition, and use the same verification algorithm to verify the integrity of the APP partition after copying. An intelligent recovery time window mechanism is also designed to dynamically evaluate the priority of recovery tasks.
[0012] In a preferred embodiment, the FLASH of the embedded single-chip computer is divided into: BOOT partition, APP partition, BACKUP partition, APPValid partition, and BACKUPValid partition, among which the BOOT partition function realizes the upgrade of the APP part; the APP partition is the implementation part of the main functions of the embedded product; the BACKUP partition serves as the backup area for the new software to be upgraded; the APPValid partition marks whether the APP area code is valid; and the BACKUPValid partition marks whether the upgrade backup area code is valid.
[0013] In a preferred embodiment, after the embedded single-chip microcomputer software is started, the code of the BOOT partition is executed to check whether there is external firmware data sent through the communication interface UART, USB, and Wi-Fi. When there is external firmware data, the external firmware data is transferred to the upgrade module; when there is no external firmware data, the flag status APPValid flag stored in the FLASH is checked to see if it is valid. When the APPValid flag is valid, the program jumps to the APP partition; when the APPValid flag is invalid, the code of the BACKUPValid flag is checked to see if it is valid. When the BACKUPValid flag is valid, the program enters the recovery module. When the BACKUPValid flag is invalid, the program enters the safe mode.
[0014] In a preferred embodiment, the upgrade module receives external firmware data through the communication interface and writes it into the BACKUP partition block by block. After the reception is completed, the upgrade module sets the APPValid flag to invalid, calculates the firmware check value, and compares it with the received check value. When the comparison results are consistent, the BACKUPValid flag is set to valid and prepares to update the APP partition: erase the old device data in the APP partition, and copy the firmware of the BACKUP partition block by block to the APP partition; after the copy is completed, perform an integrity check on the APP partition: when the check passes, set the APPValid flag to valid and complete the upgrade; when the check fails, keep APPValid invalid; when the comparison results are inconsistent, set the BACKUPValid flag to invalid.
[0015] In a preferred embodiment, the operating status data of the embedded single-chip microcomputer software is collected in real time, including: CPU load, memory usage, and communication bandwidth;
[0016] Use performance counters to record the proportion of CPU idle time, using the formula: CPU load = 1 - (idle time / total time). Call the memory allocation interface malloc() or the RTOS heap usage statistics interface to obtain the ratio of currently allocated memory to total memory. Set data transmission statistics counters on the communication interfaces (UART, SPI, I2C, or network interfaces) to calculate the amount of data transmitted per second and determine the bandwidth utilization rate.
[0017] The upgrade module uses a weighted average algorithm to evaluate the collected running status data of the embedded MCU software and calculates the real-time load value F of the embedded MCU software. The specific formula is: F = Qc × Fcpu + Qn × Fn + Qtx × Ftx, where F represents the real-time load value of the embedded MCU software, Qc represents the weight value of the CPU load, Fcpu represents the CPU load, Qn represents the weight value of the memory usage rate, Fn represents the memory usage rate, Qtx represents the weight value of the communication broadband usage, and Ftx represents the communication broadband usage rate; and sets a load threshold Yf, compares the real-time load value F of the embedded MCU software with the load threshold Yf, and automatically triggers the upgrade operation when the real-time load value F of the embedded MCU software is less than or equal to the load threshold Yf; when the real-time load value F of the embedded MCU software is greater than the load threshold Yf, the upgrade is postponed.
[0018] In a preferred embodiment, the recovery module first checks the flag status. When it is detected that the APPValid flag is invalid, the BACKUPValid flag is checked. If the BACKUPValid flag is valid, the old device data of the APP partition is erased, the data of the BACKUP partition is copied block by block to the APP partition, and the restored APP partition content is verified to be complete and valid. If the verification result is valid, it means that the recovery is successful. At this time, the APPValid flag is set to valid, allowing the jump to the APP partition to run. When the verification result is invalid, it means that the recovery has failed, the APPValid flag and the BACKUPValid flag are kept invalid, and the safe mode is entered.
[0019] In a preferred embodiment, the power management chip of the embedded single-chip microcomputer is used to collect the real-time status data of the embedded single-chip microcomputer battery, including: voltage, current, and remaining power. Among them, the built-in power meter calculates the remaining capacity of the battery by the cumulative current integration technology, specifically according to the formula , where I(t) represents the real-time current and the integral value represents the battery power consumption;
[0020] The recovery module determines the recovery task priority P by combining the real-time battery status data with the embedded MCU software load value F, and performing weighted average calculation. The specific formula is: P = Qf × (1-F) + Qv × V + Qi × I + Qsoc × SoC, where Qf represents the weight value of the embedded MCU software load value, Qv represents the weight value of the battery voltage, Qi represents the weight value of the battery current, and Qsoc represents the weight value of the remaining battery power, and Qf + Qv + Qi + Qsoc = 1 is satisfied. An execution threshold Yz is set. When the recovery task priority P is greater than the execution threshold Yz, the recovery task can be executed immediately. When the recovery task priority P is less than or equal to Yz, the intelligent recovery time window mechanism will postpone the recovery task until the resource management of the embedded MCU returns to a stable state.
[0021] In a preferred embodiment,
[0022] Step 1: Divide the FLASH of the embedded MCU into multiple functional areas, manage the program validity through flags, and dynamically switch to the appropriate program or recovery mode;
[0023] Step 2: Receive and verify external firmware data through the communication interface, update the APP partition after ensuring the integrity of the external firmware data, and trigger the upgrade under low load state;
[0024] Step 3: When the APP partition is damaged, restore from backup data, combine battery status and real-time load assessment to intelligently schedule upgrade and recovery operations.
[0025] The present invention discloses an effective embedded single-chip microcomputer software upgrade mechanism, which relates to the technical field of embedded single-chip microcomputers and is used to solve the problems of device stability and security of the upgrade process; it includes: a startup module, an upgrade module, a recovery module and a data storage module, and the modules are signal-connected. The startup module is responsible for receiving external firmware data and managing the jump of the program according to the flag bit. The upgrade module uses a verification algorithm to ensure the integrity of the firmware data and perform safe upgrade operations. The recovery module is used to ensure system recovery by restoring data from the backup partition when the upgrade fails or the device is abnormal. To avoid system overload, the intelligent upgrade scheduling mechanism monitors the real-time load of the embedded single-chip microcomputer, uses a weighted average algorithm to evaluate the system resource status, determines the timing of the upgrade and recovery operations, and ensures that they are executed when the device load is low. This mechanism effectively improves the stability and recovery capabilities of embedded devices under conditions of limited resources. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 This is a structural flow chart of an effective embedded single-chip microcomputer software upgrade mechanism of the present invention.
[0027] Figure 2The figure is a schematic diagram of the operation of an effective embedded single-chip computer software upgrade method of the present invention.
[0028] Figure 3 This is a schematic diagram of the FLASH partition of the embedded microcontroller; DETAILED DESCRIPTION
[0029] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0030] The present invention is collected.
[0031] Example
[0032] The invention discloses an effective embedded single chip computer software upgrade mechanism, comprising: a startup module, an upgrade module, a recovery module and a data storage module, and signal connections between the modules.
[0033] In order to solve the problem of unexpected situations during the software upgrade of embedded MCU, which may cause the product to enter a paralyzed state, the FLASH of the embedded MCU is first divided into: BOOT partition, APP partition, BACKUP partition, APPValid partition, and BACKUPValid partition. Among them, the BOOT partition function is used to upgrade the APP part; the APP partition is the implementation part of the main functions of the embedded product and is the target of subsequent upgrades; the BACKUP partition is used as the backup area for the new software to be upgraded; the APPValid partition indicates whether the APP area code is valid; and the BACKUPValid partition indicates whether the upgrade backup area code is valid.
[0034] The data storage module is used to store all data during the processing.
[0035] The boot module supports external communication interfaces (such as UART and USB), receiving and identifying external firmware data, including the firmware main program, checksum data, firmware version and header information, and upgrade scripts or configurations. It also leverages the boot logic managed by the embedded MCU software state machine to dynamically switch from the BOOT partition to the APP partition or recovery module. The BOOT partition, a fixed, non-erasable boot program, is responsible for scheduling the embedded MCU software boot logic. Furthermore, the boot module uses flags (APPValid and BACKUPValid) to record the validity of the APP and BACKUP partitions and dynamically determine program jump paths.
[0036] Specifically, after the embedded single-chip microcomputer software is started, the code of the BOOT partition is executed to check whether there is external firmware data sent through the communication interface (such as UART, USB, Wi-Fi). When there is external firmware data, the external firmware data is transferred to the upgrade module; when there is no external firmware data, the flag status APPValid flag stored in the FLASH is checked to see if it is valid. When the APPValid flag is valid, the program jumps to the APP partition; when the APPValid flag is invalid, the code of the BACKUPValid flag is checked to see if it is valid. When the BACKUPValid flag is valid, the program enters the recovery module. When the BACKUPValid flag is invalid, the program enters the safe mode to avoid running damaged or erroneous programs.
[0037] The upgrade module uses communication protocols (such as XMODEM and YMODEM) for block transmission and incorporates verification algorithms (such as CRC32) to ensure the integrity of the transmitted external firmware data. It also utilizes flags to dynamically adjust the program's running status. After verification, the upgrade module uses a FLASH erase / write operation to update the app partition, ensuring the safe removal of old programs and a secure and reliable upgrade process.
[0038] Specifically, the upgrade module receives external firmware data through the communication interface and writes it into the BACKUP partition block by block. After the reception is completed, the firmware's check value (such as CRC32) is calculated and compared with the received check value. When the comparison result is consistent, the BACKUPValid flag is set to valid; when the comparison result is inconsistent, the BACKUPValid flag is set to invalid and the firmware is discarded.
[0039] Before starting the upgrade, the upgrade module sets the APPValid flag to invalid to prevent an erroneous jump to the old program. If the verification and comparison are consistent, the BACKUPValid flag is set to valid, preparing to update the APP partition. First, the APP partition's old data is erased and the BACKUP partition's firmware is copied block by block to the APP partition. After the copy is complete, the APP partition is integrity checked. If the verification passes, the APPValid flag is set to valid, completing the upgrade. If the verification fails, APPValid remains invalid to prevent the incorrect program from running.
[0040] It should be noted that embedded MCU software typically requires long runtimes and even real-time response, so blindly upgrading it can lead to system instability. In this embodiment, an intelligent upgrade scheduling mechanism is designed to determine the optimal time for an upgrade by monitoring the operating status of the embedded MCU software (e.g., CPU load, memory usage, and communication bandwidth) in real time. For example, when the device is under low load or idle, the upgrade is automatically triggered; during periods of high load or critical tasks, the upgrade is postponed to avoid impacting normal device operation.
[0041] First, the running status data of the embedded MCU software is collected in real time, including: CPU load, memory usage, and communication bandwidth; the upgrade module uses the hardware performance counters and system resource management API (such as the resource monitoring interface in the RTOS) of the embedded MCU software to obtain the device status, and uses timer interrupts to periodically trigger status collection.
[0042] Specifically, a performance counter is a hardware function that can accurately count the processor's running time and idle time. In this embodiment, a performance counter is used to record the CPU's idle time ratio, specifically according to the formula: CPU load = 1-(idle time / total time); and a memory allocation interface (such as malloc() or the RTOS heap usage statistics interface) is called to obtain the ratio of currently allocated memory to total memory; a data transmission statistics counter is set on the communication interface (such as UART, SPI, I2C, or network interface) to calculate the amount of data transmitted per second and obtain the bandwidth utilization rate. For example, the sample operating status data of the embedded single-chip microcomputer software obtained through collection: CPU load is 85%, memory utilization is 75%, and communication bandwidth utilization is 50%.
[0043] Furthermore, the upgrade module uses a weighted average algorithm to evaluate the collected operating status data of the embedded microcontroller software, calculates the real-time load value F of the embedded microcontroller software, and judges the real-time load status of the embedded microcontroller software according to the formula: F=Qc×Fcpu+Qn×Fn+Qtx×Ftx, where. F represents the real-time load value of the embedded MCU software, Qc represents the weight value of the CPU load, Fcpu represents the CPU load, Qn represents the weight value of the memory usage, Fn represents the memory usage, Qtx represents the weight value of the communication broadband usage, and Ftx represents the communication broadband usage; and a load threshold Yf is set, and the real-time load value F of the embedded MCU software is compared with the load threshold Yf. When the real-time load value F of the embedded MCU software is less than or equal to the load threshold Yf, the upgrade operation is automatically triggered when the device is in a low-load or idle state. When the real-time load value F of the embedded MCU software is greater than the load threshold Yf, the device is in a high-load or critical task operation period, and the upgrade is postponed until the device enters a low-load state to avoid affecting the normal operation of the device. For example, in this embodiment, the load threshold Yf is set to 0.8, and Qc, Qn, and Qtx are calculated to be 0.4, 0.3, and 0.3, and the obtained data is substituted into the formula to calculate the real-time load value of the embedded single-chip microcomputer software to be 0.715, which is less than the load threshold Yf, indicating that the device is in a low-load state and automatically triggers the upgrade operation.
[0044] The recovery module uses the BACKUP partition as a backup area to support recovery in the event of data corruption in the APP partition. Using Flash read / write technology, data is copied from the BACKUP partition to the APP partition. After the copy, the APP partition is integrity-verified using the same verification algorithm to ensure data accuracy. If recovery fails, the device enters safe mode to prevent the device from continuing to run corrupted programs.
[0045] Specifically, the recovery module first checks the flag status. If the startup module detects that the APPValid flag is invalid, it checks the BACKUPValid flag. If the BACKUPValid flag is valid, it erases the old data in the APP partition, copies the data from the BACKUP partition block by block to the APP partition, and verifies whether the restored APP partition content is complete and valid. If the verification result is valid, it indicates that the recovery is successful. At this time, the APPValid flag is set to valid, allowing the jump to the APP partition to run. If the verification result is invalid, it indicates that the recovery failed. At this time, the APPValid flag and the BACKUPValid flag remain invalid, and safe mode is entered.
[0046] It should be noted that embedded single-chip microcomputers usually have limited resources (such as battery power, processor performance, memory and bandwidth). During the recovery operation, the management of device resources is particularly important. If the recovery task is forcibly executed when the device resources are tight, it may cause the device to run slowly, the system to crash or even the recovery to fail. In this embodiment, an intelligent recovery time window mechanism is designed: by relying on the intelligent upgrade scheduling mechanism to manage the resources of the device, the priority of the recovery task is dynamically evaluated in combination with the current status of the device (for example, the real-time status of the battery, the real-time load value of the embedded single-chip microcomputer software). When the device has entered a higher load state during the upgrade operation, the intelligent recovery time window mechanism will postpone the recovery task until the resources are restored to a suitable state, ensuring that the recovery operation can be performed when the system load is low.
[0047] First, use the power management chip of the embedded microcontroller (such as the BQ series battery management chip) to collect the real-time status data of the embedded microcontroller battery, including: voltage, current, and remaining power, among which:
[0048] Voltage V:
[0049] Reflects the current output capacity of the battery.
[0050] Normal range: 3.6V~4.2V (lithium battery).
[0051] Below 3.6V means the battery is nearly exhausted
[0052] Current I:
[0053] Represents the real-time discharge or charge rate.
[0054] Normal range: discharge current <1C, charge current ~0.5C.
[0055] Exceeding 1C (discharge) or abnormal charging indicates that high-load tasks are not suitable.
[0056] Remaining power SoC: The percentage of overall battery energy storage.
[0057] It should be noted that the built-in fuel gauge calculates the remaining battery capacity through the Coulomb Counting technology, according to the formula , where I(t) represents the real-time current and the integral value represents the battery power consumption. For example, the real-time status data of the embedded microcontroller battery is as follows:
[0058] Voltage 3.8V;
[0059] Current 500mA;
[0060] 40% battery remaining.
[0061] Furthermore, linear normalization is used to normalize the collected battery status data to the [0,1] interval. The formula is: Where Normalized_Score is the normalized value.
[0062] It should be noted that the normalization formula given in this embodiment is a general formula and will not be described in detail here.
[0063] Furthermore, the recovery module determines the recovery task priority P by combining the real-time battery status data with the embedded single-chip microcomputer software load value F, and performing weighted average calculation, specifically according to the formula: P = Qf × (1-F) + Qv × V + Qi × I + Qsoc × SoC, wherein Qf represents the weight value of the embedded single-chip microcomputer software load value, Qv represents the weight value of the battery voltage, Qi represents the weight value of the battery current, and Qsoc represents the weight value of the remaining battery power, and satisfies Qf + Qv + Qi + Qsoc = 1; at the same time, in this embodiment, an execution threshold Yz is set. When the recovery task priority P is greater than the execution threshold Yz, it indicates that the resource management of the embedded single-chip microcomputer has returned to a stable state and the recovery task can be executed immediately; when the recovery task priority P is less than or equal to Yz, it indicates that the resource management of the embedded single-chip microcomputer is in a high-load state. The intelligent recovery time window mechanism will postpone the recovery task until the resource management of the embedded single-chip microcomputer has returned to a stable state. For example: In this embodiment, the execution threshold Yz is set to 0.5, and Qf is calculated to be 0.1, Qv is 0.2, Qi is 0.3, and Qsoc is 0.4. Substituting the example data into the formula, the recovery task priority P is calculated to be 0.451, which is less than the execution threshold Yz. At this time, the resource management of the embedded microcontroller is in a high-load state, and the recovery task cannot be performed. It is necessary to wait for the resource management to return to a stable state.
[0064] The present invention also relates to an effective embedded single-chip computer software upgrade method, including:
[0065] Step 1: Divide the FLASH of the embedded MCU into multiple functional areas, manage the program validity through flags, and dynamically switch to the appropriate program or recovery mode.
[0066] Step 2: Receive and verify external firmware data through the communication interface. After ensuring the integrity of the external firmware data, update the APP partition and trigger the upgrade under low load state to ensure stability.
[0067] Step 3: When the APP partition is damaged, restore from backup data, combine battery status and real-time load assessment, and intelligently schedule upgrade and recovery operations to avoid resource conflicts and ensure that the recovery task is executed in a stable state.
[0068] The above formulas are all dimensionless and numerical calculations. The formulas are obtained by collecting a large amount of data and performing software simulation to obtain the most recent real situation. The preset parameters in the formulas are set by technicians in this field according to actual conditions.
[0069] The above embodiments may be implemented in whole or in part through software, hardware, firmware, or any other combination thereof. When implemented using software, the above embodiments may be implemented in whole or in part in the form of a computer program product.
[0070] Those skilled in the art will appreciate that the modules and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application of the technical solution and the invention constraints. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.
[0071] In addition, each functional module in each embodiment of the present application may be integrated into one processing module, or each module may exist physically separately, or two or more modules may be integrated into one module.
[0072] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this application should be included in the scope of protection of this application. Therefore, the scope of protection of this application should be based on the scope of protection of the claims.
[0073] Finally: The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.
Claims
1. An effective embedded single-chip microcomputer software upgrade mechanism, characterized in that: include: Startup module, upgrade module, recovery module and data storage module, and signal connections between modules; The data storage module is used to store all data in the processing process; The startup module is mainly used to provide support for external communication interfaces, receive and identify external firmware data, and use flags to record the validity of the APP partition and BACKUP partition; The upgrade module is mainly used to transmit data in blocks using the XMODEM communication protocol, and combines the CRC32 verification algorithm to ensure the integrity of the transmitted external firmware data. The flag bit is used to dynamically adjust the program running status. After the verification is completed, the FLASH erase and write operation is used to update the APP partition. An intelligent upgrade scheduling mechanism is designed to determine the optimal time for the upgrade. The recovery module is mainly used to use the BACKUP partition as a backup area, copy device data from the BACKUP partition to the APP partition, and use the same verification algorithm to perform integrity verification on the APP partition after copying; And design an intelligent recovery time window mechanism to dynamically evaluate the priority of recovery tasks.
2. The effective embedded single-chip microcomputer software upgrade mechanism according to claim 1, characterized in that: The FLASH of the embedded microcontroller is divided into: BOOT partition, APP partition, BACKUP partition, APPVal id partition, BACKUPVal id partition, among which the BOOT partition function realizes the upgrade of the APP part; the APP partition is the implementation part of the main functions of the embedded product; the BACKUP partition is used as the backup area for the new software to be upgraded; the APPVal id partition marks whether the APP area code is valid; the BACKUPVal id partition marks whether the upgrade backup area code is valid.
3. The effective embedded single-chip microcomputer software upgrade mechanism according to claim 2, characterized in that: After the embedded MCU software is started, the code of the BOOT partition is executed to check whether there is external firmware data sent through the communication interface UART, USB, and Wi-Fi. If there is external firmware data, the external firmware data is transferred to the upgrade module. If there is no external firmware data, the flag status APPValid flag stored in the FLASH is checked to see if it is valid. If the APPVal id flag is valid, the program jumps to the APP partition. When the APPVal id flag is invalid, check whether the BACKUPVal id flag is valid. When the BACKUPVal id flag is valid, enter the recovery module. When the BACKUPVal id flag is invalid, enter the safe mode.
4. An effective embedded single-chip microcomputer software upgrade mechanism according to claim 3, characterized in that The upgrade module receives external firmware data through the communication interface and writes it to the BACKUP partition block by block. After receiving the data, the upgrade module sets the APPVal id flag to invalid, calculates the firmware checksum, and compares it with the received checksum. If the comparison results are consistent, the BACKUPVal id flag is set to valid and prepares to update the APP partition: erase the old device data in the APP partition and copy the firmware in the BACKUP partition block by block to the APP partition. After the copy is completed, the integrity of the APP partition is checked: if the check passes, the APPVal id flag is set to valid and the upgrade is completed. If the check fails, the APPVal id is kept invalid; if the comparison results are inconsistent, the BACKUPVal id flag is set to invalid.
5. The effective embedded single-chip microcomputer software upgrade mechanism according to claim 4, characterized in that: Real-time collection of embedded MCU software operating status data, including: CPU load, memory usage, and communication bandwidth; Use performance counters to record the proportion of CPU idle time, using the formula: CPU load = 1 - (idle time / total time). Call the memory allocation interface mal loc() or the RTOS heap usage statistics interface to obtain the ratio of currently allocated memory to total memory. Set data transmission statistics counters on the communication interfaces UART, SPI, I2C, or network interfaces to calculate the amount of data transmitted per second and determine the bandwidth utilization rate. The upgrade module uses a weighted average algorithm to evaluate the collected running status data of the embedded MCU software and calculates the real-time load value F of the embedded MCU software. The specific formula is: F = Qc × Fcpu + Qn × Fn + Qtx × Ftx, where F represents the real-time load value of the embedded MCU software, Qc represents the weight value of the CPU load, Fcpu represents the CPU load, Qn represents the weight value of the memory usage rate, Fn represents the memory usage rate, Qtx represents the weight value of the communication broadband usage, and Ftx represents the communication broadband usage rate; and sets a load threshold Yf, compares the real-time load value F of the embedded MCU software with the load threshold Yf, and automatically triggers the upgrade operation when the real-time load value F of the embedded MCU software is less than or equal to the load threshold Yf; when the real-time load value F of the embedded MCU software is greater than the load threshold Yf, the upgrade is postponed.
6. The effective embedded single-chip microcomputer software upgrade mechanism according to claim 5, characterized in that: The recovery module first checks the flag status. When it detects that the APPVal id flag is invalid, it checks the BACKUPVal id flag. If the BACKUPVal id flag is valid, the old device data of the APP partition is erased, and the data of the BACKUP partition is copied block by block to the APP partition. It also verifies whether the restored APP partition content is complete and valid. If the verification result is valid, it means that the recovery is successful. At this time, the APPVal id flag is set to valid, allowing the jump to the APP partition to run. If the verification result is invalid, it means that the recovery failed, the APPVal id flag and the BACKUPVal id flag are kept invalid, and the safe mode is entered.
7. The effective embedded single-chip microcomputer software upgrade mechanism according to claim 6, characterized in that: The power management chip of the embedded microcontroller is used to collect the real-time status data of the embedded microcontroller battery, including voltage, current, and remaining power. Among them, the built-in power meter calculates the remaining capacity of the battery through the cumulative current integration technology. The specific formula is , where I(t) represents the real-time current and the integral value represents the battery power consumption; The recovery module determines the recovery task priority P by combining the real-time battery status data with the embedded MCU software load value F, and performing weighted average calculation. The specific formula is: P = Qf × (1-F) + Qv × V + Qi × I + Qsoc × SoC, where Qf represents the weight value of the embedded MCU software load value, Qv represents the weight value of the battery voltage, Qi represents the weight value of the battery current, and Qsoc represents the weight value of the remaining battery power, and Qf + Qv + Qi + Qsoc = 1 is satisfied. An execution threshold Yz is set. When the recovery task priority P is greater than the execution threshold Yz, the recovery task can be executed immediately. When the recovery task priority P is less than or equal to Yz, the intelligent recovery time window mechanism will postpone the recovery task until the resource management of the embedded MCU returns to a stable state.
8. An effective embedded single chip microcomputer software upgrade method, characterized in that ; Step 1: Divide the FLASH of the embedded MCU into multiple functional areas, manage the program validity through flags, and dynamically switch to the appropriate program or recovery mode; Step 2: Receive and verify external firmware data through the communication interface, update the APP partition after ensuring the integrity of the external firmware data, and trigger the upgrade under low load state; Step 3: When the APP partition is damaged, restore from backup data, combine battery status and real-time load assessment to intelligently schedule upgrade and recovery operations.