MCU starting method, electronic equipment, storage medium and computer program product

By dividing parameters and backup partitions in the MCU's Flash memory, and using CRC32 data checksum partition repair technology, the problems of flawed Flash and failed data writing in the RT-Thread system are solved, ensuring the stability and security of the system.

CN120386229APending Publication Date: 2025-07-29NANJING BESTWAY AUTOMATION SYST
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510341198.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-21
Publication Date
2025-07-29

AI Technical Summary

Technical Problem

When the MCU is running the RT-Thread operating system, Flash is easily damaged, data is easily written and failed, and partitions are damaged, resulting in system abnormalities that cannot start normally.

Method used

Divide parameter partitions and backup partitions in Flash memory. By judging partition corruption and data consistency, select appropriate partitions as the source of startup parameters, and use CRC32 data checksum partition repair technology to ensure data accuracy and system stability.

Benefits of technology

It realizes the safe and stable start of the MCU under the RT-Thread system, enhances the robustness of the system, and avoids partition damage and system crashes caused by frequent power outages or accidental operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120386229A_ABST
    Figure CN120386229A_ABST
Patent Text Reader

Abstract

The invention discloses an MCU starting method, electronic equipment, a storage medium and a computer program product. A FLASH memory is divided into a parameter partition and a backup partition which are located in completely different storage spaces; when firmware is started, whether the parameter partitions are damaged or not and whether data are correct or not are judged, the source of starting parameters is selected according to the judgment result, parameter synchronization and backup are carried out in time, the partition selection technology is utilized, parameter partition safety protection is achieved, parameter content correctness protection is achieved through the CRC32 data verification technology, and the safety of the firmware is improved. And parameter partition robustness protection is realized by using a partition repair technology.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of embedded automation control technology, and particularly to a startup method for an MCU, an electronic device, a storage medium, and a software product. Background Art

[0002] With the improvement of automation and intelligence levels, the application of MCU main control devices has become increasingly widespread in fields such as manufacturing, logistics, and underground mining exploration. The parameter security of the MCU main control device is directly related to its system efficiency and system stability.

[0003] The Flash storage inside the MCU main control device is usually divided into multiple partitions. Some areas are used to store program codes, while the other part is used to save user data or configuration parameters. Writing parameters directly into the unallocated Flash area is a common practice. However, due to the limited number of erase / write cycles of Flash storage, usually between tens of thousands and hundreds of thousands of times, frequent write operations may cause Flash wear. In addition, Flash storage during the write process is erased by page or block, which may cause data integrity problems.

[0004] RT-Thread is an event-driven real-time operating system with a very small kernel, only a few thousand bytes, so it can well meet the requirements of embedded systems. Its kernel divides system functions into different modules, and each module can run and manage independently. At the same time, RT-Thread also supports multitasking and can run multiple tasks simultaneously to meet different system requirements.

[0005] For an MCU running the RT-Thread operating system, the following problems may occur due to the limitations of RT-Thread in real-time system storage: 1. Frequent writes cause Flash damage; 2. Accidental frequent power outages easily cause data write failures and errors, and even cause partition damage; 3. Partition damage easily causes system exceptions and results in abnormal startup. Summary of the Invention

[0006] Embodiments of this application provide a startup method for an MCU, an electronic device, a storage medium, and a computer program product, which are used to solve the technical problems of easy Flash damage, easy data write failure, partition damage, and system exception when the MCU runs the RT-Thread operating system.

[0007] According to one aspect of this application, a startup method for an MCU is provided, including:

[0008] Partition the parameter partition and the backup partition in the FLASH memory that are located in completely different storage spaces;

[0009] When the firmware starts up, it determines whether the parameter partition is damaged:

[0010] If the parameter partition is not damaged and the data in the partition remains correct, it determines whether the data in the backup partition remains correct. If it is correct, it further determines whether the data in the parameter partition is consistent with the data in the backup partition. If they are consistent, it selects the data in the parameter partition as the source of startup parameters and executes the startup. If they are inconsistent, it synchronizes the data in the parameter partition to the backup partition, and then selects the data in the parameter partition as the source of startup parameters and executes the startup; if it is incorrect, it synchronizes the data in the parameter partition to the backup partition, and then selects the data in the parameter partition as the source of startup parameters and executes the startup;

[0011] If the parameter partition is not damaged but the data in the partition does not remain correct, it determines whether the data in the backup partition remains correct. If it is correct, it synchronizes the data in the backup partition to the parameter partition. If it is incorrect, it synchronizes the data in the default partition to the parameter partition, and then selects the data in the parameter partition as the source of startup parameters and executes the startup;

[0012] If the parameter partition is damaged, it determines whether the data in the backup partition remains correct. If it is correct, it selects the data in the backup partition as the source of startup parameters and executes the startup. If it is incorrect, it synchronizes the data in the default partition to the backup partition, and then selects the data in the backup partition as the source of startup parameters and executes the startup.

[0013] Furthermore, it is set that there are at least two parameter partitions and they are located in completely different storage spaces, and each parameter partition has a preset priority;

[0014] During the firmware startup phase, determining whether the parameter partition is damaged includes:

[0015] It determines whether the parameter partition is damaged in the order of priority. Only when the parameter partition with the previous priority cannot be repaired, it determines whether the parameter partition with the next priority is damaged. Otherwise, it uses the data in the parameter partition with the current priority to participate in the subsequent steps.

[0016] Furthermore, before the firmware starts up, it also includes: determining whether to enter the boot parameter configuration. If so, it enters the boot parameter configuration. Otherwise, it starts the firmware;

[0017] The entry into the boot parameter configuration includes:

[0018] It determines whether the parameter partition is damaged in the order of priority, and if the parameter partition with the current priority is not damaged, it selects this parameter partition and reads the configuration parameters in this parameter partition to the configuration page. Otherwise, it determines whether the parameter partition with the next priority is damaged;

[0019] Determine whether to save the configuration. If so, continue; otherwise, end the boot parameter configuration.

[0020] Calculate the CRC of the configuration parameters and save them together to the parameter partition corresponding to the configuration parameters, and end the boot parameter configuration.

[0021] Furthermore, after the firmware is started, it further includes:

[0022] If a parameter configuration instruction is received, save the new parameters to the partition selected for the current system operation, calculate the CRC of the new parameters, and save it to the partition selected for the current system operation.

[0023] Furthermore, judging whether the parameter partition is damaged according to the priority order, and only when the parameter partition with the previous priority cannot be repaired, judge whether the parameter partition with the next priority is damaged, including:

[0024] Judge whether the damage flag of the parameter partition of the current priority indicates damage. If so, read the erase count of the parameter partition of the current priority and judge whether the erase count is less than 3. If it is less than 3, erase the parameter partition of the current priority and judge whether the erase is successful. If the erase is successful, set the erase count of the parameter partition of the current priority to 0, and set the damage flag of the parameter partition of the current priority to indicate no damage.

[0025] Furthermore, a register is configured to store the damage flag and erase count of each parameter partition.

[0026] Furthermore, the method includes the following steps:

[0027] Step 1: The inspection device starts and enters the bootload stage. Determine whether to directly enter the firmware startup stage. If so, continue; otherwise, jump to Step 15.

[0028] Step 2: Enter the first parameter partition repair sub-process.

[0029] Step 3: Judge the damage flag of the first parameter partition. If it is true, continue; otherwise, jump to Step 8.

[0030] Step 4: Enter the second parameter partition repair sub-process.

[0031] Step 5: Judge the damage flag of the second parameter partition. If it is true, jump to Step 7; otherwise, continue.

[0032] Step 6: Read the data in the second parameter partition, perform CRC verification on the data in the second parameter partition. If the verification is correct, jump to Step 9; otherwise, jump to Step 12.

[0033] Step 7: Perform CRC check on the data in the backup parameter partition. If the check is correct, read the backup parameter partition and jump to Step 15; otherwise, synchronize the default configuration information to the backup parameter partition and then go to Step 15.

[0034] Step 8: Read the data in the first parameter partition and perform CRC check on the data in the first parameter partition. If the check is correct, continue; otherwise, jump to Step 12.

[0035] Step 9: Perform CRC check on the data in the backup parameter partition. If the check is correct, continue; otherwise, jump to Step 11.

[0036] Step 10: Compare whether the data in the undamaged first parameter partition or the second parameter partition is the same as the data in the backup parameter partition. If they are the same, jump to Step 15; otherwise, continue.

[0037] Step 11: Synchronize the data in the undamaged first parameter partition or the second parameter partition to the backup parameter partition and jump to Step 15.

[0038] Step 12: Perform CRC check on the data in the backup parameter partition. If the check is correct, continue; otherwise, jump to Step 14.

[0039] Step 13: Synchronize the data in the backup parameter partition to the undamaged first parameter partition or the second parameter partition and jump to Step 15.

[0040] Step 14: Synchronize the default configuration information to the undamaged first parameter partition or the second parameter partition and continue with the next step.

[0041] Step 15: End.

[0042] In the second aspect of the present application, there is provided an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the electronic device implements the method provided in the first aspect of the present application.

[0043] In the third aspect of the present application, there is provided a computer-readable storage medium for storing a computer program. When the computer program runs on a computer, the computer is caused to execute the method described in the first aspect of the present application.

[0044] In the fourth aspect of the present application, there is provided a computer program product including instructions. When the instructions are executed alone or jointly by at least one processor of a computing device, the computing device is caused to execute the method described in the first aspect of the present application.

[0045] In the embodiments of the present application, a method for starting an MCU is adopted. By using this method, the MCU can be started more safely and stably under the RTT real-time system, and has a backup and recovery mechanism with strong robustness to solve the problem that accidental frequent power outages under the RTT real-time system are likely to cause data writing failures and errors, and even cause partition damage, resulting in the inability to erase partitions or access partitions, thereby triggering hardware exception errors and causing APP and firmware CRASH phenomena. Through the solution of the present application, it is possible to correctly restore parameter data when various accidental operation parameter partitions cause damage to the parameter partitions, ensuring the continuous and stable operation of the system of the MCU main control device. In the technical solution proposed by the present invention, the CRC32 data verification technology is used to realize the protection of the correctness of the parameter content, the partition repair technology is used to realize the protection of the robustness of the parameter partitions, and the partition selection technology is used to realize the protection of the security of the parameter partitions. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] The accompanying drawings constituting a part of this application are used to provide a further understanding of this application. The schematic embodiments of this application and their descriptions are used to explain this application and do not constitute an improper limitation of this application. In the drawings:

[0047] Figure 1 is a flowchart of a method for starting an MCU according to an embodiment of the present application.

[0048] Figure 2 is a schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION OF THE EMBODIMENTS

[0049] It should be noted that, without conflict, the embodiments in this application and the features in the embodiments can be combined with each other. The following will refer to the accompanying drawings and combine the embodiments to detail this application.

[0050] It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although the logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in a different order than here.

[0051] As Figure 1 shown, it is a schematic flowchart of a method for starting an MCU provided by an embodiment of the present invention. In order to obtain correct startup parameters, as Figure 1 shown, the method for starting an MCU includes:

[0052] Step S102, divide a parameter partition and a backup partition with completely different storage spaces in the FLASH memory.

[0053] The parameter partition is used for storing parameters during normal system operation, and the backup partition is used for backing up the parameters in the currently active parameter partition during normal system operation.

[0054] In some alternative embodiments, there may be multiple parameter partitions. For example, in this embodiment, the built-in FLASH space of the STM32H7xx type MCU is selected for partition division. As shown in Table 1, the STM32H7xx internal FLASH has two BANKs, namely BANK0 and BANK1. On the partitions of BANK0 and BANK1, the embodiments of the present invention mainly involve the following three partitions:

[0055] The first parameter partition: The sector 7 of BANK0, with the address ranging from 0x080E 0000 to 0x080F FFFF, is used as the parameter storage partition for normal system operation.

[0056] The second parameter partition: The sector 5 of BANK1, with the address ranging from 0x081A 0000 to 0x081B FFFF, is used as the parameter storage partition for system operation when the first parameter partition is damaged.

[0057] The backup parameter partition: The sector 7 of BANK1, with the address ranging from 0x1FF40000 to 0x1FF5 FFFF, is used for backing up the currently active parameter storage partition during normal system operation.

[0058] Table 1

[0059]

[0060] Step S104: When the firmware starts, it involves specifically selecting the startup parameters from which storage partition, and it is necessary to ensure the accuracy of the selected parameters as much as possible. Therefore, it is first necessary to determine whether the parameter partition is damaged. In this embodiment, since the parameter partition is divided into 2 and located in completely different storage spaces, preset priorities are set for each parameter partition, and the priority of the first parameter partition is higher than that of the second parameter partition.

[0061] During the firmware startup phase, determining whether the parameter partition is damaged includes: determining whether the parameter partition is damaged in the order of priority. Only when the parameter partition with the previous priority cannot be repaired, then determine whether the parameter partition with the next priority is damaged, otherwise use the data in the parameter partition with the current priority to participate in the subsequent steps. That is, if the parameter partition with the higher priority is not damaged or is detected to be damaged but can be repaired successfully after repair, then select the parameter partition with the higher priority to start, otherwise select the parameter partition with the next priority for the same judgment.

[0062] Specifically, the above method further makes the following several judgments according to whether the parameter partition is damaged:

[0063] Step S1041: If the parameter partition is not damaged and the data in the partition is correct, determine whether the data in the backup partition is correct. If it is correct, further determine whether the data in the parameter partition is consistent with the data in the backup partition. If they are consistent, select the data in the parameter partition as the startup parameter source and execute the startup. If they are inconsistent, synchronize the data in the parameter partition to the backup partition, then select the data in the parameter partition as the startup parameter source and execute the startup. If it is incorrect, synchronize the data in the parameter partition to the backup partition, then select the data in the parameter partition as the startup parameter source and execute the startup.

[0064] Under this condition, the parameter partition is an ideal startup data source. For example, first determine whether the first parameter partition in the parameter partition meets this condition. If it meets the condition, the first parameter partition is used as the current active parameter partition. If the first parameter partition does not meet this condition but the second parameter partition meets the condition, the second parameter partition is used as the current active parameter partition. As long as the data in the backup partition is incorrect or not consistent with the parameter partition at this time, refer to the data in the parameter partition to synchronize the backup partition. Such an execution result ensures that the data in the backup partition is accurate and synchronized every time the startup is performed when the parameter partition is available and the data is error-free.

[0065] Step S1042: If the parameter partition is not damaged but the data in the partition is not correct, determine whether the data in the backup partition is correct. If it is correct, synchronize the data in the backup partition to the parameter partition. If it is incorrect, synchronize the data in the default partition to the parameter partition, then select the data in the parameter partition as the startup parameter source and execute the startup.

[0066] Under this condition, the parameter partition is still available. Therefore, only the data inside it needs to be adjusted to the correct state. At this time, if the data in the backup partition is correct, the data in the backup partition is preferentially synchronized. Otherwise, the data in the default partition is synchronized.

[0067] Step S1043: If the parameter partition is damaged, determine whether the data in the backup partition is correct. If it is correct, select the data in the backup partition as the startup parameter source and execute the startup. If it is incorrect, synchronize the data in the default partition to the backup partition, then select the data in the backup partition as the startup parameter source and execute the startup.

[0068] Under this condition, the parameter partition is unavailable. Then, only the data in the backup partition can be used as the startup source. At this time, it is determined whether to directly use the data in the backup partition as the startup source according to whether the data in the backup partition is correct. When the data in the backup partition is incorrect, the data in the backup partition is synchronized once using the default partition and then used as the startup source.

[0069] According to the method in the above embodiments, by dividing parameter partitions and backup partitions located in different storage spaces on the FLASH memory, judging the damage condition of the parameter partitions and whether the data therein remains correct, and according to the data condition in the backup partitions, data synchronization is performed in a timely manner and a suitable partition is selected as the source for data startup. Through the above method, the currently running partition can be switched to ensure the normal operation of the system.

[0070] Further, in this embodiment, before the firmware is started, it further includes: judging whether to enter the boot parameter configuration. If so, enter the boot parameter configuration; otherwise, start the firmware.

[0071] The entering the boot parameter configuration includes:

[0072] Judging whether the parameter partitions are damaged in the order of priority. If the parameter partition of the current priority is not damaged, select the parameter partition and read the configuration parameters therein to the configuration page; otherwise, judge whether the parameter partition of the next priority is damaged.

[0073] Judge whether to save the configuration. If so, continue; otherwise, end the boot parameter configuration.

[0074] Calculate the CRC of the configuration parameters and save them together to the parameter partition corresponding to the configuration parameters, and end the boot parameter configuration.

[0075] Further, in this embodiment, after the firmware is started, it further includes:

[0076] If a parameter configuration instruction is received, save the new parameters to the partition selected for the current system operation, and calculate the CRC of the new parameters and save them to the partition selected for the current system operation.

[0077] Through the calculation and saving of the CRC, during the firmware startup phase, it is possible to judge whether the data information in the current parameter partition is correct by comparing and judging whether the CRC check code of the current parameter partition is consistent with the saved check code.

[0078] Further, in this embodiment, in order to perform damage judgment, a register is configured to store the damage flags of each parameter partition. At the same time, in order to be able to repair the damaged parameter partitions to the greatest extent, multiple repair opportunities are given in the judgment of this embodiment. Unless it fails to be repaired successfully after multiple repairs, it is judged that the parameter partition is damaged.

[0079] In some alternative embodiments, during the power-on of the MCU main control device's system operation, when a parameter changes, the system will write the changed value to the current parameter partition through the write function interface provided by the RTT of the current RTT system, and calculate and determine the CRC (CRC32) checksum of the main parameter partition, which is saved in the current parameter partition for use in the restore backup logic. The specific detailed implementation process steps are as follows:

[0080] Step 1: The inspection device starts and enters the bootload stage. Determine whether to enter the boot parameter configuration stage. If yes, continue; otherwise, jump to step 9).

[0081] Step 2: Determine whether the first parameter partition damage flag in the register is 1. If not, continue; if yes, jump to step 4).

[0082] Step 3: Read the data of the second parameter partition to the configuration page and jump to the end step 7).

[0083] Step 4: Determine whether the second parameter partition damage flag in the register is 1. If not, continue; if yes, jump to step 6).

[0084] Step 5: Read the data of the first parameter partition to the configuration page and jump to the end step 7).

[0085] Step 6: Read the data of the backup configuration partition to the configuration page.

[0086] Step 7: Determine whether to save the configuration. If yes, continue; otherwise, jump to the end step 14).

[0087] Step 8: Calculate the CRC (CRC32) of the configuration parameters and save them together to the corresponding data partition, and jump to the end step 14).

[0088] Step 9: After selecting the correct startup data source, obtain the correct configuration information and enter the app application stage.

[0089] Step 10: Determine whether the environmental configuration is received. If yes, continue; if not, jump to the end step 14).

[0090] Step 12: Calculate the CRC (CRC32) of the configuration parameters and save them together to the corresponding data partition.

[0091] Step 14: End

[0092] In this embodiment, since the data in the corresponding area is erased once for each repair, an erase count can be generated. Therefore, this embodiment uses the above register to store the parameter of the erase count. Therefore, in this embodiment, judging whether the parameter partition is damaged according to the priority order, and judging whether the next priority parameter partition is damaged only when the parameter partition with the previous priority cannot be repaired, includes:

[0093] Judge whether the damage flag of the parameter partition of the current priority indicates damage. If so, read the erase count of the parameter partition of the current priority and judge whether the erase count is less than 3. If it is less than 3, erase the parameter partition of the current priority and judge whether the erase is successful. If the erase is successful, set the erase count of the parameter partition of the current priority to 0, and set the damage flag of the parameter partition of the current priority to indicate no damage.

[0094] It is set that when the CRC error flag is 1, it indicates a parameter error, and when it is 0, it indicates a correct parameter. It is set that when the damage flag is 1, it indicates damage, and when it is 0, it indicates no damage. Then, in the embodiments of the present invention, the state conversion principle and method steps of each partition are as follows:

[0095] For the first parameter partition:

[0096] When the damage flag of the first parameter partition is 0:

[0097] Step 1-1: When it is judged that the CRC error flag of the second parameter partition is equal to 1, synchronize the first parameter partition to the second parameter partition.

[0098] Step 1-2: When it is judged that the CRC error flag of the backup parameter partition is equal to 1, synchronize the first parameter partition to the backup parameter partition.

[0099] When the damage flag of the first parameter partition is activated to 1:

[0100] Step 1-1': Judge whether the repair times of the first parameter partition are less than 3 times. If so, continue to the next step, otherwise jump to step 1-3'.

[0101] Step 1-2': Try to repair the first parameter partition. If the repair is successful, reset the damage flag of the first parameter partition to 0 and end. Otherwise, jump to step 1-1'.

[0102] Step 1-3': When it is judged that the CRC error flag of the second parameter partition is equal to 0, start using the data in the second parameter partition and give an alarm prompt for using the second parameter partition.

[0103] For the second parameter partition:

[0104] When the damage flag of the second parameter partition is 0 and the damage flag of the first parameter partition is 1:

[0105] Step 2-1: When it is determined that the backup parameter partition CRC error flag is equal to 1, synchronize the second parameter partition data to the backup parameter partition.

[0106] When the second parameter partition damage flag is 1 and the first parameter partition damage flag is 1:

[0107] Step 2-1': Determine whether the repair times of the second parameter partition are less than 3 times. If so, continue to the next step.

[0108] Step 2-2': Try to repair the second parameter partition. If the repair is successful, reset the second parameter partition damage flag to, and end. Otherwise, jump to Step 2-1'.

[0109] Step 2-3': When it is determined that the backup parameter partition CRC error flag is equal to 0, start using the data in the backup parameter partition and give an alarm prompt for using the backup parameter partition.

[0110] For the backup parameter partition:

[0111] When the backup parameter partition damage flag is 0:

[0112] Step 3-1: When it is determined that the CRC error flag of the first parameter partition is 1 and the first parameter partition damage flag is 0, synchronize the backup parameter partition synchronization parameters to the first parameter partition.

[0113] Step 3-2: When it is determined that the second parameter partition CRC error flag is equal to 1 and the second parameter partition damage flag is 0, synchronize the backup parameter partition synchronization parameters to the second parameter partition.

[0114] When the backup parameter partition damage flag is 1:

[0115] Step 3-1': Determine whether the repair times of the backup parameter partition are less than 3 times. If so, continue to the next step.

[0116] Step 3-2': Try to repair the backup parameter partition. If the repair is successful, reset the backup parameter partition damage flag to 0 and continue to the next step. Otherwise, jump to Step 3-1'.

[0117] Step 3-3': When it is determined that the backup partition CRC error flag is equal to 0, start using the data in the backup parameter partition and give an alarm prompt for restoring the backup parameter partition to the default value, and end. Otherwise, go to the next step.

[0118] Step 3-4': When it is determined that the backup partition CRC error flag is equal to 1, use the default parameters and save them to the backup parameter partition, and give an alarm prompt that the backup parameter partition cannot be used.

[0119] The following are the specific startup steps in this embodiment. For the FLASH space with 2 parameter partitions and 1 backup partition, the startup method of the MCU includes the following steps:

[0120] Step 1: The inspection device starts up and enters the bootload stage. Determine whether to directly enter the firmware startup stage. If so, continue; otherwise, jump to step 15;

[0121] Step 2: Enter the first parameter partition repair sub-process;

[0122] Step 3: Determine the damage flag of the first parameter partition. If it is true, continue; otherwise, jump to step 8;

[0123] Step 4: Enter the second parameter partition repair sub-process;

[0124] Step 5: Determine the damage flag of the second parameter partition. If it is true, jump to step 7; otherwise, continue;

[0125] Step 6: Read the data in the second parameter partition and perform CRC check on the data in the second parameter partition. If the check is correct, jump to step 9; otherwise, jump to step 12;

[0126] Step 7: Perform CRC check on the data in the backup parameter partition. If the check is correct, read the backup parameter partition and jump to step 15; otherwise, synchronize the default configuration information to the backup parameter partition and then go to step 15;

[0127] Step 8: Read the data in the first parameter partition and perform CRC check on the data in the first parameter partition. If the check is correct, continue; otherwise, jump to step 12;

[0128] Step 9: Perform CRC check on the data in the backup parameter partition. If the check is correct, continue; otherwise, jump to step 11;

[0129] Step 10: Compare whether the data in the undamaged first parameter partition or the second parameter partition is the same as the data in the backup parameter partition. If they are the same, jump to step 15; otherwise, continue;

[0130] Step 11: Synchronize the data in the undamaged first parameter partition or the second parameter partition to the backup parameter partition and jump to step 15;

[0131] Step 12: Perform CRC check on the data in the backup parameter partition. If the check is correct, continue; otherwise, jump to step 14;

[0132] Step 13: Synchronize the data in the backup parameter partition to the undamaged first parameter partition or the second parameter partition and jump to step 15;

[0133] Step 14: Synchronize the default configuration information to the undamaged first parameter partition or second parameter partition, and continue to the next step;

[0134] Step 15: End.

[0135] The embodiments of the present invention adopt a combination of multi-partition storage and backup register technologies to record the damage status of the first parameter partition, the second parameter partition, and the backup parameter partition. In combination with the partition repair technology and the CRC data verification technology, when the MCU device system crashes the RTT real-time system due to FLASH problems, the flag of the damaged partition is recorded. After restarting, through this flag bit, when the first parameter partition is abnormal, the configuration is obtained from the second parameter partition or the backup parameter partition to start the system, and the mechanism for timely synchronization and recovery of damaged data can be solved, enhancing the stability and security of the system data, avoiding the possibility of system crashes in an environment where the system is frequently started, and greatly improving the robustness of the MCU device system.

[0136] Based on the same inventive concept as the above method embodiment, an electronic device is also provided in an embodiment of the present application, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the electronic device implements the control method in the above embodiment.

[0137] In one embodiment, the electronic device may be a server. In this embodiment, the structure of the electronic device may be as Figure 2 shown, including a memory 2001, a communication module 2003, and one or more processors 2002.

[0138] The memory 2001 is used to store the computer program executed by the processor 2002. The memory 2001 may mainly include a program storage area and a data storage area. Among them, the program storage area may store an operating system and programs required to run the instant messaging function, etc.; the data storage area may store various instant messaging information and operation instruction sets, etc.

[0139] The memory 2001 can be a volatile memory, such as a random-access memory (RAM); the memory 2001 can also be a non-volatile memory, such as a read-only memory, a flash memory, a hard disk drive (HDD), or a solid-state drive (SSD); or the memory 2001 is any other medium that can be used to carry or store a desired computer program in the form of instructions or data structures and can be accessed by a computer, but is not limited thereto. The memory 2001 can be a combination of the above memories.

[0140] The processor 2002 can include one or more central processing units (CPUs) or be a digital processing unit, etc. The processor 2002 is used to implement the above audio data processing method when calling the computer program stored in the memory 2001.

[0141] The communication module 2003 is used to communicate with the terminal device and other servers.

[0142] In the embodiments of the present application, the specific connection medium between the above-mentioned memory 2001, communication module 2003, and processor 2002 is not limited. In the embodiments of the present application Figure 2 it is described that the memory 2001 and the processor 2002 are connected through a bus 2004, and the bus 2004 is described by an arrow in Figure 2 The connection manners between other components are only for illustrative purposes and are not to be taken as limiting. The bus 2004 can be divided into an address bus, a data bus, a control bus, etc. For the convenience of description, Figure 2 only one arrow is used to describe it in

[0143] Based on the same inventive concept as the above method embodiments, an embodiment of the present invention further provides a computer-readable storage medium for storing a computer program. When the computer program runs on a computer, the electronic device is enabled to implement the control method in the above embodiments. The computer-readable storage medium may be a readable signal medium or a readable storage medium. The readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (non-exhaustive list) of the readable storage medium include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0144] Based on the same inventive concept as the above method embodiments, an embodiment of the present invention further provides a computer program product. The computer program product includes a computer program. When the program product runs on an electronic device, the computer program is used to enable the electronic device to execute the steps in the control method according to various exemplary embodiments described above in this specification. The program product may adopt any combination of one or more readable media. These computer program instructions may be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, such that the instructions executed by the processor of the computer or other programmable data processing device generate means for implementing the functions specified in Figure 1 one process or multiple processes and / or Figure 1 boxes or multiple boxes.

[0145] Although the preferred embodiments of the present application have been described, those skilled in the art can make additional changes and modifications once they learn the basic creative concept. Therefore, the appended claims are intended to be construed as including the preferred embodiments and all changes and modifications falling within the scope of the present application.

Claims

1. A startup method for an MCU, characterized in that: A parameter partition and a backup partition located in completely different storage spaces are partitioned in the FLASH memory; When the firmware starts up, it is judged whether the parameter partition is damaged: If the parameter partition is not damaged and the data in the partition remains correct, it is judged whether the data in the backup partition remains correct. If it is correct, it is further judged whether the data in the parameter partition is consistent with the data in the backup partition. If they are consistent, the data in the parameter partition is selected as the startup parameter source and startup is executed. If they are inconsistent, the data in the parameter partition is synchronized to the backup partition, and then the data in the parameter partition is selected as the startup parameter source and startup is executed; if it is incorrect, the data in the parameter partition is synchronized to the backup partition, and then the data in the parameter partition is selected as the startup parameter source and startup is executed; If the parameter partition is not damaged but the data in the partition does not remain correct, it is judged whether the data in the backup partition remains correct. If it is correct, the data in the backup partition is synchronized to the parameter partition. If it is incorrect, the data in the default partition is synchronized to the parameter partition, and then the data in the parameter partition is selected as the startup parameter source and startup is executed; If the parameter partition is damaged, it is judged whether the data in the backup partition remains correct. If it is correct, the data in the backup partition is selected as the startup parameter source and startup is executed. If it is incorrect, the data in the default partition is synchronized to the backup partition, and then the data in the backup partition is selected as the startup parameter source and startup is executed.

2. The method according to claim 1, wherein It is set that there are at least two parameter partitions located in completely different storage spaces, and each parameter partition has a preset priority; In the firmware startup stage, judging whether the parameter partition is damaged includes: Judging whether the parameter partition is damaged in the order of priority. Only when the parameter partition with a higher priority cannot be repaired, it is judged whether the parameter partition with the next priority is damaged. Otherwise, the data in the parameter partition with the current priority is used for subsequent steps.

3. The method according to claim 2, wherein Before the firmware starts up, it also includes: judging whether to enter the boot parameter configuration. If so, enter the boot parameter configuration. Otherwise, perform firmware startup; The entry into the boot parameter configuration includes: Judging whether the parameter partition is damaged in the order of priority. And if the parameter partition with the current priority is not damaged, select the parameter partition and read the configuration parameters in the parameter partition to the configuration page. Otherwise, judge whether the parameter partition with the next priority is damaged; Judging whether to save the configuration. If so, continue. Otherwise, end the boot parameter configuration; Calculate the CRC of the configuration parameters and save them together to the parameter partition corresponding to the configuration parameters, and end the boot parameter configuration.

4. The method according to claim 3, characterized in that, After the firmware starts up, it also includes: If a parameter configuration instruction is received, save the new parameters to the partition selected by the current system operation, and calculate the CRC of the new parameters and save them to the partition selected by the current system operation.

5. The method according to claim 2, wherein The judging whether the parameter partition is damaged in the order of priority, and only when the parameter partition with a higher priority cannot be repaired, judging whether the parameter partition with the next priority is damaged, includes: Determine whether the damage flag of the parameter partition of the current priority indicates damage. If so, read the erase count of the parameter partition of the current priority and determine whether the erase count is less than 3. If it is less than 3, erase the parameter partition of the current priority and determine whether the erase is successful. If the erase is successful, set the erase count of the parameter partition of the current priority to 0 and set the damage flag of the parameter partition of the current priority to indicate no damage.

6. The method according to claim 5, characterized in that, A register is configured to store the damage flags and erase counts of each parameter partition.

7. The method according to claim 5, characterized in that The method includes the following steps: Step 1: The inspection device starts and enters the bootload stage. Determine whether to directly enter the firmware startup stage. If so, continue; otherwise, jump to step 15. Step 2: Enter the first parameter partition repair sub-process. Step 3: Determine the damage flag of the first parameter partition. If it is true, continue; otherwise, jump to step 8. Step 4: Enter the second parameter partition repair sub-process. Step 5: Determine the damage flag of the second parameter partition. If it is true, jump to step 7; otherwise, continue. Step 6: Read the data in the second parameter partition and perform a CRC check on the data in the second parameter partition. If the check is correct, jump to step 9; otherwise, jump to step 12. Step 7: Perform a CRC check on the data in the backup parameter partition. If the check is correct, read the backup parameter partition and jump to step 15; otherwise, synchronize the default configuration information to the backup parameter partition and then go to step 15. Step 8: Read the data in the first parameter partition and perform a CRC check on the data in the first parameter partition. If the check is correct, continue; otherwise, jump to step 12. Step 9: Perform a CRC check on the data in the backup parameter partition. If the check is correct, continue; otherwise, jump to step 11. Step 10: Compare whether the data in the undamaged first parameter partition or the second parameter partition is the same as the data in the backup parameter partition. If they are the same, jump to step 15; otherwise, continue. Step 11: Synchronize the data in the undamaged first parameter partition or the second parameter partition to the backup parameter partition and jump to step 15. Step 12: Perform a CRC check on the data in the backup parameter partition. If the check is correct, continue; otherwise, jump to step 14. Step 13: Synchronize the data in the backup parameter partition to the undamaged first parameter partition or the second parameter partition and jump to step 15. Step 14: Synchronize the default configuration information to the undamaged first parameter partition or the second parameter partition and continue to the next step. Step 15: End.

8. An electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, the electronic device implements the method according to any one of claims 1 to 7.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium is used to store a computer program. When the computer program runs on a computer, the computer executes the method according to any one of claims 1 to 7.

10. A computer program product comprising instructions, characterized in that, When the instruction is executed alone or jointly by at least one processor of the computing device, the computing device executes the method according to any one of claims 1 to 7.