Method, device and equipment for initializing single register of embedded system and storage medium
By using dual flags of non-volatile and volatile storage media after the bootloader initialization in the embedded system, the initialization of the single-write constraint register is ensured only when the main application starts, thus solving the problem of unstable startup in embedded systems and achieving system startup stability.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- WUHAN HAIWEI TECH CO LTD
- Filing Date
- 2026-02-26
- Publication Date
- 2026-06-30
Smart Images

Figure CN122308934A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of system startup control technology, and in particular to a method, apparatus, device, and storage medium for initializing a single register in an embedded system. Background Technology
[0002] In the field of embedded systems, the initialization of special registers within the microcontroller is a crucial step when the bootloader jumps to the main application. Currently, common implementations fall into two main categories: one integrates the initialization logic within the jump function, resulting in repeated configuration attempts with each jump; the other completely delays the initialization task until the main application starts and executes it automatically. However, some special registers have a hardware constraint that they can only be successfully written to once after power-on, and there is currently no specific design for this characteristic. Repeated configuration attempts can cause microcontroller malfunctions, leading to boot failure. Therefore, improving system boot stability remains a problem that needs to be solved.
[0003] The above content is only used to help understand the technical solution of this application and does not represent an admission that the above content is prior art. Summary of the Invention
[0004] The main objective of this application is to provide a method, apparatus, device, and storage medium for initializing a single register in an embedded system, aiming to solve the technical problem of how to improve the stability of system startup.
[0005] To achieve the above objectives, this application proposes a method for initializing a single register in an embedded system, the method comprising:
[0006] In response to the startup signal of the embedded system, the boot program is run and the basic system initialization is performed; After the basic system is initialized, it is checked whether the jump conditions to the main application are met. The jump conditions are met when a valid main program start flag is detected in a non-volatile storage medium or a valid software jump instruction flag is detected in a volatile storage medium. When the jump condition is met, a jump operation from the bootloader to the main application is performed; After successfully jumping to the main application, the system initialization function of the main application is executed to complete the initialization of hardware registers with single-write constraints.
[0007] In one embodiment, the step of responding to the startup signal of the embedded system, running the bootloader, and performing basic system initialization includes: In response to a power-on signal or a hardware reset signal, the program counter is set to the starting address of the boot program's memory. The bootloader code is executed starting from the storage address to complete the basic system initialization.
[0008] In one embodiment, the step of checking whether the conditions for redirection to the main application are met includes: Read the first data stored at a fixed address on the non-volatile storage medium, and read the second data stored at a predetermined address on the volatile storage medium; Verify whether the first data and the second data are predefined instruction values respectively; If any flag passes the verification, the jump condition is deemed met; otherwise, the jump condition is deemed not met.
[0009] In one embodiment, the step of performing the jump operation from the bootstrap program to the main application includes: Obtain the initial stack pointer value from the main application's storage area; Set the microcontroller's main stack pointer to the initial stack pointer value; Set the microcontroller's interrupt vector table offset register to point to the interrupt vector table of the main application. Set the program counter to the entry address of the main application's reset interrupt service routine and begin execution.
[0010] In one embodiment, the step of executing the system initialization function of the main application to complete the initialization of hardware registers with single-write constraints includes: During the startup process of the main application, the system initialization function is called; During the execution of the system initialization function, a preset initialization hook function is called; In the initialization hook function, configuration parameters are written to a hardware register with a single-write constraint to complete the initialization.
[0011] In one embodiment, the step of calling a preset initialization hook function includes: During the execution flow of the system initialization function, it is checked whether there is a preset initialization hook function; When the existence of the initialization hook function is detected, the execution flow will jump to the entry address of the initialization hook function; Execute the code instructions contained in the initialization hook function.
[0012] In one embodiment, after the step of checking whether the conditions for jumping to the main application are met, the method further includes: If the jump condition is not met, the main loop of the bootloader will be entered. In the main loop, commands input from outside are listened for through the communication interface; If a jump command to the main application is detected, the predefined instruction value is written to a predetermined address in the volatile storage medium to set the software jump instruction flag. Based on the software jump instruction flag, the jump operation from the bootloader to the main application continues.
[0013] Furthermore, to achieve the above objectives, this application also proposes an initialization device for a single-use register in an embedded system, the initialization device comprising: The runtime module is used to respond to the startup signal of the embedded system, run the boot program, and perform basic system initialization. The checking module is used to check whether the jump conditions to the main application are met after the basic system is initialized. The jump conditions are met when a valid main program start flag is detected in a non-volatile storage medium or a valid software jump instruction flag is detected in a volatile storage medium. A jump module is used to execute a jump operation from the bootloader to the main application when the jump conditions are met; An initialization module is used to execute the system initialization function of the main application after successfully jumping to the main application, so as to complete the initialization of hardware registers with single-write constraints.
[0014] Furthermore, to achieve the above objectives, this application also proposes an initialization device for a single-use register in an embedded system, the device comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the single-use register initialization method for an embedded system as described above.
[0015] In addition, to achieve the above objectives, this application also proposes a storage medium, which is a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, it implements the steps of the embedded system single register initialization method described above.
[0016] In addition, to achieve the above objectives, this application also provides a computer program product, which includes a computer program that, when executed by a processor, implements the steps of the embedded system single register initialization method described above.
[0017] This application provides a method for initializing a single-write register in an embedded system. In response to the embedded system's startup signal, the method runs a bootloader and performs basic system initialization. After basic system initialization, it checks whether the jump condition to the main application is met. The jump condition is met when a valid main program startup flag is detected in non-volatile storage or a valid software jump instruction flag is detected in volatile storage. When the jump condition is met, a jump operation from the bootloader to the main application is performed. After successfully jumping to the main application, the system initialization function of the main application is executed to complete the initialization of the hardware register with a single-write constraint. By placing the initialization of the hardware register with a single-write constraint within the system initialization function of the main application and determining the jump condition based on dual flags in both non-volatile and volatile storage, this method ensures that the register is configured only once during the entire startup cycle, thereby preventing hardware anomalies caused by repeated initialization and improving system startup stability. Attached Figure Description
[0018] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0019] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a flowchart illustrating an embodiment of the single-time register initialization method for an embedded system according to this application. Figure 2 This is a flowchart illustrating a second embodiment of the embedded system single register initialization method of this application. Figure 3 This is a schematic diagram of the module structure of the single-time register initialization device for an embedded system according to an embodiment of this application; Figure 4 This is a schematic diagram of the device structure of the hardware operating environment involved in the single register initialization method of the embedded system in this application embodiment.
[0021] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0022] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0023] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0024] The main solution of this application is to respond to the startup signal of the embedded system, run the boot program and perform basic system initialization; after the basic system initialization, check whether the jump condition to the main application is met. The jump condition is met when a valid main program startup flag is detected in a non-volatile storage medium or a valid software jump instruction flag is detected in a volatile storage medium; when the jump condition is met, execute the jump operation from the boot program to the main application; after successfully jumping to the main application, execute the system initialization function of the main application to complete the initialization of hardware registers with single write constraints.
[0025] In the field of embedded systems, the initialization of special registers within the microcontroller is a crucial step when the bootloader jumps to the main application. Currently, common implementations fall into two main categories: one integrates the initialization logic within the jump function, resulting in repeated configuration attempts with each jump; the other completely delays the initialization task until the main application starts and executes it automatically. However, some special registers have a hardware constraint that they can only be successfully written to once after power-on, and there is currently no specific design for this characteristic. Repeated configuration attempts can cause microcontroller malfunctions, leading to boot failure. Therefore, improving system boot stability remains a problem that needs to be solved.
[0026] This application ensures that the hardware register with a single-write constraint is configured only once during the entire startup cycle by placing the initialization of the hardware register with a single write constraint in the system initialization function of the main application and by determining the jump condition based on the dual flags in the non-volatile and volatile storage media. This prevents hardware anomalies caused by repeated initialization and improves the stability of system startup.
[0027] Based on this, embodiments of this application provide a method for initializing a single register in an embedded system, referring to... Figure 1 , Figure 1 This is a flowchart illustrating the first embodiment of the single-time register initialization method for the embedded system of this application.
[0028] In this embodiment, the method for initializing the embedded system's single register includes steps S10 to S40: Step S10: Respond to the startup signal of the embedded system, run the boot program and perform basic system initialization; It should be noted that the executing entity in this embodiment can be a computing service device with data processing, network communication, and program execution functions, such as a tablet computer, personal computer, or mobile phone, or an electronic device or microcontroller unit of an embedded system capable of performing the above functions. The following description uses a microcontroller unit with a single-use register in an embedded system as an example to illustrate this embodiment and the subsequent embodiments.
[0029] It should be noted that the startup signal can be either a power-on signal received by the microcontroller unit (MCU) or a hardware reset signal. The bootloader is a special, fixed piece of software stored at the beginning of the microcontroller's non-volatile memory (usually flash memory) in an embedded system. It is the first program to run after the system is powered on or reset.
[0030] In one feasible approach, the steps of responding to the startup signal of the embedded system, running the boot program, and performing basic system initialization include: responding to a power-on signal or a hardware reset signal, setting the program counter to the storage start address of the boot program; and executing the boot program code from the storage start address to complete the basic system initialization.
[0031] It should be noted that the MCU's reset circuit generates an internal reset pulse upon detecting a power-on signal or a level change in the external hardware reset pin (i.e., a hardware reset signal). This pulse forcibly resets the program counter (PC) to the chip's preset boot vector address, which is the starting address of the bootloader's memory. Subsequently, the first instruction is fetched from this starting address and execution begins, thus entering the bootloader's code segment. The bootloader code first performs a series of operations to complete the basic system initialization, such as initializing the clock tree, configuring necessary memory controllers, and disabling unused peripheral clocks to reduce power consumption, thereby establishing a software environment suitable for the stable operation of the bootloader.
[0032] Step S20: After the basic system is initialized, check whether the jump conditions to the main application are met. The jump conditions are met when a valid main program start flag is detected in a non-volatile storage medium or a valid software jump instruction flag is detected in a volatile storage medium. It should be noted that after completing the basic system initialization, the Bootloader does not jump immediately. Instead, it first checks whether the conditions for jumping to the main application (APP) are met. This jump condition is determined by two OR flags: First, it checks whether a valid APP startup flag exists in a fixed location pre-defined for the APP in non-volatile storage media (such as Flash); second, it checks whether a valid jump instruction flag set by the software exists in a pre-defined address area in volatile storage media where data can be retained after a software reset.
[0033] In one feasible approach, the step of checking whether the jump condition to the main application is met includes: reading first data stored at a fixed address in a non-volatile storage medium and reading second data stored at a predetermined address in a volatile storage medium; verifying whether the first data and the second data are predefined instruction values respectively; when either flag passes the verification, it is determined that the jump condition is met, otherwise it is determined that the jump condition is not met.
[0034] It should be noted that the bootloader first reads a continuous block of data from a fixed starting address (usually the interrupt vector table location) in the APP program area of non-volatile storage medium (such as Flash), using this data as the main program startup flag to be verified, i.e., the first data. Simultaneously, it reads data from a pre-agreed address in volatile storage medium (such as RAM) specifically for communication, using this data as the software jump instruction flag to be verified, i.e., the second data. Next, the bootloader verifies these two sets of data. Verifying the main program startup flag typically involves checking if it conforms to predefined valid APP characteristics, such as determining if the first few words of the interrupt vector table are non-zero valid addresses, or calculating the cyclic redundancy check (CRC) code of the data and comparing it with a pre-stored value. Verifying the software jump instruction flag involves determining if it equals a predefined specific instruction value representing a "jump request". Finally, a decision is made: if the main program startup flag verification passes (indicating the existence of a complete and usable APP in Flash), or the software jump instruction flag verification passes, the jump condition is satisfied. If both flags fail verification, the jump condition is not satisfied.
[0035] In one feasible approach, after the step of checking whether the conditions for redirection to the main application are met, the method further includes: When the jump condition is not met, the main loop of the bootloader is entered. In the main loop, external input commands are listened for through the communication interface. If a jump command to the main application is heard, the predefined instruction value is written to a predetermined address in the volatile storage medium to set the software jump instruction flag. The jump operation from the bootloader to the main application continues to be executed based on the software jump instruction flag.
[0036] It's important to note that if the bootloader determines the jump condition is not met, it will not execute the jump but will instead enter its own main loop. Within this main loop, the bootloader continuously listens for external input commands through one or more communication interfaces. These commands may be for firmware updates, system diagnostics, etc. If, within this main loop, the bootloader detects a clear jump command requesting it to jump to the main application, it will not immediately execute the jump. Instead, it will write a predefined instruction value representing the jump request (e.g., 0xA5A5A5A5) to a predetermined address in the volatile memory (RAM), thus actively setting the software jump instruction flag. After setting the flag, the bootloader will trigger a software reset of the MCU by writing to the system control register.
[0037] Step S30: When the jump condition is met, execute the jump operation from the bootloader to the main application; It should be noted that when the jump conditions are met, the Bootloader will perform a safe jump operation. This operation is not a simple function call, but a series of low-level hardware context switches to ensure that the app can obtain a clean and independent running environment.
[0038] In one feasible approach, the step of performing the jump operation from the bootloader to the main application includes: obtaining an initial stack pointer value from the main application's storage area; setting the microcontroller's main stack pointer to the initial stack pointer value; setting the microcontroller's interrupt vector table offset register to point to the main application's interrupt vector table; and setting the program counter to the main application's reset interrupt service routine entry address and starting execution.
[0039] It's important to note that the bootloader first reads the initial main stack pointer (MSP) value of the application from a fixed location in the application's storage area (usually the first entry in the application's interrupt vector table). Then, the bootloader uses assembly instructions to set the current main stack pointer of the MCU core to the newly read initial stack pointer value of the application. This ensures that when the CPU switches to the application, its stack space will use the area defined by the application itself, avoiding conflicts with the bootloader's stack space. Next, the bootloader sets the MCU core's interrupt vector table offset register (VTOR) to point to the memory address where the application's interrupt vector table is located. This ensures that any subsequent interrupts will be looked up in the application's interrupt vector table to find the corresponding interrupt service routine entry point. Finally, the bootloader uses a jump instruction to directly set the program counter (PC) to the second entry in the application's interrupt vector table, which is the entry address of the application's reset interrupt service routine. Instruction fetching and execution begin from this address, thus completely and safely transferring control to the application, completing the jump operation.
[0040] Step S40: After successfully jumping to the main application, execute the system initialization function of the main application to complete the initialization of the hardware registers with single-write constraints.
[0041] It's important to note that after a successful jump, the first instruction of the application is executed. Within its own startup sequence, the application calls its system initialization function (usually named SystemInit). It is within this application initialization function execution flow that the configuration of special hardware registers with "single-write constraints" is finally completed. This ensures that these registers are configured only once during the entire MCU power-on cycle, at application startup, perfectly adhering to its hardware constraints.
[0042] This embodiment responds to the startup signal of the embedded system, runs the bootloader, and performs basic system initialization. After basic system initialization, it checks whether the jump conditions to the main application are met. Meeting the jump conditions means detecting a valid main program startup flag in non-volatile storage or a valid software jump instruction flag in volatile storage. When the jump conditions are met, a jump operation from the bootloader to the main application is performed. After successfully jumping to the main application, the system initialization function of the main application is executed to complete the initialization of hardware registers with single-write constraints. This embodiment ensures that the register is configured only once during the entire startup cycle by placing the initialization of hardware registers with single-write constraints within the system initialization function of the main application and determining the jump conditions based on dual flags in both non-volatile and volatile storage. This prevents hardware anomalies caused by repeated initialization and improves the stability of system startup.
[0043] Based on the first embodiment of this application, in the second embodiment of this application, the content that is the same as or similar to that in the first embodiment described above can be referred to the above description, and will not be repeated hereafter. Based on this, please refer to... Figure 2 Step S40 also includes steps S401 to S403: Step S401: In the startup process of the main application, the system initialization function is called; It should be noted that the app's startup code first calls its own system initialization function (SystemInit). This function is typically responsible for configuring the general hardware environment required for the app to run, such as the system clock and memory.
[0044] Step S402: During the execution of the system initialization function, a preset initialization hook function is called; It's important to note that during the execution of the SystemInit function, it calls a pre-defined, user-implemented initialization hook function (such as SystemInitHook). This hook function is weakly defined, allowing developers to override it in their user code to add custom initialization code without modifying the library files.
[0045] In one feasible approach, the step of calling a preset initialization hook function includes: in the execution flow of the system initialization function, detecting whether a preset initialization hook function exists; when the initialization hook function is detected, jumping the execution flow to the entry address of the initialization hook function; and executing the code instructions contained in the initialization hook function.
[0046] It's important to note that the system initialization function (SystemInit) includes a detection logic within its execution flow to determine if the user has defined and implemented an initialization hook function called SystemInitHook in the project. If the linker detects this function in the user's code, SystemInit will generate a jump instruction at a specific point, redirecting the execution flow to the entry address of the user-implemented SystemInitHook function. Subsequently, all code instructions within the SystemInitHook function body are executed sequentially. These instructions include operations for configuring special hardware registers. Because the SystemInit function is called only once by the application during startup within the MCU power-on cycle, the embedded SystemInitHook function is also executed only once, fundamentally eliminating the risk of duplicate configuration.
[0047] Step S403: In the initialization hook function, configuration parameters are written to the hardware register with a single write constraint to complete the initialization.
[0048] It should be noted that this application requires that the configuration code for "hardware registers with single-write constraints" (e.g., security option bytes used to lock clock configuration in certain chips, one-time programmable configuration registers, etc.) be written only and exclusively into this SystemInitHook function. When the application starts for the first time, SystemInit will call this hook function to complete the single, valid configuration of these special registers.
[0049] In this embodiment, during the startup process of the main application, a system initialization function is called. During the execution of the system initialization function, a preset initialization hook function is called. Within the initialization hook function, configuration parameters are written to a hardware register with a single-write constraint to complete the initialization. This embodiment ensures that the initialization operation is performed only once during the entire microcontroller power-on cycle by limiting the initialization code of the hardware register with the single-write constraint to a preset initialization hook function called by the main application's system initialization function. This strictly adheres to the hardware constraints of such special registers, fundamentally avoiding system hardware anomalies or lock-ups that may be caused by repeated configuration, thereby significantly improving the reliability and stability of the embedded system startup process.
[0050] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the single register initialization method of the embedded system of this application. Any simple modifications based on this technical concept are within the protection scope of this application.
[0051] This application also provides an embedded system single-time register initialization device, please refer to... Figure 3 The embedded system single-time register initialization device includes: Module 10 is used to respond to the startup signal of the embedded system, run the boot program and perform basic system initialization; The inspection module 20 is used to check whether the jump conditions to the main application are met after the basic system is initialized. The jump conditions are met when a valid main program start flag is detected in a non-volatile storage medium or a valid software jump instruction flag is detected in a volatile storage medium. Jump module 30 is used to execute a jump operation from the bootstrap program to the main application when the jump condition is met; The initialization module 40 is used to execute the system initialization function of the main application after successfully jumping to the main application, so as to complete the initialization of the hardware registers with single write constraints.
[0052] This application responds to the startup signal of the embedded system, runs the bootloader, and performs basic system initialization. After basic system initialization, it checks whether the jump condition to the main application is met. The jump condition is met when a valid main program startup flag is detected in non-volatile storage or a valid software jump instruction flag is detected in volatile storage. When the jump condition is met, a jump operation from the bootloader to the main application is performed. After successfully jumping to the main application, the system initialization function of the main application is executed to complete the initialization of hardware registers with single-write constraints. By placing the initialization of hardware registers with single-write constraints within the system initialization function of the main application and determining the jump condition based on dual flags in both non-volatile and volatile storage, this application ensures that the register is configured only once during the entire startup cycle, thereby preventing hardware anomalies caused by repeated initialization and improving the stability of system startup.
[0053] The embedded system single-use register initialization device provided in this application, employing the embedded system single-use register initialization method in the above embodiments, can solve the technical problem of how to improve the stability of system startup. Compared with the prior art, the beneficial effects of the embedded system single-use register initialization device provided in this application are the same as the beneficial effects of the embedded system single-use register initialization method provided in the above embodiments, and other technical features in the embedded system single-use register initialization device are the same as the features disclosed in the methods of the above embodiments, and will not be repeated here.
[0054] In one embodiment, the running module 10 is further configured to respond to a power-on signal or a hardware reset signal, point the program counter to the storage start address of the boot program, and execute the boot program code from the storage start address to complete the basic system initialization.
[0055] In one embodiment, the checking module 20 is further configured to read first data stored at a fixed address in a non-volatile storage medium and read second data stored at a predetermined address in a volatile storage medium; verify whether the first data and the second data are predefined instruction values respectively; when either flag passes the verification, it is determined that the jump condition is met, otherwise it is determined that the jump condition is not met.
[0056] In one embodiment, the jump module 30 is further configured to obtain an initial stack pointer value from the storage area of the main application; set the main stack pointer of the microcontroller to the initial stack pointer value; set the interrupt vector table offset register of the microcontroller to point to the interrupt vector table of the main application; and set the program counter to point to the entry address of the reset interrupt service routine of the main application and start execution.
[0057] In one embodiment, the initialization module 40 is further configured to call a system initialization function during the startup process of the main application; during the execution of the system initialization function, call a preset initialization hook function; and in the initialization hook function, write configuration parameters to a hardware register with a single write constraint to complete the initialization.
[0058] In one embodiment, the initialization module 40 is further configured to detect whether a preset initialization hook function exists during the execution flow of the system initialization function; when the initialization hook function is detected, the execution flow is jumped to the entry address of the initialization hook function; and the code instructions contained in the initialization hook function are executed.
[0059] In one embodiment, the checking module 20 is further configured to enter the main loop of the bootstrap program when the jump condition is not met; in the main loop, it listens for externally input commands through the communication interface; if a jump command to the main application is detected, it writes the predefined instruction value at a predetermined address in the volatile storage medium to set a software jump instruction flag; and continues to execute the jump operation from the bootstrap program to the main application program based on the software jump instruction flag.
[0060] This application provides an initialization device for a single-use register in an embedded system. The initialization device includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to execute the initialization method for the single-use register in the first embodiment described above.
[0061] The following is for reference. Figure 4 This document illustrates a schematic diagram of a structure suitable for initializing a single-use register of an embedded system in the embodiments of this application. The initialization device for a single-use register of an embedded system in the embodiments of this application may include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), in-vehicle terminals (e.g., in-vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers. Figure 4 The illustrated device for initializing a single register in an embedded system is merely an example and should not impose any limitations on the functionality and scope of use of the embodiments of this application.
[0062] like Figure 4As shown, the embedded system's single-register initialization device may include a processing unit 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in ROM (Read Only Memory) 1002 or a program loaded from storage device 1003 into RAM (Random Access Memory) 1004. RAM 1004 also stores various programs and data required for the operation of the embedded system's single-register initialization device. The processing unit 1001, ROM 1002, and RAM 1004 are interconnected via bus 1005. Input / output (I / O) interface 1006 is also connected to the bus. Typically, the following systems can be connected to I / O interface 1006: input devices 1007 including, for example, touchscreens, touchpads, keyboards, mice, image sensors, microphones, accelerometers, gyroscopes, etc.; output devices 1008 including, for example, liquid crystal displays (LCDs), speakers, vibrators, etc.; storage devices 1003 including, for example, magnetic tapes, hard disks, etc.; and communication devices 1009. Communication device 1009 allows the embedded system's single-register initialization device to communicate wirelessly or wiredly with other devices to exchange data. Although the figure shows embedded system single-register initialization devices with various systems, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems can be implemented or have alternatively.
[0063] Specifically, according to the embodiments disclosed in this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments disclosed in this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program containing program code for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via a communication device, or installed from storage device 1003, or installed from ROM 1002. When the computer program is executed by processing device 1001, it performs the functions defined in the methods of the embodiments disclosed in this application.
[0064] The embedded system single-use register initialization device provided in this application, employing the embedded system single-use register initialization method in the above embodiments, can solve the technical problem of how to improve the stability of system startup. Compared with the prior art, the beneficial effects of the embedded system single-use register initialization device provided in this application are the same as the beneficial effects of the embedded system single-use register initialization method provided in the above embodiments, and other technical features in the embedded system single-use register initialization device are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0065] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0066] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0067] This application provides a computer-readable storage medium having computer-readable program instructions (i.e., a computer program) stored thereon, the computer-readable program instructions being used to execute the embedded system single register initialization method in the above embodiments.
[0068] The computer-readable storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of computer-readable storage media may include, but are not limited to: electrical connections having one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the computer-readable storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0069] The aforementioned computer-readable storage medium may be included in the initialization device of the embedded system's single register; or it may exist independently and not be assembled into the initialization device of the embedded system's single register.
[0070] The aforementioned computer-readable storage medium carries one or more programs. When these programs are executed by the embedded system single-write register initialization device, the embedded system single-write register initialization device: responds to the embedded system's startup signal, runs the bootloader and performs basic system initialization; after basic system initialization, checks whether the jump condition to the main application is met, wherein the jump condition is met by detecting a valid main program startup flag in a non-volatile storage medium or a valid software jump instruction flag in a volatile storage medium; when the jump condition is met, performs a jump operation from the bootloader to the main application; after successfully jumping to the main application, executes the main application's system initialization function to complete the initialization of hardware registers with single-write constraints.
[0071] Computer program code for performing the operations of this application can be written in one or more programming languages or a combination thereof, including object-oriented programming languages such as Java, Smalltalk, and C++, and conventional procedural programming languages such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0072] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, can be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0073] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0074] The readable storage medium provided in this application is a computer-readable storage medium that stores computer-readable program instructions (i.e., a computer program) for executing the above-described method for initializing a single register in an embedded system, thereby solving the technical problem of improving the stability of system startup. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided in this application are the same as those of the single register initialization method for an embedded system provided in the above embodiments, and will not be repeated here.
[0075] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the embedded system single register initialization method described above.
[0076] The computer program product provided in this application can solve the technical problem of how to improve the stability of system startup. Compared with the prior art, the beneficial effects of the computer program product provided in this application are the same as those of the embedded system single register initialization method provided in the above embodiments, and will not be repeated here.
[0077] The above description is only a part of the embodiments of this application and does not limit the patent scope of this application. All equivalent structural transformations made under the technical concept of this application and using the contents of the specification and drawings of this application, or direct / indirect applications in other related technical fields, are included in the patent protection scope of this application.
Claims
1. A method for initializing a single register in an embedded system, characterized in that, The method includes: In response to the startup signal of the embedded system, the boot program is run and the basic system initialization is performed; After the basic system is initialized, it is checked whether the jump conditions to the main application are met. The jump conditions are met when a valid main program start flag is detected in a non-volatile storage medium or a valid software jump instruction flag is detected in a volatile storage medium. When the jump condition is met, a jump operation from the bootloader to the main application is performed; After successfully jumping to the main application, the system initialization function of the main application is executed to complete the initialization of hardware registers with single-write constraints.
2. The method as described in claim 1, characterized in that, The steps of responding to the startup signal of the embedded system, running the boot program, and performing basic system initialization include: In response to a power-on signal or a hardware reset signal, the program counter is set to the starting address of the boot program's memory. The bootloader code is executed starting from the storage address to complete the basic system initialization.
3. The method as described in claim 1, characterized in that, The step of checking whether the conditions for redirection to the main application are met includes: Read the first data stored at a fixed address on the non-volatile storage medium, and read the second data stored at a predetermined address on the volatile storage medium; Verify whether the first data and the second data are predefined instruction values respectively; If any flag passes the verification, the jump condition is deemed met; otherwise, the jump condition is deemed not met.
4. The method as described in claim 1, characterized in that, The steps of performing the jump operation from the bootloader to the main application include: Obtain the initial stack pointer value from the main application's storage area; Set the microcontroller's main stack pointer to the initial stack pointer value; Set the microcontroller's interrupt vector table offset register to point to the interrupt vector table of the main application. Set the program counter to the entry address of the main application's reset interrupt service routine and begin execution.
5. The method as described in claim 1, characterized in that, The step of executing the system initialization function of the main application to complete the initialization of hardware registers with single-write constraints includes: During the startup process of the main application, the system initialization function is called; During the execution of the system initialization function, a preset initialization hook function is called; In the initialization hook function, configuration parameters are written to a hardware register with a single-write constraint to complete the initialization.
6. The method as described in claim 5, characterized in that, The step of calling a preset initialization hook function includes: During the execution flow of the system initialization function, it is checked whether there is a preset initialization hook function; When the existence of the initialization hook function is detected, the execution flow will jump to the entry address of the initialization hook function; Execute the code instructions contained in the initialization hook function.
7. The method as described in claim 1, characterized in that, After the step of checking whether the conditions for redirection to the main application are met, the method further includes: If the jump condition is not met, the main loop of the bootloader will be entered. In the main loop, commands input from outside are listened for through the communication interface; If a jump command to the main application is detected, the predefined instruction value is written to a predetermined address in the volatile storage medium to set the software jump instruction flag. Based on the software jump instruction flag, the jump operation from the bootloader to the main application continues.
8. A single-use register initialization device for an embedded system, characterized in that, The device includes: The runtime module is used to respond to the startup signal of the embedded system, run the boot program, and perform basic system initialization. The checking module is used to check whether the jump conditions to the main application are met after the basic system is initialized. The jump conditions are met when a valid main program start flag is detected in a non-volatile storage medium or a valid software jump instruction flag is detected in a volatile storage medium. A jump module is used to execute a jump operation from the bootloader to the main application when the jump conditions are met; An initialization module is used to execute the system initialization function of the main application after successfully jumping to the main application, so as to complete the initialization of hardware registers with single-write constraints.
9. A device for initializing a single register in an embedded system, characterized in that, The device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, the computer program being configured to implement the steps of the embedded system single register initialization method as described in any one of claims 1 to 7.
10. A storage medium, characterized in that, The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, it implements the method for initializing a single register in an embedded system as described in any one of claims 1 to 7.