Program switching method and device of single-chip microcomputer, electronic equipment and storage medium

By maintaining flag bits in the microcontroller and running the startup boot program, the problem of time-consuming business logic switching and data loss in the existing technology is solved, real-time user program switching and upgrades are realized, and the convenience and efficiency of the microcontroller are improved.

CN118689607APending Publication Date: 2024-09-24REEMOON TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202410866409.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-01
Publication Date
2024-09-24

AI Technical Summary

Technical Problem

Existing microcontrollers need to re-program user programs when switching business logic, which is time-consuming and may result in data loss, making it impossible to switch between different business logics in real time.

Method used

By maintaining the program validity flag, upgrade flag, user program flag and boot flag on the microcontroller, run the startup boot program to determine the target user program, and switch or upgrade the user program after receiving instructions from the host computer to avoid re-burning. write operation.

Benefits of technology

It realizes real-time switching of user programs in the microcontroller without reprogramming, improves the convenience and efficiency of business logic switching, and avoids data loss.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118689607A
    Figure CN118689607A
Patent Text Reader

Abstract

The invention provides a program switching method and device of a single-chip microcomputer, electronic equipment and a storage medium, and relates to the field of single-chip microcomputers. According to the method, when a single-chip microcomputer is powered on, a bootstrap program is operated to determine an operated target user program; and in the process of running the target user program, if a program switching instruction of the upper computer is received, re-running the boot program after setting the flag bit so as to switch to other user programs specified by the program switching instruction to run. Compared with the prior art, under the condition that service logic switching needs to be carried out, the method supports real-time switching from the target user program to other user programs for operation, re-programming is not needed, and time saving and convenience are achieved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of single-chip microcomputers, and in particular to a program switching method, device, electronic equipment and storage medium of a single-chip microcomputer. Background Art

[0002] Current MCUs usually have a fixed set of user programs burned in for continuous use, but this is only suitable for a single business scenario logic. In some cases, different business logics need to be performed alternately. When the business logic is switched, the user program needs to be re-burned, which is time-consuming and may also cause data loss in the original user program. Summary of the invention

[0003] The purpose of the present invention is to provide a program switching method, device, electronic equipment and storage medium for a single-chip microcomputer to improve the problems existing in the prior art.

[0004] The embodiments of the present invention can be implemented as follows:

[0005] In a first aspect, the present invention provides a program switching method for a single chip microcomputer, the method comprising:

[0006] When the single chip microcomputer is powered on, a boot program is run to determine a target user program to be run;

[0007] During the process of running the target user program, if a program switching instruction is received from the host computer, the boot program is re-run after setting a flag to switch to another user program specified by the program switching instruction for running.

[0008] Optionally, the single-chip microcomputer is installed with a first user program and a second user program, and maintains a program validity flag, an upgrade flag and a boot flag;

[0009] The step of running the boot program to determine the target user program to be run includes:

[0010] Running the boot program and reading the program validity flag;

[0011] If the program validity flag is not a program null value, then reading the upgrade flag;

[0012] If the upgrade flag is not an upgrade status value, reading the boot flag;

[0013] When the boot flag is a first boot value, determining that the first user program is the target user program, and running the first user program;

[0014] When the boot flag is a second boot value, the second user program is determined to be the target user program, and the second user program is run.

[0015] Optionally, the single-chip microcomputer maintains a program validity flag, an upgrade flag, a user program flag and a boot flag;

[0016] The step of re-running the boot program after setting a flag bit to switch to another user program specified by the program switching instruction for running comprises:

[0017] During the process of running the target user program, if a program switching instruction is received from the host computer, the identifier of the program to be switched carried by the program upgrade instruction is obtained;

[0018] The boot flag is set to a switch boot value, and the user program flag is set to a program flag value of another user program corresponding to the program identifier to be switched;

[0019] Running the boot program and reading the program validity flag;

[0020] If the program validity flag is not a program null value, then reading the upgrade flag;

[0021] If the upgrade flag is a non-upgrade state value, reading the boot flag;

[0022] When the boot flag is the switch boot value, reading the user program flag;

[0023] Switch to other user programs represented by the program flag value of the user program flag bit to run, and reset the boot flag bit to the boot value of the other user programs.

[0024] Optionally, the method further includes:

[0025] During the process of running the target user program, if a program upgrade instruction is received from the host computer, the boot program is re-run after the flag is set to update the user program specified by the program upgrade instruction, and the target user program is re-run after the update is completed; the user program specified by the program upgrade instruction is the target user program or the other user program.

[0026] Optionally, the single-chip microcomputer maintains a program validity flag, an upgrade flag, a user program flag and a boot flag;

[0027] The step of re-running the boot program after setting a flag bit to update the user program specified by the program upgrade instruction, and re-running the target user program after the update is completed, comprises:

[0028] During the process of running the target user program, if a program upgrade instruction is received from the host computer, a new user program and an identifier of the program to be upgraded carried in the program upgrade instruction are obtained;

[0029] The upgrade flag is set to an upgrade state value, and the user program flag is set to a program flag value of the user program corresponding to the program identifier to be upgraded;

[0030] Running the boot program and reading the program validity flag;

[0031] If the program validity flag is not a program null value, then reading the upgrade flag;

[0032] If the upgrade flag is the upgrade state value, the user program represented by the user program flag is updated using the new user program, the program validity flag is updated, and the upgrade flag is set to a non-upgrade state value;

[0033] The boot flag is read to re-run the target user program based on the current boot value of the boot flag.

[0034] Optionally, the single-chip microcomputer maintains a program validity flag, and the method further includes:

[0035] During the running of the target user program, if a program validity query instruction sent by the host computer is received, the current value of the program validity flag is read;

[0036] The current value of the program validity flag is returned to the host computer.

[0037] Optionally, the single-chip microcomputer maintains a program validity flag, an upgrade flag and a boot flag;

[0038] Before the step of running a boot program to determine a target user program to be run when the single-chip microcomputer is powered on, the method further includes the step of running the boot program to install a program and setting the target user program to be initially run, so as to run the boot program to determine the target user program to be run when the single-chip microcomputer is powered on again, which includes:

[0039] Running the boot program and reading the program validity flag;

[0040] If the program validity flag is a null value, the host computer is notified that the program needs to be installed, and the first installation package and the second installation package sent by the host computer are received;

[0041] Install the first installation package and the second installation package to obtain a first user program and a second user program;

[0042] Setting the program validity flag to a dual program validity value, notifying the host computer of successful installation, and receiving program-specified instructions from the host computer;

[0043] Running a target user program specified by the program specifying instruction; the target user program is the first user program or the second user program;

[0044] The boot flag is set to a target boot value corresponding to the target user program, and the upgrade flag is set to a non-upgrade state value, so that the boot program is run when the single-chip microcomputer is powered on again to determine the running target user program.

[0045] In a second aspect, the present invention provides a program switching device for a single chip microcomputer, comprising:

[0046] A program determination module, used to run a boot program to determine a target user program to run when the single chip microcomputer is powered on;

[0047] The program switching module is used to set a flag bit and re-run the boot program if a program switching instruction is received from the host computer during the running of the target user program, so as to switch to other user programs specified by the program switching instruction for running.

[0048] In a third aspect, the present invention provides an electronic device, comprising a single-chip microcomputer, wherein the single-chip microcomputer is used to implement the program switching method of the single-chip microcomputer as described in the first aspect.

[0049] In a fourth aspect, the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the program switching method of the single-chip microcomputer described in the first aspect is implemented.

[0050] Compared with the prior art, the embodiment of the present invention provides a program switching method, device, electronic device and storage medium of a single-chip microcomputer. When the single-chip microcomputer is powered on, the method runs a boot program to determine the target user program to be run; during the process of running the target user program, if a program switching instruction from a host computer is received, the boot program is re-run after a flag is set to switch to other user programs specified by the program switching instruction for running. Compared with the prior art, when business logic switching is required, the present invention supports real-time switching from the target user program to other user programs for running, without the need for re-burning, which is time-saving and convenient. BRIEF DESCRIPTION OF THE DRAWINGS

[0051] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for use in the embodiments are briefly introduced below. It should be understood that the following drawings only show certain embodiments of the present invention and therefore should not be regarded as limiting the scope. For ordinary technicians in this field, other related drawings can be obtained based on these drawings without creative work.

[0052] Figure 1 One of the flow charts of a program switching method of a single-chip microcomputer provided in an embodiment of the present invention.

[0053] Figure 2 The second flowchart of a program switching method for a single-chip microcomputer provided by an embodiment of the present invention.

[0054] Figure 3 The third flowchart of a program switching method for a single-chip microcomputer provided by an embodiment of the present invention.

[0055] Figure 4 A fourth flow chart of a program switching method for a single-chip microcomputer provided in an embodiment of the present invention.

[0056] Figure 5 A fifth flow chart of a program switching method for a single-chip microcomputer provided in an embodiment of the present invention.

[0057] Figure 6 The sixth flowchart of a program switching method for a single-chip microcomputer provided in an embodiment of the present invention.

[0058] Figure 7 A schematic structural diagram of a program switching device for a single-chip microcomputer provided in an embodiment of the present invention. DETAILED DESCRIPTION

[0059] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0060] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0061] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, further definition and explanation thereof is not required in subsequent drawings.

[0062] In addition, the terms “first”, “second”, etc., if used, are merely used to distinguish between the descriptions and should not be understood as indicating or implying relative importance.

[0063] It should be noted that, in the absence of conflict, the features in the embodiments of the present invention may be combined with each other.

[0064] The program switching method of the single-chip microcomputer provided in the embodiment of the present invention can be applied to electronic devices, which may be but are not limited to small controllers equipped with single-chip microcomputers, industrial control equipment, drones, smart home devices, etc.

[0065] Optionally, the electronic device and the host computer are connected to each other by wired or wireless communication, and the single-chip microcomputer carried by the electronic device supports the installation of at least two user programs, so that the single-chip microcomputer controls the switching of user programs running in the single-chip microcomputer carried by the electronic device and updates different user programs. The following introduces the program switching method of the single-chip microcomputer by taking two user programs as an example.

[0066] Please refer to Figure 1 , Figure 1 A schematic flow chart of a program switching method of a single-chip microcomputer provided in an embodiment of the present invention, the method comprises the following steps S201-S202:

[0067] S201. When the single chip microcomputer is powered on, a boot program is run to determine a target user program to be run.

[0068] In this embodiment, when the single chip microcomputer is powered on, a boot program is run to determine a target user program from two user programs to run.

[0069] S202. During the process of running the target user program, if a program switching instruction is received from the host computer, a flag is set and the boot program is re-run to switch to another user program specified by the program switching instruction for running.

[0070] In this embodiment, during the process of running the target user program, if there is a need to switch business logic, the host computer will send a program switching instruction to the microcontroller of the electronic device, so that the microcontroller can set the flag and re-run the boot program to switch to other user programs specified by the program switching instruction for execution.

[0071] The program switching method of the single-chip microcomputer provided in the embodiment of the present invention runs the boot program to determine the target user program to be run when the single-chip microcomputer is powered on; during the process of running the target user program, if a program switching instruction from the host computer is received, the boot program is re-run after the flag is set to switch to other user programs specified by the program switching instruction for running. Compared with the prior art, when business logic switching is required, the present invention supports real-time switching from the target user program to other user programs for running, without the need for re-burning, which is time-saving and convenient.

[0072] Optionally, the single-chip microcomputer maintains a boot flag, an upgrade flag, a user program flag, and a program validity flag. When the single-chip microcomputer supports the installation of two user programs (the two user programs are the first user program and the second user program), the respective preset values ​​and meanings are shown in the following table (1):

[0073] Table (1) Flag bit comparison table

[0074]

[0075] It should be noted that the examples of the values ​​of the various flag bits given in Table (1) are based on the example that the flag bits occupy 8 bits. The present invention does not limit the number of bits occupied by the flag bits and the preset values ​​of each flag bit.

[0076] Optionally, in the initial stage of the electronic device's single-chip microcomputer, each flag bit is an initial value (for example, all 0), and the user program is empty, so it is necessary to install the user program and initialize each flag bit first. Therefore, please refer to Figure 2 Before the above step S201, the method may further include:

[0077] S101, running a boot program to install a program and set a target user program to be initially run, so that when the single-chip microcomputer is powered on again, the boot program is run to determine the target user program to be run.

[0078] Optional, in Figure 2 Based on Figure 3 , the sub-steps of step S101 may include S1011 to S1016.

[0079] S1011, run the boot program and read the program validity flag.

[0080] S1012: If the program validity flag is a null value, notify the host computer that the program needs to be installed, and receive the first installation package and the second installation package sent by the host computer.

[0081] In this embodiment, if the program validity flag is a program null value, the microcontroller sends the current program null value of the program validity flag to the host computer. The host computer can determine that the current user program of the microcontroller is empty and needs to be installed, that is, it will send the first installation package and the second installation package to the microcontroller.

[0082] S1013: Install the first installation package and the second installation package to obtain a first user program and a second user program.

[0083] S1014, setting the program validity flag to a dual program validity value, notifying the host computer of successful installation, and receiving program specified instructions from the host computer.

[0084] In this embodiment, after the installation of the single-chip microcomputer is completed, the program validity flag is reset to the dual-program validity value, and the current dual-program validity value of the program validity flag is sent to the host computer. The host computer can then determine that the single-chip microcomputer has been installed and there are two user programs. The host computer can select any one of the two user programs as the target user program that the single-chip microcomputer needs to run next. The single-chip microcomputer sends a program specification instruction to the single-chip microcomputer based on the selected one of the user programs.

[0085] S1015. Run the target user program specified by the program specifying instruction.

[0086] In this embodiment, the target user program specified by the program specifying instruction may be a first user program or a second user program.

[0087] S1016, setting the boot flag to a target boot value corresponding to the target user program, and setting the upgrade flag to a non-upgrade state value, so that when the single-chip microcomputer is powered on again, the boot program is run to determine the target user program to be run.

[0088] In this embodiment, when the microcontroller starts running the target user program, the boot flag is set to the target boot value corresponding to the target user program, and the upgrade flag is set to the non-upgrade state value, thereby ensuring that when the microcontroller is powered on again, the boot program can be run to determine the target user program to be run.

[0089] In the optional example, assuming that the target user program is the first user program, combined with the example in the above table (1), the microcontroller will set the boot flag to the first boot value 0xA1 and the upgrade flag to the non-upgrade state value 0x55. This example is only an example and is not limited here.

[0090] In this way, the microcontroller can complete the installation of the first user program and the second user program through the above steps S1011 to S1016, and determine the target user program to be run and perform corresponding flag configuration, so that the next time the microcontroller is powered on, it can directly determine the target user program by running the boot program and then run it.

[0091] In an optional implementation, Figure 2 Based on Figure 4 The process of "running the boot program to determine the target user program to be run" in the above step S201 may include the following sub-steps S2011 to S2015.

[0092] S2011. Run the boot program and read the program validity flag.

[0093] S2012. If the program validity flag is not a program null value, read the upgrade flag.

[0094] S2013: If the upgrade flag is not an upgrade status value, read the boot flag.

[0095] S2014: When the boot flag is the first boot value, determine that the first user program is the target user program, and run the first user program.

[0096] S2015: When the boot flag is the second boot value, determine that the second user program is the target user program, and run the second user program.

[0097] When the microcontroller is powered on, the target user program to be run is determined by running the boot program. The program validity flag, upgrade flag and boot flag are read in sequence, so as to determine the target user program to be run based on the current boot value of the boot flag.

[0098] In an optional implementation, if the program needs to be switched during the execution of the target user program, the MCU needs to reset the flag and re-run the boot program. Figure 2 Based on Figure 5 , the sub-steps of the above step S202 may include S2021 to S2027:

[0099] S2021. During the running of the target user program, if a program switching instruction is received from the host computer, an identifier of the program to be switched carried by the program upgrade instruction is obtained.

[0100] S2022: Set the boot flag bit to the switch boot value, and set the user program flag bit to the program flag value of other user programs corresponding to the program identifier to be switched.

[0101] In this embodiment, if a program switching instruction is received from the host computer, the single-chip microcomputer needs to reset the boot flag and the user program flag to the switching boot value and the program flag value of other user programs specified by the program switching instruction respectively.

[0102] S2023. Run the boot program and read the program validity flag.

[0103] S2024. If the program validity flag is not a program null value, read the upgrade flag.

[0104] S2025: If the upgrade flag is a non-upgrade state value, read the boot flag.

[0105] S2026. When the boot flag is a switch boot value, read the user program flag.

[0106] S2027, switching to other user programs represented by the program flag value of the user program flag bit to run, and resetting the boot flag bit to the boot value of other user programs.

[0107] In this embodiment, while switching to the program flag value of the user program flag bit to run other user programs, it is also necessary to reset the boot flag bit to the boot value of other user programs to ensure that the other user programs can be directly run the next time the microcontroller is powered on.

[0108] In an optional implementation, any user program can be upgraded during the running of the target user program. Figure 2 The method may further include the following step S203.

[0109] S203. During the process of running the target user program, if a program upgrade instruction is received from the host computer, the flag is set and the boot program is re-run to update the user program specified by the program upgrade instruction, and the target user program is re-run after the update is completed.

[0110] In this embodiment, the user program specified by the program upgrade instruction may be a target user program or another user program other than the target user program.

[0111] Optional, in Figure 2Based on Figure 6 , the sub-steps of step S203 may include S2031 to S2036.

[0112] S2031. During the process of running the target user program, if a program upgrade instruction is received from the host computer, a new user program and an identifier of the program to be upgraded carried in the program upgrade instruction are obtained.

[0113] S2032: Set the upgrade flag bit to the upgrade state value, and set the user program flag bit to the program flag value of the user program corresponding to the program identifier to be upgraded.

[0114] S2033, run the boot program and read the program validity flag.

[0115] S2034. If the program validity flag is not a program null value, read the upgrade flag.

[0116] S2035: If the upgrade flag is an upgrade state value, the user program represented by the user program flag is updated using a new user program, and the program validity flag is updated, and the upgrade flag is set to a non-upgrade state value.

[0117] S2036: Read the boot flag to re-run the target user program based on the current boot value of the boot flag.

[0118] In this embodiment, after the update is completed, it is necessary to update the program validity flag and reset the upgrade flag to a non-upgrade state value, and then read the current boot value of the boot flag to run the corresponding target user program.

[0119] In the optional implementation, the host computer can query the program status in the MCU. Figure 2 The method may further include the following steps S301-S302:

[0120] S301, during the process of running the target user program, if a program validity query instruction sent by the host computer is received, the current value of the program validity flag is read;

[0121] S302. Return the current value of the program validity flag to the host computer.

[0122] In this embodiment, when the single-chip microcomputer receives the program validity query instruction sent by the host computer, it directly reads the current value of the program validity flag and returns the current value of the program validity flag to the host computer, so that the host computer can know the current user program status of the single-chip microcomputer.

[0123] It should be noted that the present invention does not limit the type of device to which the host computer mentioned above belongs, and it can be but not limited to a personal computer, a server, a control device, etc. The execution order of each step in the above method embodiment is not limited to that shown in the drawings, and the execution order of each step shall be subject to the actual application situation.

[0124] Compared with the prior art, the embodiments of the present invention have the following beneficial effects:

[0125] In the present invention, the single-chip microcomputer maintains four flags, namely the boot flag, the upgrade flag, the user program flag and the program validity flag. Among them, the program validity flag is responsible for reflecting the validity of the user program installed by the single-chip microcomputer; the upgrade flag is used to be set to the upgrade state value when receiving the program upgrade instruction, to ensure that the upgrade process is directly entered when the boot program is re-run; the user program flag is used to be configured as the program flag value of the user program to be upgraded or the user program to be switched during program upgrade or program switching, to ensure the clarity of the upgrade object and the switching object, and to avoid updating or switching errors; the boot flag is used to determine the target user program to be run at power-on or after the update is completed. In the present invention, the single-chip microcomputer realizes the switching between different user programs through the maintenance and use of four flags, and also supports the updating of the user program specified by the host computer, with small resource occupation and fast switching or updating.

[0126] In order to execute the corresponding steps in the above method embodiment and various possible implementation modes, an implementation method of a program switching device of a single chip microcomputer is provided below.

[0127] See also Figure 7 , Figure 7 The schematic diagram of the structure of the program switching device of the single chip microcomputer provided by the embodiment of the present invention is shown. The program switching device 200 of the single chip microcomputer comprises: a program determination module 220 and a program switching module 230.

[0128] The program determination module 220 is used to run the boot program to determine the target user program to be run when the single chip microcomputer is powered on;

[0129] The program switching module 230 is used to set a flag and re-run the boot program if a program switching instruction is received from the host computer during the process of running the target user program, so as to switch to other user programs specified by the program switching instruction for running.

[0130] Optionally, the microcontroller maintains a program validity flag, an upgrade flag, a user program flag, and a boot flag.

[0131] Optionally, the program switching device 200 of the single chip microcomputer may further include an initialization module 210 for running a boot program to install the program and set the target user program to be initially run, so as to run the boot program to determine the target user program to be run when the single chip microcomputer is powered on again.

[0132] The initialization module 210 can be specifically used for: running the boot program and reading the program validity flag; if the program validity flag is a program null value, notifying the host computer that the program needs to be installed, and receiving the first installation package and the second installation package sent by the host computer; installing the first installation package and the second installation package to obtain the first user program and the second user program; setting the program validity flag to a dual program validity value, notifying the host computer that the installation is successful, and receiving the program specified instruction from the host computer; running the target user program specified by the program specified instruction; the target user program is the first user program or the second user program; setting the boot flag to the target boot value corresponding to the target user program, and setting the upgrade flag to a non-upgrade state value, so that the boot program is run when the microcontroller is powered on again to determine the target user program to be run.

[0133] Optionally, the program determination module 220 can be specifically used to: run the startup boot program and read the program validity flag; if the program validity flag is not a program null value, read the upgrade flag; if the upgrade flag is not an upgrade status value, read the boot flag; when the boot flag is a first boot value, determine that the first user program is the target user program, and run the first user program; when the boot flag is a second boot value, determine that the second user program is the target user program, and run the second user program.

[0134] Optionally, the program switching module 230 can be specifically used for: during the process of running the target user program, if a program switching instruction is received from the upper computer, then the identifier of the program to be switched carried by the program upgrade instruction is obtained; the boot flag is set to the switching boot value, and the user program flag is set to the program flag value of other user programs corresponding to the program identifier to be switched; the boot program is run and the program validity flag is read; if the program validity flag is not a program null value, the upgrade flag is read; if the upgrade flag is a non-upgrade state value, the boot flag is read; when the boot flag is a switching boot value, the user program flag is read; other user programs represented by the program flag value of the switch to the user program flag are run, and the boot flag is reset to the boot value of other user programs.

[0135] Optionally, the program switching device 200 of the single-chip microcomputer may also include a program upgrade module 240, which is used to set a flag and re-run the boot program if a program upgrade instruction from the host computer is received during the running of the target user program, so as to update the user program specified by the program upgrade instruction, and re-run the target user program after the update is completed; the user program specified by the program upgrade instruction is the target user program or other user programs.

[0136] Optionally, the program upgrade module 240 can be specifically used for: during the process of running the target user program, if a program upgrade instruction is received from the host computer, then obtaining the new user program and the identifier of the program to be upgraded carried by the program upgrade instruction; setting the upgrade flag to the upgrade status value, and setting the user program flag to the program flag value of the user program corresponding to the identifier of the program to be upgraded; running the boot program and reading the program validity flag; if the program validity flag is not a program null value, reading the upgrade flag; if the upgrade flag is an upgrade status value, using the new user program to update the user program represented by the user program flag, and updating the program validity flag, and setting the upgrade flag to a non-upgrade status value; reading the boot flag to re-run the target user program based on the current boot value of the boot flag.

[0137] Optionally, the program switching device 200 of the single-chip microcomputer may also include a query response module 250, which can be used to: during the process of running the target user program, if a program validity query instruction is received from the host computer, read the current value of the program validity flag; and return the current value of the program validity flag to the host computer.

[0138] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the program switching device 200 of the single-chip microcomputer described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.

[0139] An embodiment of the present invention further provides an electronic device, which includes a single-chip microcomputer, and the single-chip microcomputer is used to implement the program switching method of the single-chip microcomputer disclosed in the above embodiment.

[0140] The embodiment of the present invention also provides a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the program switching method of the single-chip microcomputer disclosed in the above embodiment is implemented. The computer-readable storage medium can be, but is not limited to: a USB flash drive, a mobile hard disk, an optical disk, a RAM (Random Access Memory), a ROM (Read Only Memory), a FLASH (Flash Memory), a PROM (Programmable Read-Only Memory), an EPROM (Erasable Programmable Read-Only Memory), an EEPROM (Electric Erasable Programmable Read-Only Memory), etc.

[0141] In summary, the embodiments of the present invention provide a program switching method, device, electronic device and storage medium for a single-chip microcomputer. When the single-chip microcomputer is powered on, the method runs a boot program to determine the target user program to be run; during the process of running the target user program, if a program switching instruction from a host computer is received, the boot program is re-run after a flag is set to switch to other user programs specified by the program switching instruction for operation. Compared with the prior art, when business logic switching is required, the present invention supports real-time switching from the target user program to other user programs for operation without the need for re-burning, which is time-saving and convenient.

[0142] The above are only specific embodiments of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A program switching method for a single chip microcomputer, characterized in that: The method comprises: When the single chip microcomputer is powered on, a boot program is run to determine a target user program to be run; During the process of running the target user program, if a program switching instruction is received from the host computer, the boot program is re-run after setting a flag to switch to another user program specified by the program switching instruction for running.

2. The method according to claim 1, characterized in that The single-chip microcomputer is installed with a first user program and a second user program, and maintains a program validity flag, an upgrade flag and a boot flag; The step of running the boot program to determine the target user program to be run includes: Running the boot program and reading the program validity flag; If the program validity flag is not a program null value, then reading the upgrade flag; If the upgrade flag is not an upgrade status value, reading the boot flag; When the boot flag is a first boot value, determining that the first user program is the target user program, and running the first user program; When the boot flag is a second boot value, the second user program is determined to be the target user program, and the second user program is run.

3. The method according to claim 1, characterized in that The single chip microcomputer maintains a program validity flag, an upgrade flag, a user program flag and a boot flag; The step of re-running the boot program after setting a flag bit to switch to another user program specified by the program switching instruction for running comprises: During the process of running the target user program, if a program switching instruction is received from the host computer, the identifier of the program to be switched carried by the program upgrade instruction is obtained; The boot flag is set to a switch boot value, and the user program flag is set to a program flag value of another user program corresponding to the program identifier to be switched; Running the boot program and reading the program validity flag; If the program validity flag is not a program null value, then reading the upgrade flag; If the upgrade flag is a non-upgrade state value, reading the boot flag; When the boot flag is the switch boot value, reading the user program flag; Switch to other user programs represented by the program flag value of the user program flag bit to run, and reset the boot flag bit to the boot value of the other user programs.

4. The method according to claim 1, characterized in that The method further comprises: During the process of running the target user program, if a program upgrade instruction is received from the host computer, the boot program is re-run after the flag is set to update the user program specified by the program upgrade instruction, and the target user program is re-run after the update is completed; the user program specified by the program upgrade instruction is the target user program or the other user program.

5. The method according to claim 4, characterized in that The single chip microcomputer maintains a program validity flag, an upgrade flag, a user program flag and a boot flag; The step of re-running the boot program after setting a flag bit to update the user program specified by the program upgrade instruction, and re-running the target user program after the update is completed, comprises: During the process of running the target user program, if a program upgrade instruction is received from the host computer, a new user program and an identifier of the program to be upgraded carried in the program upgrade instruction are obtained; The upgrade flag is set to an upgrade state value, and the user program flag is set to a program flag value of the user program corresponding to the program identifier to be upgraded; Running the boot program and reading the program validity flag; If the program validity flag is not a program null value, then reading the upgrade flag; If the upgrade flag is the upgrade state value, the user program represented by the user program flag is updated using the new user program, the program validity flag is updated, and the upgrade flag is set to a non-upgrade state value; The boot flag is read to re-run the target user program based on the current boot value of the boot flag.

6. The method according to claim 1, characterized in that The single-chip microcomputer maintains a program validity flag, and the method further includes: During the running of the target user program, if a program validity query instruction sent by the host computer is received, the current value of the program validity flag is read; The current value of the program validity flag is returned to the host computer.

7. The method according to claim 1, characterized in that The single chip microcomputer maintains a program validity flag, an upgrade flag and a boot flag; Before the step of running a boot program to determine a target user program to be run when the single-chip microcomputer is powered on, the method further includes the step of running the boot program to install a program and setting the target user program to be initially run, so as to run the boot program to determine the target user program to be run when the single-chip microcomputer is powered on again, which includes: Running the boot program and reading the program validity flag; If the program validity flag is a null value, the host computer is notified that the program needs to be installed, and the first installation package and the second installation package sent by the host computer are received; Install the first installation package and the second installation package to obtain a first user program and a second user program; Setting the program validity flag to a dual program validity value, notifying the host computer of successful installation, and receiving program-specified instructions from the host computer; Running a target user program specified by the program specifying instruction; the target user program is the first user program or the second user program; The boot flag is set to a target boot value corresponding to the target user program, and the upgrade flag is set to a non-upgrade state value, so that the boot program is run when the single-chip microcomputer is powered on again to determine the target user program to be run.

8. A program switching device for a single chip microcomputer, characterized in that: include: A program determination module, used to run a boot program to determine a target user program to run when the single chip microcomputer is powered on; The program switching module is used to set a flag bit and re-run the boot program if a program switching instruction is received from the host computer during the running of the target user program, so as to switch to other user programs specified by the program switching instruction for running.

9. An electronic device, characterized in that: It comprises a single chip microcomputer, and the single chip microcomputer is used to implement the program switching method of the single chip microcomputer as described in any one of claims 1-7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the program switching method of the single-chip microcomputer according to any one of claims 1 to 7 is implemented.