Methods for upgrading electricity meter software and electricity meters

By embedding the Boot program code into a constant array of the application source code in the electricity meter, a unified compilation and simplified design for electricity meter software upgrades are achieved. This solves the problems of complex partitioned compilation and program inability to run in existing technologies, and improves the reliability and convenience of software upgrades.

CN114490178BActive Publication Date: 2026-03-10QINGDAO ITECHENE TECH CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-22
Publication Date
2026-03-10

AI Technical Summary

Technical Problem

In the current technology, during the software upgrade process of electricity meters, the compilation of the on-chip Flash partition of the microcontroller is complex and prone to errors, and it is impossible to avoid the situation where the program cannot run.

Method used

By placing the boot program code in a constant array and embedding it into the application's source code, and upgrading it via serial port or off-chip memory, unified compilation and simplified program design can be achieved.

Benefits of technology

It simplifies the design of the boot program, reduces the amount of code, avoids program crashes, and improves the reliability and convenience of software upgrades.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114490178B_ABST
    Figure CN114490178B_ABST
Patent Text Reader

Abstract

This invention relates to a method for software upgrade of an electricity meter and an electricity meter itself. The method includes an electricity meter with a microcontroller powered on. The microcontroller has a serial port for communication and is electrically connected to external memory. The method includes the following steps: S1, initiating the software upgrade; S1.1, the microcontroller's internal Flash memory is pre-divided into a Boot program area and an application program area. The Boot program area is used to upgrade the application program area. The Boot program contains upgrade-related functions, variables, and constants, excluding the startup file. Interrupts are not allowed in the corresponding Boot function within the Boot program area. The write-back jump instruction for the Boot program's reset address is set to ZZYYYY, where YYYY is the address of the startup file. The Boot function entry address is XXXX, satisfying (XXXX&0xYYYY)==0xYYYY. The main function for upgrading the Boot area is Boot(). This invention is reasonably designed, compact in structure, and easy to use.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a method for upgrading electricity meter software and to an electricity meter, belonging to the field of power meter technology. It relates to the implementation of electricity meter software upgrade functions, and this invention is based on the Boot program design of a microcontroller. Background Technology

[0002] Currently, domestic electricity meters are not allowed to have software upgrade capabilities. However, the international DLMS protocol standard has clearly defined the file transfer process related to software upgrades and is already in use. To implement software upgrade functionality, the common practice is to divide the microcontroller's on-chip Flash memory into two areas: a Boot program area and an application program area. The Boot program is responsible for upgrading the application program. After the upgrade is complete, the Boot program jumps to the application program area to execute the normal program. The Boot program address must start from the reset address. To avoid code coupling between the two areas due to unified source code compilation, the Boot program and application program must be compiled independently using two projects. The compiled code is then concatenated to form a complete program. However, code concatenation is always cumbersome and error-prone. This invention provides a method to embed the Boot code into the application program's source code in binary form. This eliminates the need for further concatenation in the generated files and avoids situations where only the application program is burned, resulting in the program failing to run. Summary of the Invention

[0003] The technical problem this invention aims to solve is, in general, to provide a method for upgrading electricity meter software and an electricity meter itself. Some compilers, such as IAR for ARM, allow automatic linking of binary files in their compiler configuration, essentially performing automatic assembly, which is convenient but relies on the compiler's own functionality. The purpose of this invention is to design a method to embed the boot program into the application's source code in binary form, achieving unified compilation and application. This invention places the boot program code in a constant array, stores it in the code segment, and calls it in the application's startup file.

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

[0005] A method for upgrading the software of an electricity meter, based on an electricity meter, wherein the microcontroller of the electricity meter is powered on; the microcontroller has a serial port for communication; the microcontroller is electrically connected to an external memory.

[0006] The method includes the following steps;

[0007] S1, initiate software upgrade.

[0008] S1.1 The microcontroller's on-chip Flash memory is pre-divided into a Boot program area and an application program area. The Boot program area is used to upgrade the application program area.

[0009] The Boot program contains upgrade-related functions, variables, and constants, excluding the startup file. Interrupts are not allowed in the corresponding Boot function in the Boot program area. The write-back jump instruction for the reset address of the Boot program is set to ZZYYYY, where YYYY is the address of the startup file. The entry address of the Boot function is XXXX, satisfying (XXXX&0xYYYY)==0xYYYY; the main upgrade function in the Boot area is Boot().

[0010] S2, enter the Boot area to perform software upgrade; first, put the Boot program code in a constant array and store it in the code area; then, the application's startup file calls the Boot program code from the code area and embeds the Boot code into the application's source code in binary code form.

[0011] In S1, after S1.1, S1.2 is executed;

[0012] S1.2, The application sends a command to set the upgrade flag, and the meter restarts;

[0013] S1.2.1, Upgrade status judgment: If the upgrade start flag in the upgrade information area is valid and / or if the code at address 0x0001 is not 0x04, it is considered to have entered the upgrade status.

[0014] S1.2.2 First, the upgrade is triggered by a communication command; then, the upgrade program writes the upgrade start flag to the upgrade information code area. After the main program detects the upgrade flag, it enters while(1); second, it waits for the watchdog to reset and the system restarts.

[0015] S1.3, entering the Boot main function from the startup file; First, after the system restarts, in order to enter S2 later, the Boot area performs a software upgrade, calling the Boot entry function in the startup file; the settings are as follows:

[0016] Add the following to the beginning of the STARTUP.A51 file: EXTRN CODE(BootCode);

[0017] Before the statement `MOV SP,#? STACK-1`, add: `LCALL BootCode;`

[0018] Then, S2 is executed, calling the Boot section function to locate the address.

[0019] In S2, the boot process is handled.

[0020] S2.1 First, enter the Boot function and determine whether the upgrade flag is set;

[0021] If enabled, execute S2.1.1; otherwise, do not enable.

[0022] S2.1.1 First, erase the on-chip Flash area other than the Boot program; after erasing, write the application program; then, force a write-back jump instruction to the reset address of the Boot program; second, the write-back jump instruction replaces the address of the startup file with the entry address of the Boot function; third, after the upgrade is completed, restore the reset jump instruction to the address of the startup file.

[0023] S2.2, the Boot program receives the upgrade file, receives a complete frame of data, verifies its correctness, returns 'O' to indicate successful reception, and writes the data to Flash according to the address;

[0024] There are two methods for receiving upgrade files. Method 1 involves configuring the serial port and receiving the upgrade file via serial communication in the Boot function. The main loop checks the serial port send and receive flags, and the serial port protocol can be customized as needed. Method 2 involves downloading the upgrade file to the external memory in the application area. The Boot program reads the upgrade file from the external memory and then performs the upgrade.

[0025] S2.3, embed the Boot code in the application area; First, after the Boot program is debugged in S2.1-S2.2, the Boot program is compiled into binary code and placed in a preset constant array BootCode[] in hexadecimal form, and stored as the Boot.c file; Then, Boot.c is added to the application, and the code in BootCode[] is located, and the startup file in S2.1.1 is modified accordingly; Second, after the initialization code in the startup file, the required external call statements are added;

[0026] In the application, the startup file is located based on the address of S2.1.1.

[0027] S2.4, Before executing S2.1.1, the application is backed up;

[0028] S2.4.1 If the upgrade fails, execute this step; otherwise, execute step S2.4.2. Restore the program to the state before erasure. At the same time, the upgrade file must be verified. After the application is written, it is read out and compared with the verification code of the upgrade file. If the verification matches, the upgrade is successful. Otherwise, repeat the upgrade or restore the program to the state before erasure to improve the reliability and fault tolerance of the program upgrade.

[0029] S2.4.2 After sending the last frame of data and receiving all the upgrade file data, perform an overall data verification. If the internal program verification code of the chip matches the sent data verification code, the upgrade is successful; otherwise, perform an erase and upgrade again.

[0030] S3, after the upgrade is successful, address 0x0001 is written back to 0x04, the reset jump address is restored to the startup file address 0400, the system enters the while(1) loop, waits for restart, and completes the upgrade.

[0031] When using Keil C51

[0032] In S2.1.1, the reset address jump instruction of the Boot program is 020400, where 0400 is the address of the boot file. The write-back instruction replaces 0400 with the entry address of the Boot function. After the upgrade is completed, the reset jump instruction is restored to 020400. Assuming the entry address of the Boot function is XXXX, then (XXXX&0x0400) == 0x0400 must be satisfied. This is because Flash can only be written from 1 to 0, not from 0 to 1. Therefore, it is necessary to ensure that the reset jump address can be written to the address of the boot file.

[0033] When the startup file is located at address 0x0400 and the Boot function is located at address 0xF400, after the program is erased, the Flash is erased to all 1s to erase the program code data outside the Boot area, and the reset address jump instruction is written to 02F400 so that after the program is reset, it jumps directly to the Boot function. After the upgrade is completed, the reset address is written to 020400 to restore the normal jump of the startup file.

[0034] In S2.3, for the Keil C51 startup file, EXTRN CODE(BootCode) is added to the beginning of the startup file again, and after the initialization code, the instruction LCALL BootCode,MOV SP,#? STACK-1 is added; then, it jumps to the Boot function first, and then restores the stack after returning.

[0035] An automatic software-upgraded energy meter, wherein the microcontroller of the energy meter can be powered on; the microcontroller has a serial port for communication; the microcontroller is electrically connected to an external memory.

[0036] The microcontroller's on-chip Flash memory is pre-divided into a Boot program area and an application program area;

[0037] The Boot program area is used to upgrade the application area. The Boot program contains upgrade-related functions, variables, and constants, excluding the startup file. Interrupts are not allowed in the corresponding Boot function in the Boot program area. The write-back jump instruction for the reset address of the Boot program is set to ZZYYYY, where YYYY is the address of the startup file. The entry address of the Boot function is XXXX, satisfying (XXXX&0xYYYY)==0xYYYY. The Boot main function for upgrading the Boot program in the Boot area is Boot().

[0038] The code section contains a set of constants that store the Boot program code corresponding to the Boot program section;

[0039] The application area contains the startup file and the application's source code; the startup file is used to call the boot program code from the code area; the application's source code contains the boot code in binary form.

[0040] In the application area, there is an upgrade start flag, which is set after receiving an upgrade command and written to the upgrade information code area;

[0041] The main boot function is accessed from the startup file, where...

[0042] Call the Boot entry function in the startup file; set as follows:

[0043] Add the following to the beginning of the STARTUP.A51 file: EXTRN CODE(BootCode);

[0044] Before the statement `MOV SP,#? STACK-1`, add: `LCALL BootCode;`

[0045] The write-back jump instruction, after locating the address by calling the Boot section function, forces a write-back jump instruction to the reset address of the Boot program. The write-back jump instruction replaces the address of the startup file with the entry address of the Boot function, and after the upgrade is completed, restores the reset jump instruction to the address of the startup file.

[0046] The upgrade file, as a complete frame of data, is received by the Boot program. After verification, it returns 'O' to indicate successful reception and writes the data to the Flash memory according to the address.

[0047] This invention has three advantages: First, the boot program can start from any address, not limited to the reset address; second, after the upgrade is completed in the boot program, no jump is needed, only a chip reset is required; third, the boot program does not need to handle jumps at interrupt entry points. This simplifies the design of the boot program, reduces the amount of boot program code, avoids application crashes caused by missing jumps at certain interrupt entry points, and is also more convenient to use. Attached Figure Description

[0048] Figure 1 This is a standard software upgrade design process.

[0049] Figure 2 This is the software upgrade process of the present invention.

[0050] Figure 3 This is a reference to the Keil C51 compiler of the present invention. Detailed Implementation

[0051] Example 1, as Figure 1-3 This invention is based on an electricity meter, in which the microcontroller is powered on; the microcontroller has a serial port for communication; and the microcontroller is electrically connected to an external memory.

[0052] S1, the microcontroller's on-chip Flash is divided into a Boot program area and an application program area. The Boot program area is used to upgrade the application program area.

[0053] The boot program contains upgrade-related functions, variables, and constants. Excluding the startup file, interrupts are not allowed in the corresponding boot function within the boot program area. The write-back jump instruction for the boot program's reset address is set to ZZYYYY, where YYYY is the address of the startup file. The boot function entry address is XXXX, satisfying (XXXX&0xYYYY)==0xYYYY.

[0054] S2, First, the Boot program code is placed in a constant array and stored in the code segment; then, the application's startup file calls the Boot program code from the code segment and embeds the Boot code into the application's source code in binary code form;

[0055] Example 2: In S2, the Boot program is processed.

[0056] S2.1 First, enter the Boot function and determine whether the upgrade flag is set;

[0057] If enabled, execute S2.1.1; otherwise, do not enable.

[0058] S2.1.1 First, erase the on-chip Flash area other than the Boot program; after erasing, write the application program; then, force a write-back jump instruction to the reset address of the Boot program; second, the write-back jump instruction replaces the address of the startup file with the entry address of the Boot function; third, after the upgrade is completed, restore the reset jump instruction to the address of the startup file.

[0059] When using Keil C51, the reset jump instruction for the boot program is 020400, where 0400 is the address of the boot file. Therefore, the write-back instruction must replace 0400 with the entry address of the boot function. After the upgrade, the reset jump instruction is restored to 020400. Assuming the boot function entry address is XXXX, then (XXXX & 0x0400) must satisfy 0x0400. This is because Flash can only be written from 1 to 0, not from 0 to 1. Therefore, it is essential to ensure that the reset jump address can be written to the address of the boot file. For example, if the boot file is located at address 0x0400 and the boot function is located at address 0xF400, after program erasure, the Flash is erased to all 1s. Writing 02F400 to the reset address allows the program to reset and directly jump to the boot function. After the upgrade, the reset address is written back to 020400 to restore the normal jump to the boot file. This demonstrates that F400 can be written as 0400.

[0060] S2.2 The Boot program receives the upgrade file, including two schemes. Scheme 1: The upgrade file is received via serial communication in the Boot function, and the main loop determines the serial port send and receive flags. The serial port protocol can be customized as needed. Scheme 2: In the application area, the upgrade file is downloaded to the external memory. The Boot program reads the upgrade file from the external memory and then performs the upgrade.

[0061] S2.3, embed the Boot code in the application area; First, after the Boot program is debugged in S2.1-S2.2, the Boot program is compiled into binary code and placed in a preset constant array BootCode[] in hexadecimal form, and stored as the Boot.c file; Then, Boot.c is added to the application, and the code in BootCode[] is located, and the startup file in S2.1.1 is modified accordingly; Second, after the initialization code in the startup file, the required external call statements are added;

[0062] For example, in the Keil C51 startup file, EXTRN CODE(BootCode) is added to the beginning of the startup file, and after the initialization code, the instruction LCALL BootCode,MOV SP,#? STACK-1 is added. Then, the program jumps to the Boot function, returns, and restores the stack.

[0063] In the application, the startup file is located based on the address of S2.1.1.

[0064] S2.4 Before executing S2.1.1 and upgrading / wiping, the application is backed up. If the upgrade fails, the program is restored to the state before erasure. At the same time, the upgrade file is verified. After the application is written, it is read out and compared with the verification code of the upgrade file. If the verification matches, the upgrade is successful. Otherwise, the upgrade is repeated or the program before erasure is restored to improve the reliability and fault tolerance of the program upgrade.

[0065] As an example scenario:

[0066] This embodiment uses the Silergy 71M6543F chip as an example to illustrate the design of software upgrades. The compiler is Keil C51, and the upgrade process is carried out in the Boot function by receiving data through the serial port while upgrading.

[0067] The 71M6543F is a 64KB Flash memory, and its overall memory allocation is as follows:

[0068]

[0069] Application space planning is as follows:

[0070]

[0071] 1) Initiate software upgrade

[0072] During normal operation, the upgrade is triggered by communication commands. The program writes the upgrade start flag to the upgrade information code area. After the main program detects the upgrade flag, it enters while(1) and waits for the watchdog to reset and the system to restart.

[0073] 2) Call the Boot section function

[0074] After the system restarts, it needs to enter the Boot area for software upgrades, therefore the Boot entry function needs to be called in the startup file. The settings are as follows:

[0075] Add the following to the beginning of the STARTUP.A51 file: EXTRN CODE(BootCode)

[0076] Before the statement `MOV SP,#? STACK-1`, add: `LCALL BootCode`

[0077] 3) Address location

[0078] For the Keil C51 compiler, please refer to... Figure 3 The format is used for address location.

[0079] 4) Boot area code design

[0080] The main function for upgrading the Boot area is Boot(). To ensure the security of the upgrade process, a complete data verification is performed after sending the last frame of data. If the internal program verification code and the sent data verification code match, the upgrade is successful; otherwise, an erase is performed and the upgrade is restarted.

[0081] The upgrade process is as follows:

[0082] 4.1 Send a command from the application to set the upgrade flag, and the meter will restart.

[0083] 4.2 Enter the Boot main function from the startup file;

[0084] 4.2.1 Upgrade status determination;

[0085] 4.2.2 If the upgrade start flag in the upgrade information area is valid, the system is considered to have entered the upgrade state;

[0086] 4.2.3 If the code at address 0x0001 is not 0x04 (this address will be written as F4 after the erase is performed, ensuring that the Boot function can be re-entered after a power failure during the upgrade process), it is considered to have entered the upgrade state.

[0087] 4.3 Configure the serial port.

[0088] 4.4 Erase the program code data outside the Boot area and write the reset address jump instruction as 02F400.

[0089] 4.5 Detect the serial port receive flag and receive data.

[0090] 4.6 Upon receiving a complete data frame and verifying its correctness, return 'O' to indicate successful reception, and write the data to Flash according to the address.

[0091] 4.7 After receiving all the upgrade file data, the entire code address data is verified and compared. If there is an error, the Flash is erased, and the system waits for another upgrade.

[0092] After a successful upgrade (4.8), address 0x0001 is rewritten to 0x04, the reset jump address is restored to the startup file address 0400, and the system enters a while(1) loop, waiting to restart.

[0093] Upgrade to version 5.0 is complete.

[0094] The present invention has been described in detail for the purpose of making the disclosure clearer, and the prior art will not be listed in detail.

[0095] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. It is obvious to those skilled in the art that multiple technical solutions of the present invention can be combined. These modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention. All technical contents not described in detail in the present invention are well-known technologies.

Claims

1. A method for software upgrade of an electric energy meter, characterized by: The single-chip microcomputer of the electric energy meter is in a power-on state; the single-chip microcomputer has a serial port for communication; the single-chip microcomputer is electrically connected with an off-chip memory; The method comprises the following steps; S1, starting software upgrade, S1.1, in the single-chip microcomputer, the in-chip Flash is pre-divided into a Boot program area and an application program area, the Boot program area is used for upgrading the application program area; Wherein, the Boot program contains functions, variables and constants related to upgrading, excluding the startup file, the Boot function in the Boot program area is not allowed to start the interrupt, the write-back jump instruction of the reset address of the Boot program is set as ZZYYYY, YYYY is the address of the startup file, the Boot function entry address is XXXX, and satisfies (XXXX&0xYYYY)==0xYYYY; the Boot area upgrade main function is Boot(); S2, entering the Boot area for software upgrade; first, the Boot program code is placed in a constant array and stored in the code area; then, the startup file of the application program calls the Boot program code from the code area, and the Boot code is embedded into the source code of the application program in the form of binary code; In S1, after S1.1, S1.2 is executed; S1.2, the application program sends a command to set the upgrade flag, and the electric meter is restarted; S1.2.1, upgrade state judgment, if it is judged that the upgrade start flag in the upgrade information area is valid and / or if it is judged that the address 0x0001 code is not 0x04, it is considered that the upgrade state is entered; S1.2.2, first, the upgrade is triggered through a communication command; then, the upgrade program writes the upgrade start flag to the upgrade information code area, and the main program detects the upgrade flag and enters while(1); second, the watchdog reset is waited, and the system is restarted; S1.3, entering the Boot main function from the startup file; first, in order to enter S2, the Boot area for software upgrade after the system is restarted, the Boot entry function is called in the startup file; the following settings are made: In the STARTUP.A51 file header, add: EXTRN CODE(BootCode); Before the MOV SP, #?STACK-1 statement, add: LCALL BootCode; Then, S2 is executed, the Boot area function is called, and address positioning is performed.

2. The method for electric energy meter software upgrade according to claim 1, characterized in that: In S2, the Boot program is processed, S2.1, first, enter the Boot function, and judge whether the upgrade flag is set; If it is set, S2.1.1 is executed, otherwise, it is not set; S2.1.1, first, the chip area of the in-chip Flash other than the Boot program is erased; after the erasing is completed, the application program is written; then, the write-back jump instruction of the reset address of the Boot program is forced; Secondly, the write-back jump instruction changes the address of the startup file into the entry address of the Boot function; thirdly, after the upgrade is completed, the reset jump instruction is restored to the address of the startup file; S2.2, Boot program receives upgrade file, receives complete one frame data, checks correct, returns '0', indicates receiving success, writes data according to address to Flash; Receiving upgrade file includes two schemes, scheme one, carries out serial port configuration, receives upgrade file through serial port communication in Boot function, and judges serial port sending and receiving mark in main loop, and serial port protocol can be self-defined according to need; Scheme two, downloads upgrade file to off-chip memory in application program area, and Boot program reads out upgrade file from off-chip memory, and then upgrades; S2.3, Boot code is embedded in application program area; first, in S2.1-S2.2, after Boot program debugging is completed, Boot program is compiled to form binary code, and is placed in a preset constant array BootCode[] in hexadecimal form, and is stored as Boot.c file; Then, Boot.c is added to application program, and BootCode[] is subjected to code positioning, and the start-up file in S2.1.1 is correspondingly modified; Secondly, the required external calling statement is added after the initialization code of the start-up file; Among them, in the application program, the start-up file is subjected to address positioning according to execution S2.1.1; S2.4, before execution S2.1.1, the application program is backed up before upgrading and erasing; S2.4.1, if upgrading is wrong, this step is executed, otherwise S2.4.2 is executed; the program before erasing is restored, and the application program is written and then read out, and is compared with the check code of the upgrade file, and if the check is consistent, it indicates that upgrading is successful, otherwise, repeated upgrading or restoring the program before erasing is executed, so as to improve the reliability and fault tolerance of program upgrading; S2.4.2, after the last frame data is sent, the overall data check is carried out, the chip internal program check code and the data check code sent down are consistent, indicating that upgrading is successful, otherwise, erasing is executed, and re-upgrading is carried out; S3, after upgrading is successful, 0x0001 address is rewritten as 0x04, the reset jump address is restored to the start-up file address 0400, and the system enters while(1) loop, waits for restarting, and completes upgrading.

3. The method for electric energy meter software upgrade according to claim 2, characterized in that: When Keil C51 is adopted, In S2.1.1, the reset address jump instruction of Boot program is 020400, wherein 0400 is the address of the start-up file, so the rewriting instruction changes 0400 into the entry address of Boot function, after upgrading is completed, the reset jump instruction is restored to 020400, assuming that the entry address of Boot function is XXXX, then it must satisfy (XXXX & 0x0400) == 0x0400, because Flash can only write 1 to 0, and cannot write 0 to 1, so it must be ensured that the reset jump address can be written to the address of the start-up file; When the startup file is located at the address of 0x0400, the Boot function is located at the address of 0xF400, the program is erased, the Flash is erased to all 1s to erase the program code data outside the Boot area, and the reset address jump instruction is written as 02F400, so that the program is reset and directly jumps to the Boot function after the reset, and after the upgrade is completed, the reset address is written as 020400, and the normal jump of the startup file is restored; In S2.3, for the startup file of keil C51, EXTRN CODE(BootCode) is added to the head of the startup file again, and the instruction LCALL BootCode, MOV SP, #?STACK-1 is added after the initialization code; then, the Boot function is jumped to first, and the stack is restored after returning.

4. An electric energy meter capable of automatic software upgrade, characterized in that: The method for software upgrade of the electric energy meter according to claim 1; The single-chip microcomputer of the electric energy meter can be in a power-on state; the single-chip microcomputer has a serial port for communication; and the single-chip microcomputer is electrically connected with an off-chip memory; The in-chip Flash of the single-chip microcomputer is pre-divided into a Boot program area and an application program area; The Boot program area is used for upgrading the application program area; the Boot program includes functions, variables and constants related to upgrade, excludes the startup file, and does not allow to enable interrupts in the Boot function corresponding to the Boot program area; the write-back jump instruction of the reset address of the Boot program is set as ZZYYYY, YYYY is the address of the startup file, the entry address of the Boot function is XXXX, and (XXXX&0xYYYY)==0xYYYY is satisfied; the Boot main function of the Boot area is Boot(); The code area stores a set constant array storing Boot program code corresponding to the Boot program area; The application program area has source codes of the startup file and the application program; The startup file is used for calling the Boot program code from the code area; and the source code of the application program is embedded with the Boot code in the form of binary code.

5. The automated software upgradeable electric energy meter of claim 4, wherein: In the application program area, there is an upgrade startup flag, which is set after receiving an upgrade command and is written into the upgrade information code area; The Boot main function is entered from the startup file, The write-back jump instruction is used for forcibly writing back the jump instruction of the reset address of the Boot program after the address is located by calling the Boot area function; the write-back jump instruction changes the address of the startup file into the entry address of the Boot function, and restores the reset jump instruction to the address of the startup file after the upgrade is completed; The upgrade file is a complete frame of data, is received by the Boot program, and returns 'O' after being verified to be correct, indicating that the reception is successful; and the data is written into the Flash according to the address.

Citation Information

Patent Citations

  • A single chip microcomputer online upgrading method and system

    CN109240730A