Embedded microcontroller and data reading and writing method thereof

By using RAM and FLASH memory in embedded microcontrollers, the EEPROM function is simulated, and the problem of high data storage cost is solved, real-time reading, writing and power-down storage of data is realized, reducing hardware costs and extending the storage unit. Service life.

CN117289860BActive Publication Date: 2024-11-19BEIJING SMARTCHIP MICROELECTRONICS TECHNOLOGY CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311140151.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-05
Publication Date
2024-11-19
Estimated Expiration
2043-09-05

AI Technical Summary

Technical Problem

When existing processing devices realize instant data read, write and power-down storage, the hardware cost is high, and the lack of EEPROM leads to unstable data storage.

Method used

By using RAM and FLASH memory in embedded microcontrollers, data writing and flag value management methods are used to simulate the functions of EEPROM, ensuring that data is not lost after power loss and reducing hardware costs.

Benefits of technology

Realize instant read, write and power-down storage of data, reduce hardware costs and complexity, while extending the service life of the storage unit and ensuring data integrity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117289860B_ABST
    Figure CN117289860B_ABST
Patent Text Reader

Abstract

The present application discloses an embedded microcontroller and a data reading and writing method thereof. The processor can write the data to be stored in the EEPROM into the valid storage unit in the FLASH. Since the FLASH is non-volatile, it can ensure that the data will not be lost after the embedded microcontroller loses power. Therefore, by storing the data in the FLASH, the effect of storing in the EEPROM can be achieved. After the embedded microcontroller is initialized, the processor can write the data stored in the valid storage unit before initialization into the RAM for the processor to read. Since the RAM and the EEPROM have the same reading and writing mode, it can ensure that the processor can achieve the effect of accessing the EEPROM by accessing the RAM. In this way, the function of the EEPROM can be simulated. There is no need to add an additional EEPROM, so the hardware cost of the embedded microcontroller is effectively reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data reading and writing, and in particular to an embedded microcontroller and a data reading and writing method thereof. Background Art

[0002] Electrically erasable programmable read only memory (EEPROM) has the function of instant reading and writing, and can save the required data (such as configuration data) after power failure. Therefore, many processing devices (such as embedded microcontrollers) often need EEPROM to realize data reading, writing and saving.

[0003] However, most processing devices are not provided with EEPROM. Therefore, in order to realize the instant reading and writing of data and the preservation of data after power failure, in the related art, an EEPROM may be added to the processing device.

[0004] It can be seen that the hardware cost of the processing device in the related art to achieve real-time reading and writing of data and power-off preservation is relatively high. Summary of the invention

[0005] The present application provides an embedded microcontroller and a data reading and writing method thereof, which can solve the problem of high hardware cost of the processing device in the related art to realize instant reading and writing of data and power-off preservation. The technical solution is as follows:

[0006] On the one hand, a data reading and writing method is provided, which is applied to a processor of an embedded microcontroller, wherein the embedded microcontroller further comprises: a random access memory RAM and a flash memory FLASH, wherein the FLASH comprises a plurality of storage units arranged in sequence, wherein each of the plurality of storage units stores a flag value; the method comprises:

[0007] After the embedded microcontroller is initialized, first data stored in a first storage unit among the multiple storage units is written into the RAM for the processor to read, wherein the first storage unit is a valid storage unit among the multiple storage units before the embedded microcontroller is initialized, and the valid storage unit refers to: a storage unit to which data was written most recently, and a flag value of the valid storage unit is an extreme value among the flag values ​​of the multiple storage units;

[0008] After obtaining the second data to be stored in the EEPROM, writing the second data into the RAM, and obtaining a valid second storage unit from the plurality of storage units;

[0009] If the remaining capacity of the second storage unit is less than the capacity threshold, the multiple data stored in the RAM and the target address of each data in the multiple data are written into the next storage unit of the second storage unit, and the multiple data are all the data in the RAM that need to be stored in the EEPROM;

[0010] Updating the flag value of the next storage unit to use the next storage unit as a valid storage unit among the multiple storage units, wherein the flag value of the next storage unit after update is an extreme value among the flag values ​​of the multiple storage units;

[0011] The multiple data include the second data, and the target address of each of the data is the EEPROM address of the data in the EEPROM, or the RAM address in the RAM corresponding to the EEPROM address of the data.

[0012] Optionally, the flag value is used to indicate whether the storage unit stores data, the flag value of the storage unit that does not store data in the multiple storage units is a default value, and the difference between the flag values ​​of any two adjacent storage units that store data is a target value; before writing the multiple data stored in the RAM and the target address of each data in the multiple data into the next storage unit of the second storage unit, the method further includes:

[0013] A storage unit whose flag value is an extreme value among the multiple storage units is determined as the second storage unit.

[0014] Optionally, the extreme value is a minimum value; and the updated mark value of the next storage unit is a value obtained by subtracting the target value from the mark value of the second storage unit.

[0015] Optionally, each of the storage units further stores: a verification value of the flag value, wherein the verification value is generated based on the flag value; and determining a storage unit having an extreme flag value among the plurality of storage units as the second storage unit comprises:

[0016] For each storage unit in the plurality of storage units, verifying a flag value of the storage unit based on a verification value of the storage unit;

[0017] If the flag value of the storage unit passes the verification and the flag value of the storage unit is the minimum value of the flag values ​​of the multiple storage units, the storage unit is determined to be the second storage unit.

[0018] Optionally, the first storage unit further stores a check value of the first data, where the check value is obtained by processing the first data using a check algorithm; and writing the first data stored in a first storage unit among the plurality of storage units into the RAM comprises:

[0019] Verifying the first data according to the verification value;

[0020] If the verification is successful, the first data is written into the RAM.

[0021] Optionally, writing the first data stored in a first storage unit among the plurality of storage units into the RAM includes:

[0022] Writing first data stored in a first storage unit among the plurality of storage units into a first storage area of ​​the RAM;

[0023] Writing the second data into the RAM comprises:

[0024] Writing the second data into a second storage area of ​​the RAM;

[0025] The address of the first storage area is determined based on a first EEPROM address of the first data in the EEPROM, and the address of the second storage area is determined based on a second EEPROM address of the second data in the EEPROM.

[0026] Optionally, both the first storage area and the second storage area are located in a target storage space of the RAM, and the capacity of the target storage space is smaller than the capacity of the storage space of the RAM; and writing the multiple data stored in the RAM and the target address of each of the multiple data into a next storage unit of the second storage unit comprises:

[0027] The multiple data stored in the target storage space of the RAM and the target address of each data in the multiple data are written into the next storage unit of the second storage unit.

[0028] Optionally, the method further includes:

[0029] If the remaining capacity of the second storage unit is greater than or equal to the capacity threshold, the second data and the target address of the second data are written into the second storage unit.

[0030] Optionally, writing the first data stored in a first storage unit among the plurality of storage units into the RAM includes:

[0031] If the EEPROM emulation function of the embedded microcontroller is enabled, the first data stored in the first storage unit among the plurality of storage units is written into the RAM.

[0032] On the other hand, an embedded microcontroller is provided, the embedded microcontroller comprising: a processor, a random access memory RAM and a flash memory FLASH, the FLASH comprising a plurality of storage units arranged in sequence, each of the plurality of storage units storing a flag value; the processor is used to:

[0033] After the embedded microcontroller is initialized, first data stored in a first storage unit among the multiple storage units is written into the RAM for the processor to read, wherein the first storage unit is a valid storage unit among the multiple storage units before the embedded microcontroller is initialized, and the valid storage unit refers to: a storage unit to which data was written most recently, and a flag value of the valid storage unit is an extreme value among the flag values ​​of the multiple storage units;

[0034] After obtaining the second data to be stored in the EEPROM, writing the second data into the RAM, and obtaining a valid second storage unit from the plurality of storage units;

[0035] If the remaining capacity of the second storage unit is less than the capacity threshold, the multiple data stored in the RAM and the target address of each data in the multiple data are written into the next storage unit of the second storage unit, and the multiple data are all the data in the RAM that need to be stored in the EEPROM;

[0036] Updating the flag value of the next storage unit to use the next storage unit as a valid storage unit among the multiple storage units, wherein the flag value of the next storage unit after update is an extreme value among the flag values ​​of the multiple storage units;

[0037] The multiple data include the second data, and the target address of each of the data is the EEPROM address of the data in the EEPROM, or the RAM address in the RAM corresponding to the EEPROM address of the data.

[0038] Optionally, the flag value is used to indicate whether the storage unit stores data, the flag value of a storage unit in the multiple storage units that does not store data is a default value, and the difference between the flag values ​​of any two adjacent storage units that store data is a target value; the processor is further used to:

[0039] A storage unit whose flag value is an extreme value among the multiple storage units is determined as the second storage unit.

[0040] Optionally, the extreme value is a minimum value; and the updated mark value of the next storage unit is a value obtained by subtracting the target value from the mark value of the second storage unit.

[0041] Optionally, each of the storage units further stores: a verification value of the flag value, the verification value being generated based on the flag value; and the processor is configured to:

[0042] For each storage unit in the plurality of storage units, verifying a flag value of the storage unit based on a verification value of the storage unit;

[0043] If the flag value of the storage unit passes the verification and the flag value of the storage unit is the minimum value of the flag values ​​of the multiple storage units, the storage unit is determined to be the second storage unit.

[0044] Optionally, the first storage unit further stores a check value of the first data, where the check value is obtained by processing the first data using a check algorithm; and the processor is configured to:

[0045] Verifying the first data according to the verification value;

[0046] If the verification is successful, the first data is written into the RAM.

[0047] On the other hand, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the data reading and writing method described in the above aspects is implemented.

[0048] On the other hand, a computer program product comprising instructions is provided, and when the computer program product is run on the computer, the computer is enabled to execute the data reading and writing method described in the above aspects.

[0049] The beneficial effects of the technical solution provided by this application include at least:

[0050] The present application provides an embedded microcontroller and a data reading and writing method thereof, wherein the processor can write the data to be stored in the EEPROM into the valid storage unit in the FLASH. Since the FLASH is non-volatile, it can ensure that the data will not be lost after the embedded microcontroller loses power. Thus, the effect of storing the data in the EEPROM can be achieved by storing the data in the FLASH. After the embedded microcontroller is initialized, the processor can write the data stored in the valid storage unit before initialization into the RAM for the processor to read. Since the RAM and the EEPROM have the same reading and writing mode, it can ensure that the processor can achieve the effect of accessing the EEPROM by accessing the RAM. It can be seen that the function of the EEPROM can be simulated by the data reading and writing operation performed by the processor on the FLASH and RAM of the embedded microcontroller itself. There is no need to add an additional EEPROM, so the volume, hardware cost, hardware complexity and power consumption of the embedded microcontroller are effectively reduced. Moreover, since the FLASH includes multiple storage units, it can ensure that the service life of each storage unit is long.

[0051] In addition, after the remaining capacity of the effective second storage unit is less than the capacity threshold, the processor can first write the multiple data stored in the RAM and the target address of each data into the next storage unit of the second storage unit, and then use the next storage unit as the effective storage unit. In this way, it can be ensured that during the process of writing data to the next storage unit, even if the embedded microcontroller is accidentally powered off, after the embedded microcontroller is initialized, the processor can read the relatively complete data stored in the RAM before the power failure from the effective storage unit after the initialization.

[0052] Additional aspects and advantages of the present application will be given in part in the description below, and in part will become apparent from the description below, or will be learned through the practice of the present application. BRIEF DESCRIPTION OF THE DRAWINGS

[0053] Figure 1 It is a structural schematic diagram of an embedded microcontroller provided in an embodiment of the present application;

[0054] Figure 2 is a schematic diagram of the structure of another embedded microcontroller provided in an embodiment of the present application;

[0055] Figure 3 is a flow chart of a data reading and writing method provided in an embodiment of the present application;

[0056] Figure 4 is a flow chart of another data reading and writing method provided in an embodiment of the present application;

[0057] Figure 5is a flow chart of a method for writing first data into a first storage area of ​​a RAM provided by an embodiment of the present application;

[0058] Figure 6 is a structural schematic diagram of a storage unit provided in an embodiment of the present application;

[0059] Figure 7 It is a schematic diagram of writing acquired data into a RAM and a storage unit provided by an embodiment of the present application;

[0060] Figure 8 is a flow chart of a method for obtaining a first storage unit provided in an embodiment of the present application;

[0061] Fig. 9 is a flow chart of another method for obtaining a first storage unit provided in an embodiment of the present application;

[0062] Fig.10 This is a flow chart of a method for writing data in a first storage unit into a RAM provided in an embodiment of the present application. DETAILED DESCRIPTION

[0063] Embodiments of the present application are described in detail below, and examples of the embodiments are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present application, and should not be construed as limiting the present application.

[0064] Figure 1 is a schematic diagram of the structure of an embedded microcontroller provided in an embodiment of the present application, Figure 2 is a schematic diagram of the structure of another embedded microcontroller provided in an embodiment of the present application. Figure 1 and Figure 2 The embedded microcontroller may include: a processor 110, a random access memory (RAM) 120 and a flash memory (FLASH) 130. The processor 110 is connected to the RAM 120 and the FLASH 130 respectively.

[0065] from Figure 1 and Figure 2 It can be seen that the embedded microcontroller may further include a bus matrix 140. The processor 110 may be connected to the RAM 120 and the FLASH 130 via the bus matrix 140 respectively.

[0066] In an alternative implementation, see Figure 1The embedded microcontroller includes: a chip 100. The processor 110, RAM 120, FLASH 130 and bus matrix 140 are all located in the chip 100. That is, the RAM 120 can be an on-chip RAM, and the FLASH 130 can be an on-chip FLASH. At this time, the processor 110 can simulate the function of the EEPROM through the on-chip RAM 120 and FLASH 130 integrated in the chip 100.

[0067] In another alternative implementation, see Figure 2 , RAM120 is located outside the chip 100, that is, the RAM120 is an off-chip RAM. The embedded microcontroller may further include: an off-chip RAM controller 150 located in the chip 100. The off-chip RAM controller 150 may be connected to the bus matrix 140 and the RAM120 respectively. That is, the processor 110 may be connected to the RAM120 via the off-chip RAM controller 150. At this time, the processor 110 may simulate and implement the function of the EEPROM through the on-chip FLASH and the off-chip RAM.

[0068] Optionally, the chip may be a system on chip (SOC) or a digital signal processing (DSP) chip. The RAM may be a static random access memory (SRAM).

[0069] In the embodiment of the present application, the processor can use the entire storage space of the RAM and the K storage units of the FLASH to simulate the function of the EEPROM. Alternatively, the processor can take out a target storage space of n bytes (byte, B) from the RAM and take out K storage units from the FLASH. Then, the processor can simulate the function of the EEPROM by reading and writing data to the target storage space and the K storage units. For example, after the embedded microcontroller leaves the factory, the processor can take out the target storage space from the RAM and take out K storage units from the FLASH after detecting the need to simulate the EEPROM for the first time.

[0070] Wherein, n is the storage capacity of the EEPROM to be simulated (hereinafter referred to as capacity). The capacity of the target storage space is less than the capacity of the RAM storage space, that is, the target storage space is part of the RAM storage space. And the target storage space includes multiple storage areas of equal capacity, and the multiple storage areas correspond one-to-one to the multiple storage areas in the EEPROM to be simulated. And the capacity of each storage area in the target storage space is equal to the capacity of each storage area in the EEPROM. It can be seen that the data stored in the target storage space is the data stored in the EEPROM to be simulated. Accordingly, the target storage space can also be called the shadow RAM of the EEPROM. The capacity of each storage area in the EEPROM can be determined based on the maximum capacity of the data to be stored and pre-stored in the processor. For example, the capacity of each storage area in the EEPROM can be equal to the maximum capacity. The capacity of the data that can be stored refers to: the size of the storage area occupied by the data. For example, if the maximum capacity of the data is 2B, the capacity of each storage area in the EEPROM is 2B. Correspondingly, the capacity of each storage area in the target storage space is also 2B.

[0071] The sum of the capacities of K storage units may be less than the capacity of FLASH, where K is an integer greater than or equal to 2. Each storage unit may also include multiple storage areas of equal capacity, and the capacity of each storage area may be pre-stored. Since the storage area in the storage unit needs to store not only data but also the address of the data, the capacity of each storage area needs to be greater than the capacity of each storage area in the EEPROM, that is, greater than the capacity of each storage area in the target storage space. For example, the capacity of any storage area in each storage unit may be equal to twice the capacity of each storage area in the EEPROM. For example, assuming that the capacity of each storage area in the EEPROM is 2B, the capacity of the storage area in each storage unit may be 4B.

[0072] It is understandable that the addresses of multiple storage units can be connected, and the multiple storage units can be arranged in order, for example, in order from low to high addresses. The end address of the last storage unit in the multiple storage units can be the end address of the FLASH. And the total number of storage areas included in each storage unit can be greater than the total number of storage areas in the target storage space. Among them, the total number of storage areas in the target storage space is equal to the quotient of the capacity of the target storage space and the capacity of one storage area in the target storage space. The total number of storage areas in each storage unit is equal to the quotient of the capacity of the storage unit and the capacity of one storage area in the storage unit.

[0073] After the processor takes out the target storage space of n B, the address of each storage area in the target storage space and the address of the storage area in the EEPROM corresponding to the storage area can be recorded in the target address mapping relationship. That is, the target address mapping relationship records the RAM addresses of the multiple storage areas in the target storage space and the EEPROM address of a storage area in the EEPROM corresponding to each RAM address.

[0074] The address of each storage area in the target storage space is determined based on the address range of the target storage space and the capacity of the storage area. The address range can be determined by the processor. For example, if the processor starts from the end of the RAM storage space and takes out a storage space with a capacity of nB as the target storage space, the end address of the target storage space is the end address of the RAM, and the start address of the target storage space can be determined based on the end address and the capacity nB.

[0075] In the embodiment of the present application, at least one process may also be run in the processor. Each process may rely on the processor to read and write RAM and FLASH. In the embodiment of the present application, the end address of the target storage space is the end address of the storage space of the RAM, and the end address of the plurality of storage units is the end address of the storage space of the FLASH, so that the process of simulating the implementation of the EEPROM can be avoided, resulting in a change in the RAM (and FLASH) address required for the process, thereby avoiding affecting the operation of the process.

[0076] The embodiment of the present application provides a data reading and writing method, which is applied to a processor of an embedded microcontroller. The embedded microcontroller also includes: RAM and FLASH, and the FLASH includes a plurality of storage units arranged in sequence (such as arranged in order from low to high address). For example, the embedded microcontroller can be Figure 1 or Figure 2 See the embedded microcontroller shown. Figure 3 , the method comprising:

[0077] Step 101: After the embedded microcontroller is initialized, first data stored in a first storage unit among a plurality of storage units is written into a RAM for reading by a processor.

[0078] The first storage unit is a valid storage unit among the multiple storage units before the embedded microcontroller is initialized. The valid storage unit refers to: the storage unit to which data was most recently written among the multiple storage units before the chip was initialized. The number of valid storage units among the multiple storage units is 1. The initialization of the embedded microcontroller refers to the reset or power-on of the embedded microcontroller.

[0079] Step 102: After obtaining the second data to be stored in the EEPROM, write the second data into the RAM, and obtain a valid second storage unit from a plurality of storage units.

[0080] A process that needs to read and write EEPROM may be run in the processor. When the process needs to write the second data into EEPROM, the processor can obtain the second data to be stored in EEPROM. Then, the processor can write the second data into RAM and obtain a valid second storage unit from multiple storage units.

[0081] The second storage unit is a valid storage unit among multiple storage units after the embedded microcontroller is initialized. The valid storage unit refers to: a storage unit to which data is written most recently among multiple storage units after the chip is initialized.

[0082] Step 103: If the remaining capacity of the second storage unit is less than the capacity threshold, the multiple data stored in the RAM and the target address of each data in the multiple data are written into the next storage unit of the second storage unit.

[0083] After the processor obtains the second storage unit, it can detect whether the capacity of the second storage unit is less than the capacity threshold. If the processor determines that the remaining capacity of the second storage unit is less than the capacity threshold, it can be determined that the second storage unit cannot store the second data and the target address of the second data, and then the multiple data stored in the RAM and the target address of each of the multiple data can be written to the next storage unit of the second storage unit.

[0084] The capacity threshold may be pre-stored by the processor, and the capacity threshold may be determined based on the capacity of a storage area occupied by a data and a target address of the data. For example, the capacity threshold may be 4B.

[0085] The plurality of data includes the second data. If the processor uses all storage spaces of the RAM to simulate the function of the EEPROM, the plurality of data is all the data stored in the RAM. If the processor uses the target storage space of the RAM to simulate the function of the EEPROM, the plurality of data is all the data stored in the target storage space.

[0086] Step 104: Use the next storage unit as a valid storage unit among the multiple storage units.

[0087] After the processor writes the multiple data in the RAM into the next storage unit of the second storage unit, the next storage unit can be used as a valid storage unit among the multiple storage units. Correspondingly, the processor can use the second storage unit as an invalid storage unit.

[0088] In summary, the embodiment of the present application provides a data reading and writing method, wherein the processor can write the data to be stored in the EEPROM into the valid storage unit in the FLASH. Since the FLASH is non-volatile, it can ensure that the data will not be lost after the embedded microcontroller loses power. Thus, the effect of storing in the EEPROM can be achieved by storing the data in the FLASH. After the embedded microcontroller is initialized, the processor can write the data stored in the valid storage unit before initialization into the RAM for the processor to read. Since the RAM and the EEPROM have the same reading and writing mode, it can ensure that the processor can achieve the effect of accessing the EEPROM by accessing the RAM. It can be seen that the data reading and writing operations performed by the processor on the FLASH and RAM of the embedded microcontroller itself can simulate the function of the EEPROM, that is, the instant reading and writing and power-off preservation of the data can be realized. There is no need to add an additional EEPROM, so the volume, hardware cost, hardware complexity and power consumption of the embedded microcontroller are effectively reduced. In addition, since the FLASH includes multiple storage units, it can ensure that the service life of each storage unit is long.

[0089] In addition, after the remaining capacity of the effective second storage unit is less than the capacity threshold, the processor can first write the multiple data stored in the RAM and the target address of each data into the next storage unit of the second storage unit, and then use the next storage unit as the effective storage unit. In this way, it can be ensured that during the process of writing data to the next storage unit, even if the embedded microcontroller is accidentally powered off, after the embedded microcontroller is initialized, the processor can read the relatively complete data stored in the RAM before the power failure from the effective storage unit after the initialization.

[0090] The embodiment of the present application takes the example of a processor using a target storage space of a RAM to simulate and implement the function of an EEPROM to exemplify the data reading and writing method provided in the embodiment of the present application. The method can be applied to a processor of an embedded microcontroller. Figure 4 , the method may include:

[0091] Step 201: After the embedded microcontroller is initialized, a first storage unit is determined from a plurality of storage units.

[0092] The first storage unit is a valid storage unit among multiple storage units before the embedded microcontroller is initialized. The valid storage unit refers to the storage unit to which data was most recently written among multiple storage units before the chip is initialized. The embedded microcontroller initialization refers to the reset or power-on of the embedded microcontroller.

[0093] In an embodiment of the present application, each of the plurality of storage units may store: a flag value for indicating a valid state of the storage unit. The valid state may include: valid or invalid. And the number of valid storage units in the plurality of storage units is 1. The processor may detect the flag value of each storage unit after the embedded microcontroller is initialized, and may determine the storage unit to which the flag value indicating that the valid state is valid belongs as the first storage unit.

[0094] In an optional example, the flag value of each storage unit may be a first value or a second value. The valid state indicated by the first value is valid, and the valid state indicated by the second value is invalid. The first value is different from the second value, for example, the first value may be 1, and the second value may be 0.

[0095] For example, assuming that the first value is 1 and the second value is 0, after the embedded microcontroller is initialized, the processor can detect whether the flag value of each storage unit in the multiple storage units is 1. If the processor determines that the flag value of the storage unit is 0, it can be determined that the valid state indicated by the flag value is invalid, that is, the storage unit is an invalid storage unit. If the processor determines that the flag value of the storage unit is 1, it can be determined that the valid state indicated by the flag value is valid, that is, the storage unit is a valid storage unit, and then the storage unit can be determined as the first storage unit.

[0096] In another optional example, the flag value of a storage unit that does not store data in the plurality of storage units arranged in order is a default value. The difference between the flag values ​​of any two adjacent storage units storing data is a target value. The difference between the flag values ​​of the two adjacent storage units may refer to: a value obtained by subtracting the flag value of a storage unit from the flag value of the next storage unit, or a value obtained by subtracting the flag of the next storage unit from the flag value of the storage unit.

[0097] Correspondingly, if the difference is a value obtained by subtracting the mark value of the next storage unit from the mark value of a storage unit, the mark value of each storage unit may be the difference between the mark value of the last storage unit storing data and the target value. If the difference is a value obtained by subtracting the mark value of the next storage unit from the mark value of the storage unit, the mark value of each storage unit may be the sum of the mark value of the last storage unit storing data and the target value.

[0098] It is understandable that the flag value of the first storage unit storing data can be the difference (or sum) between the default value and the target value. It can be seen that the flag value of the storage unit storing data can decrease or increase, and can indicate whether the storage unit stores data.

[0099] It can also be understood that the processor usually writes data to the multiple storage units in sequence according to the arrangement order of the multiple storage units, that is, first writes data to the first storage unit, and after the first storage unit is full, writes data to the next storage unit, and writes data to the multiple storage units in turn. Therefore, it can be determined without a doubt that the flag value of the storage unit written by the data most recently acquired by the processor is the largest (or smallest). Since the storage unit written by the data most recently acquired by the processor is a valid storage unit, the processor can determine the storage unit with the extreme flag value among the multiple storage units as the first storage unit.

[0100] For example, if the flag value of the storage unit storing data decreases, the processor can determine the storage unit with the smallest flag value as the first storage unit. If the flag value of the storage unit storing data increases, the processor can determine the storage unit with the largest flag value as the first storage unit.

[0101] It is understandable that the default value in the increasing scenario is different from the default value in the decreasing scenario. For example, assuming that the number of bits of the flag value is 32 bits, the default value in the increasing scenario may be 0x00000000, and the default value in the decreasing scenario may be 0xFFFFFFFF. 0x represents hexadecimal.

[0102] Optionally, for a scenario where the flag value of a storage unit storing data decreases or increases, each storage unit may further include: a verification value of the flag value of the storage unit, the verification value being used for the processor to verify the accuracy of the flag value, wherein the verification value of a storage unit not storing data is the same as the flag value.

[0103] In an embodiment of the present application, the verification value of the storage unit storing data may be obtained by performing a bitwise inversion operation on the flag value of the storage unit. Alternatively, the verification value of the storage unit storing data may be obtained by processing the flag value of the storage unit using a verification algorithm. The verification algorithm may be a sum verification algorithm, a redundancy verification algorithm, or an exclusive-or verification algorithm.

[0104] After the embedded microcontroller is initialized, the processor can verify the flag value of each storage unit among multiple storage units based on the verification value of the storage unit, and determine the storage unit among the multiple storage units whose flag value passes the verification and whose flag value is an extreme value as the first storage unit.

[0105] For example, assuming that the verification value of the storage unit storing data is obtained by performing a bitwise inversion operation on the flag value of the storage unit, the processor can perform an XOR operation on the flag value and the verification value, and detect whether the result of the XOR operation is a reference value. The reference value can be pre-stored by the processor. If the processor determines that the result is a reference value, it can be determined that the flag value has passed the verification. If the processor determines that the result is not a reference value, it can be determined that the flag value has not passed the verification.

[0106] For example, if the default value is 0xFFFFFFFF or 0x00000000, and the verification value is obtained by bitwise inverting the flag value, the reference value may be 0xFFFFFFFF.

[0107] Optionally, after determining that the EEPROM emulation function is enabled, the processor may determine a first storage unit from a plurality of storage units and execute the following steps 202 to 209. In this way, the use flexibility of the processor may be improved.

[0108] For example, the embedded microcontroller (such as a processor) may be connected to a display screen, and the display screen may display an enable switch control having an EEPROM emulation function. If the user requires the embedded microcontroller to enable the EEPROM emulation function, the user may touch the enable switch control so that the switch control indicates that the switch state is an open state. Thereafter, if the user does not require the embedded microcontroller to enable the EEPROM emulation function, the user may touch the enable switch control again so that the switch control indicates that the switch state is an off state.

[0109] It can be understood that after the EEPROM simulation function of the processor is enabled, if no data is written into any of the K storage cells of the FLASH, that is, the processor has not started to simulate the function of implementing the EEPROM, then after receiving the data to be stored in the EEPROM, the processor can first write the data and the target address of the data into the first storage cell among the multiple storage cells, and then determine the first storage cell as a valid storage cell.

[0110] Step 202: Write the first data stored in the first storage unit into the RAM for the processor to read.

[0111] After the processor determines the first storage unit, it can read the first data from the first storage unit and erase the RAM. Then, the processor can write the read first data into the first storage area of ​​the RAM after the erasure process (i.e., the first storage area in the target storage space), so that the processor can access the RAM based on the target address of the first data, thereby reading the first data and performing corresponding configuration. For example, the processor can send a read control signal to the FLASH so that the FLASH feeds the first data back to the processor. Then, the processor can send a write control signal to the RAM, as well as the address of the first storage area, so that the RAM writes the first data into the first storage area.

[0112] The value of each storage area of ​​the erased RAM may be 0xFF, where 0xFF indicates that no data is written. The first data is configuration data that is originally required to be stored in the EEPROM. The address of the first storage area is determined based on the first EEPROM address of the first data in the EEPROM.

[0113] In the embodiment of the present application, the first storage unit may also store a target address of the first data. Accordingly, the processor may read the first data and the target address of the first data from the first storage unit, and then obtain the address of the first storage area based on the target address, and write the first data into the first storage area. The target address may be the first EEPROM address or a RAM address corresponding to the first EEPROM address. The RAM address is obtained based on the mapping relationship between the first EEPROM address and the target address.

[0114] It is understandable that if the target address of the first data is the RAM address corresponding to the first EEPROM address, the processor can directly determine the RAM address as the address of the first storage area. If the target address of the first data is the first EEPROM address, the processor can determine the RAM address corresponding to the first EEPROM address based on the target address mapping relationship, and determine the RAM address as the address of the first storage area.

[0115] Optionally, the number of the first data may be one or more. The processor may write all the first data stored in the first storage unit into the RAM. In the case where the number of the first data is multiple, the multiple first data may be stored in different storage areas of the first storage unit. The FLASH addresses of the different storage areas are different. At this time, the processor may read the multiple first data from the first storage unit in sequence according to the FLASH address from low to high, and write the read first data into the corresponding first storage area in the RAM in sequence. That is, the number of the first storage areas may be multiple.

[0116] Optionally, when the chip is not damaged, the embedded microcontroller may accidentally lose power while the processor is writing data to the storage unit, resulting in failure to write the data successfully. At this time, if the processor directly writes the data into the RAM after the embedded microcontroller is powered on, it will cause the data read by the subsequent processor to be incorrect. Based on this, the first storage unit can also store a check value corresponding to the first data. The check value is obtained by processing the first data using a check algorithm before the embedded microcontroller is initialized, and is written into the first storage unit together with the first data. Optionally, the check algorithm can be one of the following algorithms: a parity check algorithm, a sum check algorithm, and a redundancy check algorithm.

[0117] At this time, see Figure 5 , the process of the processor writing the first data stored in the first storage unit into the first storage area of ​​the RAM may include:

[0118] Step 2021: verify the first data according to the verification value.

[0119] In the embodiment of the present application, the processor may read the first data and the check value of the first data from the first storage unit, and then the processor may check the first data based on the check value.

[0120] In an embodiment of the present application, if the check algorithm is a parity check algorithm, the processor can detect whether the number of 1s in the target value is an odd number (or an even number) to implement the check of the first data. Wherein, the target value includes the read check value and the first data. If the check algorithm is a sum check algorithm or a redundant check algorithm, the processor can use the check algorithm to process the first data after reading the first data and the check value, and implement the check of the first data by detecting the difference between the result obtained by the processing and the check value.

[0121] Optionally, the check value may be obtained by the processor using a check algorithm to process the first data and the target address of the first data before writing the first data and the target address of the first data into the first storage unit. Accordingly, the processor may check the first data and the target address based on the check value.

[0122] Optionally, the processor may verify the first data after determining that the verification function is enabled. In this way, the use flexibility of the embedded microcontroller can be improved.

[0123] Step 2022: If the verification is successful, write the first data into the RAM.

[0124] After the processor verifies the first data, if it is determined that the verification of the first data is successful, the first data may be written into the first storage area of ​​the RAM.

[0125] Since the processor can verify the first data based on the verification value of the first data and write the first data into the RAM after the verification is successful, the reliability of the written data can be ensured to be high, thereby ensuring that the data subsequently read by the processor is relatively accurate.

[0126] In an embodiment of the present application, a storage area indicated by a target address (such as a RAM address) can be written with different data multiple times. Each time the processor writes a piece of data to the target address, the data and the target address of the data can be written into the storage unit of the FLASH, so each storage unit storing data (such as the first storage unit) may store multiple data with the same target address. The multiple data are located in multiple different storage areas of the storage unit. The FLASH addresses of the multiple different storage areas are different.

[0127] The data in the storage area indicated by the highest FLASH address among multiple FLASH addresses is the latest data written into the storage area indicated by the target address. In this case, if multiple data with the same target address in the storage unit pass the verification, the data written into the storage area indicated by the target address in the RAM by the processor is the latest data.

[0128] If a certain data (such as the first data) among the multiple data fails to pass the verification, the processor can display a prompt message indicating that the data fails to pass the verification for the user to view. Then, if the processor receives an operation executed by the user to instruct to skip the data, the data stored in the next storage area of ​​the storage unit, the target address of the data, and the check value can be read. If the processor receives an operation executed by the user to instruct to stop working, the operation can be terminated.

[0129] It can be seen that, if the chip is not damaged, the processor provided in the embodiment of the present application can skip the first data after the first data verification fails, and keep the data previously written to the first storage area unchanged. That is, the embedded microcontroller provided in the embodiment of the present application has the function of automatic data recovery. In this way, the data security can be ensured to be higher.

[0130] Step 203: Obtain second data to be stored in the EEPROM.

[0131] A process that needs to read and write EEPROM may be run in the processor. When the process needs to write second data into the EEPROM, the processor can obtain the second data to be stored in the EEPROM. In addition, when obtaining the second data, the processor can also obtain the second EEPROM address of the second data in the EEPROM. The second data may be configuration data. The second EEPROM address may be pre-allocated by the processor for the process.

[0132] It is understandable that in the embodiment of the present application, the processor simulates the EEPROM by executing read and write operations on the RAM and FLASH, and there is actually no EEPROM. Therefore, the second EEPROM address of the second data in the EEPROM is a virtual address.

[0133] Step 204: Write the second data into the RAM.

[0134] The processor may write the second data into a second storage area of ​​the RAM. The second storage area is located in the target storage space of the RAM, and the address of the second storage area is determined based on the second EEPROM address. For example, the processor may pre-store a target address mapping relationship, and may determine the RAM address corresponding to the second EEPROM address as the address of the second storage area based on the second EEPROM address and the target address mapping relationship.

[0135] Step 205: Obtain a valid second storage unit from the multiple storage units.

[0136] After the processor obtains the second data, it can also obtain a valid second storage unit among the multiple storage units, wherein the second storage unit is an embedded microcontroller and is a valid storage unit among the multiple storage units after initialization.

[0137] In the embodiment of the present application, the process of the processor acquiring a valid second storage unit from multiple storage units can refer to the implementation process of acquiring the first storage unit from multiple storage units in step 201. For example, in a scenario where the flag value of a storage unit storing data increases or decreases, the processor can determine a storage unit with an extreme flag value among the multiple storage units as the third storage unit.

[0138] That is, in a scenario where the flag value of a storage unit storing data increases, that is, the updated flag value of the second storage unit is the sum of the flag value of the third storage unit and the target value, the processor can determine the storage unit with the largest flag value among multiple storage units as the third storage unit.

[0139] In a scenario where the flag value of a storage unit storing data increases or decreases, that is, when the updated flag value of the second storage unit is the difference between the flag value of the third storage unit and the target value, the processor can determine the storage unit with the smallest flag value among multiple storage units as the third storage unit.

[0140] Step 206: Detect whether the remaining capacity of the second storage unit is less than the capacity threshold.

[0141] After the processor determines the second storage unit from the plurality of storage units, the processor may detect the remaining capacity of the second storage unit. If the processor determines that the remaining capacity of the second storage unit is greater than or equal to the capacity threshold, it is determined that the second storage unit can still store the second data and the target address of the second data, and then step 207 may be executed. If the processor determines that the remaining capacity of the second storage unit is less than the capacity threshold, it is determined that the second storage unit cannot store the second data and the target address of the second data, and then step 208 may be executed.

[0142] The capacity threshold may be pre-stored by the processor, and the capacity threshold may be determined based on the capacity of a storage area occupied by a data and a target address of the data. For example, the capacity threshold may be 4B.

[0143] Step 207: Write the second data and the target address of the second data into the second storage unit.

[0144] If the processor determines that the remaining capacity of the second storage unit is greater than or equal to the capacity threshold, the second data and the target address of the second data may be directly written into the second storage unit.

[0145] The target address of the second data is the second EEPROM address, or the RAM address in the RAM corresponding to the second EEPROM address. Furthermore, if the target address of the second data is the RAM address, the processor can determine the RAM address corresponding to the second EEPROM address based on the mapping relationship between the second EEPROM address and the target address before writing the second data into the second storage unit.

[0146] Step 208: write the multiple data stored in the target storage space of the RAM and the target address of each data in the multiple data into the next storage unit of the second storage unit.

[0147] If the processor determines that the remaining capacity of the second storage unit is less than the capacity threshold, the multiple data stored in the target storage space of the RAM and the target address of each data in the multiple data can be written into the next storage unit of the second storage unit.

[0148] The multiple data are all data stored in the target storage space, and the multiple data include the second data. The target address of each data is the EEPROM address of the data in the EEPROM, or the RAM address in the RAM corresponding to the EEPROM address of the data.

[0149] It is understandable that the processor may first erase the second storage unit before writing the data into the next storage unit, and then write the multiple data and the target address of each of the multiple data into the next storage unit.

[0150] Step 209: Take the next storage unit as a valid storage unit.

[0151] In the embodiment of the present application, the processor may update the flag value of the next storage unit to make the next storage unit a valid storage unit among the multiple storage units, wherein the valid state indicated by the updated flag value of the next storage unit is valid.

[0152] According to the description of the above steps 208 to 209, when the valid second storage unit is full, the processor can first write all the data in the target storage space of the RAM into the next storage unit, and then update the flag value of the next storage unit to make the next storage unit a valid storage unit. In this way, compared with the method of first updating the flag value of the next storage unit and then writing multiple data to the next storage unit, it can be avoided that during the process of writing data to the next storage unit, the flag value of the next storage unit has been updated (that is, the next storage unit has been used as a valid storage unit) due to an unexpected power failure of the embedded microcontroller, but only part of the data is written, thereby causing the problem that after the embedded microcontroller is initialized, the processor cannot read the relatively complete data stored in the RAM before the power failure.

[0153] It can be understood that if the flag value of each storage unit is the first value or the second value, the processor can update the flag value of the next storage unit of the second storage unit from the second value to the first value, and can update the flag value of the second storage unit from the first value to the second value.

[0154] If the flag value of the storage unit storing data increases, the processor can update the flag value of the next storage unit of the second storage unit to the sum of the flag value of the second storage unit and the target value. If the flag value of the storage unit storing the value decreases, the processor can update the flag value of the next storage unit to the difference between the flag value of the second storage unit and the target value.

[0155] The target value may be a positive integer pre-stored by the processor. For example, the target value may be 1.

[0156] In the embodiment of the present application, the process of the processor executing step 207 may include: the processor obtains the target FLASH address, and writes the second data and the target address of the second data into the storage area indicated by the target FLASH address in the second storage unit.

[0157] Since each time the processor obtains a piece of data, it can write the data into a valid storage unit, a storage area that does not store data and has the lowest address, and each time the processor writes data to a storage area, it can record the FLASH address of the storage area. Therefore, the processor can determine the next FLASH address of a FLASH address in the second storage unit that was most recently recorded as the target FLASH address.

[0158] Optionally, for each storage unit in the plurality of storage units, the processor may record the FLASH addresses of the storage areas included in the storage unit in order from low to high addresses. At this time, the processor may determine the next FLASH address based on the FLASH addresses of the plurality of storage areas arranged in sequence in the second storage unit.

[0159] Alternatively, for each storage unit in the plurality of storage units, the processor may record the starting address, the ending address, and the capacity of each storage area in the storage unit. Then, the processor may determine the next FLASH address according to the starting address, the ending address, the capacity, and a FLASH address in the second storage unit that was recorded most recently of the second storage unit.

[0160] It can be understood that, at this time, if a FLASH address in the second storage unit recorded most recently is empty, the next FLASH address is the FLASH address of the first storage unit of the second storage unit.

[0161] Alternatively, the addresses of the plurality of storage units are continuous, and the plurality of storage units are arranged in order of addresses from low to high. The processor records the start address, the end address, and the capacity of each storage area in the storage space composed of the plurality of storage units. Then, the processor can determine the next FLASH address according to the start address, the end address, the capacity, and a FLASH address in the second storage unit recorded most recently.

[0162] It is understandable that, at this time, if a FLASH address in the second storage unit recorded most recently is empty, then the next FLASH address is the starting address of the storage space.

[0163] In an embodiment of the present application, during the process of writing the second data and the target address of the second data into the second storage unit, the processor may suffer a bit flip due to damage to the chip itself or electromagnetic interference to the chip, thereby causing the data and address written into the second storage unit to differ from the expected value (i.e., the second data and the target address of the second data).

[0164] Based on this, the processor can also read the third data and the target address of the third data stored in the storage area indicated by the target FLASH address after writing the second data and the target address of the second data into the storage area indicated by the target FLASH address, and when it is determined that the second data is different from the second data, and / or the target address of the second data is different from the target address of the third data, the operation of writing the second data and the target address of the second data can be repeated until the writing is successful or the number of consecutive write failures is greater than the number threshold. In this way, the accuracy of the data written into the second storage unit can be ensured to be high.

[0165] The number threshold may be pre-stored by the processor. The write success means that the processor determines that the data written into the storage area indicated by the target FLASH address is the second data, and the address is the target address of the second data.

[0166] It is understandable that if the processor 110 determines that the number of consecutive write failures is greater than the number threshold, it can be determined that the chip is damaged (such as internal circuit damage), and then a prompt message can be issued to prompt the user to send it for inspection and repair.

[0167] Optionally, before the processor writes the second data and the target address of the second data into the second storage unit, it can also use a verification algorithm to process the second data and the target address to obtain a verification value of the second data. Then, the processor can write the second data, the target address and the verification value into the second storage unit together. In this way, it can be avoided that during the process of the processor writing the second data, the target address and the verification value into the second storage unit, due to an unexpected power failure of the embedded microcontroller, the data written by the processor is incorrect, and the processor still writes the incorrect data into the RAM after the embedded microcontroller is powered on again. This can ensure that after the embedded microcontroller is initialized, the accuracy of the data written into the RAM by the processor is high.

[0168] It is understandable that, when the processor executes step 208, in the process of writing each data into the next storage unit of FLASH, the process of writing the second data and the target address of the second data into the storage area indicated by the target FLASH address can all refer to. That is, after writing the data, a comparison can be performed, and before writing, the data and the target address of the data can be verified to obtain a verification value, and the data, the target address of the data and the verification value are all written into the storage unit. The embodiments of the present application will not be repeated here.

[0169] Assuming that the capacity of the storage area in the target storage space is 2B, the capacity of the storage area in the storage unit is 4B, and the capacity of the EEPROM to be simulated is nB, the target storage space and each storage unit provided in the embodiment of the present application are exemplarily described:

[0170] Since the capacity of the EEPROM to be simulated is nB and the capacity of the storage area in the target storage space is 2B, the total number of storage areas in the target storage space is n / 2. That is, after the processor obtains the target storage space from the RAM, the target storage space can be divided into n / 2 storage areas.

[0171] Assume that the total number of storage areas in each storage unit is m more than the total number of storage areas in the target storage space, then see Figure 6 , the total number of storage areas (also called storage rows) of each storage unit is n / 2+m. Therefore, the capacity of each storage unit can be (n / 2+m)×4B, that is, the processor takes out a total storage space of K×(n / 2+m)×4B from the FLASH to simulate EEPROM. Among them, m can be an integer greater than or equal to 1.

[0172] It is understandable that since the minimum erasing unit of FLASH is a page, it is necessary to ensure that the capacity of each storage unit is an integer multiple of the capacity of a page. For example, assuming that the capacity of each page is p B, it is necessary to ensure that (n / 2+m)×4 is an integer multiple of p.

[0173] Since the total number of storage areas of each storage unit is m more than the total number of storage areas of the target storage space, the capacity of each storage unit is greater than the capacity of the EEPROM, so it can be avoided that after the EEPROM is full, modifying a data in the EEPROM requires switching to the next storage unit.

[0174] Optionally, the number of the K storage units may be greater than or equal to 3, that is, the number of the plurality of storage units may be at least 3. In this way, it can be further ensured that the service life of each storage unit is longer.

[0175] When the processor writes data to the FLASH, it fills up one storage unit and then switches to the next storage unit, that is, multiple storage units store data in turn. Therefore, if the total number of erase and write times remains unchanged, the more storage units there are, the fewer erase and write times each storage unit has. Correspondingly, the life of each storage unit is longer.

[0176] See also Figure 6 and Figure 7 The first storage row of each storage unit can be used to store the flag value of the storage unit, and the flag value is unsigned data. The second storage row can be used to store the verification value of the flag value. The next (n / 2+m)-2 storage rows can store the data to be stored in the EEPROM, the target address of the data, and the verification value of the data.

[0177] For example, the lower 16 bits of each storage row in (n / 2+m)-2 storage rows can store 2B of data. The upper 16 bits of each storage row can store the target address and check value of the data. It can be understood that since the capacity of EEPROM is usually 4 kilobytes (KB), a 12-bit storage area is sufficient to store the EEPROM address, and each storage row in (n / 2+m)-2 storage rows still has 4 bits of storage area left. Therefore, the upper 4 bits of each storage row can store the check value. The remaining 12 bits of the upper 16 bits of each storage row, except the upper 4 bits, can be used to store the EEPROM address of the data.

[0178] For example, from Figure 6 and Figure 7 It can be seen that the first storage unit stores data, and the flag value of the first storage unit is 0xFFFFFFFE. Assuming that the verification value of the storage unit is obtained by performing a bitwise inversion operation on the flag value of the storage unit, then Figure 6 and Figure 7 As shown, the verification value of the first storage unit may be 0x00000001. No data is stored in the second storage unit to the Kth storage unit, so the flag value and verification value of each storage unit in the second storage unit to the Kth storage unit are 0xFFFFFFFF.

[0179] Assume that no data is written to any of the multiple storage units, the target address is the EEPROM address, the default value is 0xFFFFFFFF, the target value is 1, the valid storage unit is the storage unit with the smallest flag value, and the data check value is not considered first, then Figure 7 As shown, the process of the processor writing the acquired data into RAM and FLASH can be described as follows:

[0180] First, after the processor obtains the data 0x1234 at the EEPROM address 0x0100, it can first write the data 0x1234 to the storage area corresponding to the address 0x0100 in the RAM. Then, the processor can erase the first storage unit among the multiple storage units, and write the address 0x0100 and the data 0x1234 to the third storage row in the first storage unit. Afterwards, the processor can update the flag value of the first storage unit to 0xFFFFFFFE, and can update the verification value of the first storage unit to 0x000000001. At this point, the first storage unit is a valid storage unit. Among them, from Figure 7 It can be seen that the values ​​stored in the upper 16 bits and lower 16 bits of each storage row in the first storage unit after erasure are both 0xFFFF. 0xFFFF means that no data is written.

[0181] Secondly, the processor obtains the data 0x5678 at the EEPROM address 0x0200. The processor writes the data 0x5678 into the storage area corresponding to the address 0x0200 in the RAM. After that, the processor writes the address 0x0200 and the data 0x5678 together into the fourth storage row of the first storage unit.

[0182] After that, the processor obtains the data at the EEPROM address 0x0100. The processor can write the data 0xAB to the storage area corresponding to the address 0x0100 in the RAM. At this time, since the data 0xAB occupies an 8-bit storage area, the processor can update the data 0xAB to the lower 8-bit storage unit of the storage area and keep the upper 8-bit data of the storage area unchanged. That is, the updated data is 0x12AB. After that, the processor can write the address 0x0100 and the data 0x12AB to the third data row of the first storage unit.

[0183] Data is continuously written in this way until the first storage unit is full, that is, all storage rows of the first storage unit are stored with data. Then, the next time the processor receives data and the EEPROM address of the data, it can first write the data to the RAM based on the EEPROM address. After that, the processor can switch to the next storage unit (i.e., the second storage unit). At this time, the processor can erase the next storage unit and save the data that is not 0xFFFF in the target storage space of the RAM and the target address of the data to the storage row of the next storage unit. Finally, the processor updates the flag value and verification value of the next storage unit. When the last storage unit among multiple storage units is full, the processor can automatically switch to the first storage unit.

[0184] Taking the case where the flag value of a storage unit storing data decreases, the default value of the storage unit is 0xFFFFFFFF, and the verification value of the storage unit is obtained by performing a bitwise inversion operation on the flag value as an example, the process of the processor determining the first storage unit from multiple storage units is exemplarily described. Figure 8 , the process may include:

[0185] Step A1, read the flag value and verification value of the storage unit.

[0186] After starting, the processor may read the flag value and verification value of each storage unit in the plurality of storage units. For example, the processor may read the flag value and verification value of each storage unit in the plurality of storage units in sequence according to the arrangement order of the plurality of storage units.

[0187] Step A2: Check whether the flag value and the verification value of the storage unit are both 0xFFFFFFFF.

[0188] If the processor determines that the flag value and the verification value of the storage unit are not 0xFFFFFFFF, it can be determined that the storage unit stores data, and then step A3 can be executed. If the processor determines that the flag value and the verification value of the storage unit are both 0xFFFFFFFF, it can be determined that the storage unit does not store data, and then step A8 can be executed.

[0189] Step A3: Check whether the result of the XOR operation of the read flag value and the verification value is 0xFFFFFFFF.

[0190] If the processor determines that the result is not 0xFFFFFFFF, it can be determined that the flag value is incorrect, that is, it fails to pass the verification, and then step A4 can be executed. If the processor determines that the result is 0xFFFFFFFF, it can be determined that the flag value in the storage unit is accurate, that is, it passes the verification, and then step A5 can be executed.

[0191] It can be seen that in the embodiment of the present application, the processor can also verify the flag value of the storage unit according to the verification value. In this way, the accuracy of the determined first storage unit can be ensured to be high, thereby ensuring the accuracy of the data written to the RAM after initialization to be high.

[0192] Step A4: execute the first interrupt processing program, and detect whether the execution result of the first interrupt processing program is to continue detection.

[0193] If the processor determines that the result is not 0xFFFFFFFF, it can be determined that the flag value is incorrect, and then the first interrupt handler can be executed to the processor. After the processor executes the first interrupt handler, the execution result of the first interrupt handler can be obtained. The execution result may include: continue detection or stop detection. If the execution result is to continue detection, the processor can execute step A8. If the execution result is to stop detection, the processor can end the operation and no longer execute the subsequent process.

[0194] Step A5: Check whether the flag value is less than a first reference value.

[0195] After the processor determines that the flag value of the storage unit passes the verification, it can detect whether the flag value is less than the first reference value. If the processor determines that the flag value is less than the first reference value, step A6 can be executed. If the processor determines that the flag value is greater than or equal to the first reference value, step A7 can be executed.

[0196] The first reference value is a minimum flag value determined before the flag value of the storage unit is read.

[0197] Step A6: Update the first reference value to the mark value.

[0198] If the processor determines that the flag value is less than the first reference value, the first reference value may be updated to the flag value, that is, the flag value is used as the first reference value.

[0199] Step A7: keep the first reference value unchanged.

[0200] If the processor determines that the flag value is greater than or equal to the reference value, the first reference value may be kept unchanged.

[0201] According to the above description, the first reference value is a variable. It is understandable that, for the first storage unit that passes the verification among the plurality of storage units arranged in order, the processor can directly determine the flag value of the storage unit as the first reference value and end the operation. Afterwards, the processor can update the first reference value according to the flag value subsequently read.

[0202] Step A8: Detect whether the storage unit is the last storage unit among the multiple storage units.

[0203] In the embodiment of the present application, the processor may execute step A8 after determining that no data is stored in the storage unit, or after receiving an instruction to instruct continued detection, or after executing step A6 or A7.

[0204] If the processor determines that the storage unit is not the last storage unit, it can continue to execute step 201. If the processor determines that the storage unit is the last storage unit, it can end the operation and determine the storage unit to which the current reference value belongs as the first storage unit.

[0205] Taking the case where the flag value of a storage unit storing data is incremented, the default value of the storage unit is 0x00000000, and the verification value of the storage unit is obtained by performing a bitwise inversion operation on the flag value as an example, the process of the processor determining the first storage unit from multiple storage units is exemplarily described, see Fig.10 , the process may include:

[0206] Step B1, read the flag value and verification value of the storage unit.

[0207] Step B2: Check whether the flag value and the verification value of the storage unit are both 0xFFFFFFFF.

[0208] Step B3: Check whether the result of the XOR operation of the read flag value and the verification value is 0xFFFFFFFF.

[0209] Step B4: execute the second interrupt processing program, and detect whether the execution result of the second interrupt processing program is to continue detection.

[0210] It can be understood that the implementation process of steps B1 to B4 can refer to the implementation process of steps A1 to A4, and the embodiments of the present application will not be repeated here.

[0211] Step B5: Check whether the flag value is greater than a second reference value.

[0212] If the processor determines that the flag value is greater than the second reference value, step B6 may be executed. If the processor determines that the flag value is less than or equal to the second reference value, step B7 may be executed. The second reference value is the maximum flag value determined before the flag value of the storage unit is read.

[0213] Step B6: Update the second reference value to the flag value.

[0214] If the processor determines that the flag value is greater than the second reference value, the second reference value may be updated to the flag value.

[0215] Step B7: keep the second reference value unchanged.

[0216] If the processor determines that the flag value is less than or equal to the second reference value, the second reference value may be kept unchanged.

[0217] Step B8: Detect whether the storage unit is the last storage unit among the multiple storage units.

[0218] Among them, the implementation process of step B8 can refer to the implementation process of step A8, and the embodiment of the present application will not be repeated here.

[0219] See also Fig.10 , a process in which the processor writes the first data stored in the first storage unit into the RAM after initialization is exemplarily described:

[0220] Step S1, detecting whether the EEPROM emulation function is enabled.

[0221] After the embedded microcontroller is initialized, the processor can detect whether the EEPROM emulation function is enabled. If the processor detects that the EEPROM emulation function is not enabled, the operation can be terminated without executing the subsequent process. If the processor detects that the EEPROM emulation function is enabled, step S2 can be executed.

[0222] Step S2: Write the data stored in each storage area in the target storage space of the RAM as initial values.

[0223] After the processor detects that the EEPROM emulation function is enabled, the target storage space may be erased to initialize each storage area of ​​the target storage space to an initial value, which may be 0xFFFF.

[0224] Step S3: Acquire a valid first storage unit.

[0225] The processor may adopt the above steps A1 to A8, or adopt the above steps B1 to B8, to obtain the first storage unit from the plurality of storage units.

[0226] Step S4, reading the first data stored in the storage row in the first storage unit, the target address of the first data and the check value.

[0227] After the processor determines the first storage unit, it can sequentially read the first data, the target address of the first data, and the check value stored in each storage row in the multiple storage rows of the first storage unit.

[0228] Step S5: Check whether the verification function is enabled.

[0229] If the processor determines that the verification function is enabled, step S6 may be executed. If the processor determines that the verification function is not enabled, step S7 may be executed.

[0230] Step S6: verify the first data and the target address of the first data based on the verification value, and detect whether the verification is successful.

[0231] After determining that the verification function is enabled, the processor can verify the first data and the target address of the first data based on the first data, and determine whether the verification is successful. If the processor successfully verifies the first data and the target address of the first data, step S7 can be executed. If the processor fails to verify the first data and the target address of the first data, step S8 can be executed.

[0232] Step S7: Write the first data into the first storage area of ​​the RAM.

[0233] If the processor successfully verifies the first data and the target address of the first data based on the verification value, the first data may be written into the first storage area of ​​the RAM.

[0234] Step S8: display a prompt message, and detect whether an operation for instructing to continue reading is received.

[0235] If the processor fails to verify the first data and the target address of the first data based on the check value, a prompt message may be displayed. Afterwards, if the processor receives an operation for instructing to continue reading, step S4 may be continued, i.e., the first data, the target address of the first data, and the check value stored in the next storage row may be read. If the processor receives an operation for instructing to stop working, the operation may be terminated.

[0236] Step S9: Detect whether the storage row is the last storage row of the first storage unit.

[0237] If the processor determines that the storage row is the last storage row, it can be determined that the data in the first storage unit has been written into the RAM, and then the operation can be terminated. If the processor determines that the storage row is not the last storage row, step S4 can be continued to read the first data stored in the next storage row.

[0238] It is understandable that the order of the steps of the data reading and writing method provided in the embodiment of the present application can be appropriately adjusted, and the steps can also be increased or decreased accordingly according to the situation. For example, step 205 and step 204 can be executed simultaneously; or step 205 can also be executed before step 204; or step 207 can be deleted according to the situation. Any technician familiar with the technical field can easily think of a method of change within the technical scope disclosed in this application, which should be covered within the scope of protection of this application, so it will not be repeated.

[0239] In summary, the embodiment of the present application provides a data reading and writing method, wherein the processor can write the data to be stored in the EEPROM into the valid storage unit in the FLASH. Since the FLASH is non-volatile, it can ensure that the data will not be lost after the embedded microcontroller loses power. Thus, the effect of storing in the EEPROM can be achieved by storing the data in the FLASH. After the embedded microcontroller is initialized, the processor can write the data stored in the valid storage unit before initialization into the RAM for the processor to read. Since the RAM and the EEPROM have the same reading and writing mode, it can ensure that the processor can achieve the effect of accessing the EEPROM by accessing the RAM. It can be seen that the data reading and writing operations performed by the processor on the FLASH and RAM of the embedded microcontroller itself can simulate the function of the EEPROM, that is, the instant reading and writing and power-off preservation of the data can be realized. There is no need to add an additional EEPROM, so the volume, hardware cost, hardware complexity and power consumption of the embedded microcontroller are effectively reduced. In addition, since the FLASH includes multiple storage units, it can ensure that the service life of each storage unit is long.

[0240] In addition, after the remaining capacity of the effective second storage unit is less than the capacity threshold, the processor can first write the multiple data stored in the RAM and the target address of each data into the next storage unit of the second storage unit, and then use the next storage unit as the effective storage unit. In this way, it can be ensured that during the process of writing data to the next storage unit, even if the embedded microcontroller is accidentally powered off, after the embedded microcontroller is initialized, the processor can read the relatively complete data stored in the RAM before the power failure from the effective storage unit after the initialization.

[0241] The present application embodiment also provides an embedded microcontroller, which can be used to execute the data reading and writing method provided by the above method embodiment. Figure 1 and Figure 2 The embedded microcontroller may include: a processor 110, a RAM 120 and a FLASH 130, wherein the FLASH 130 includes a plurality of storage units arranged in sequence. The processor 110 is used to:

[0242] After the embedded microcontroller is initialized, first data stored in a first storage unit among the multiple storage units is written into the RAM for reading by the processor, wherein the first storage unit is a valid storage unit among the multiple storage units before the embedded microcontroller is initialized;

[0243] After obtaining the second data to be stored in the EEPROM, the second data is written into the RAM, and a valid second storage unit is obtained from the plurality of storage units;

[0244] If the remaining capacity of the second storage unit is less than the capacity threshold, the multiple data stored in the RAM and the target address of each data in the multiple data are written into the next storage unit of the second storage unit;

[0245] taking the next storage unit as a valid storage unit among the plurality of storage units;

[0246] The multiple data include the second data, and the target address of each data is the EEPROM address of the data in the EEPROM, or the RAM address in the RAM corresponding to the EEPROM address of the data.

[0247] Optionally, each storage unit stores: a flag value, the flag value is used to indicate whether the storage unit stores data, and the difference between the flag values ​​of any two adjacent storage units is the target value. The processor 110 can also be used to:

[0248] A storage unit whose flag value is an extreme value among the plurality of storage units is determined as a second storage unit.

[0249] Optionally, the extreme value is a minimum value; the processor 110 may be configured to:

[0250] The flag value of the next storage unit is updated, and the updated flag value of the next storage unit is a value obtained by subtracting the target value from the flag value of the second storage unit.

[0251] Optionally, each storage unit further stores: a verification value of the flag value, the verification value being generated based on the flag value. The processor 110 may be configured to:

[0252] For each storage unit in the plurality of storage units, verifying a flag value of the storage unit based on a verification value of the storage unit;

[0253] If the flag value of the storage unit passes the verification, and the flag value of the storage unit is the minimum value of the flag values ​​of the plurality of storage units, the storage unit is determined as the second storage unit.

[0254] Optionally, the first storage unit further stores a check value of the first data, where the check value is obtained by processing the first data using a check algorithm. The processor 110 may be configured to:

[0255] Verifying the first data according to the verification value;

[0256] If the verification is successful, the first data is written into the RAM.

[0257] In summary, the embodiment of the present application provides an embedded microcontroller, and the processor can write the data to be stored in the EEPROM into the valid storage unit in the FLASH. Since the FLASH is non-volatile, it can ensure that the data will not be lost after the embedded microcontroller is powered off. Therefore, by storing the data in the FLASH, the effect of storing in the EEPROM can be achieved. After the embedded microcontroller is initialized, the processor can write the data stored in the valid storage unit before initialization into the RAM for the processor to read. Since the RAM and the EEPROM have the same reading and writing mode, it can ensure that the processor can achieve the effect of accessing the EEPROM by accessing the RAM. It can be seen that the data read and write operations performed by the processor on the FLASH and RAM of the embedded microcontroller itself can simulate the function of the EEPROM, that is, the instant reading and writing and power-off preservation of the data can be realized. There is no need to add an additional EEPROM, so the volume, hardware cost, hardware complexity and power consumption of the embedded microcontroller are effectively reduced. In addition, since the FLASH includes multiple storage units, it can ensure that the service life of each storage unit is long.

[0258] In addition, after the remaining capacity of the effective second storage unit is less than the capacity threshold, the processor can first write the multiple data stored in the RAM and the target address of each data into the next storage unit of the second storage unit, and then use the next storage unit as the effective storage unit. In this way, it can be ensured that during the process of writing data to the next storage unit, even if the embedded microcontroller is accidentally powered off, after the embedded microcontroller is initialized, the processor can read the relatively complete data stored in the RAM before the power failure from the effective storage unit after the initialization.

[0259] The present application also provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, the data reading and writing method provided in the above method embodiment can be implemented. Figure 3 or Figure 4 The method shown.

[0260] The present application also provides a computer program product including instructions. When the computer program product is run on a computer, the computer is caused to execute the data reading and writing method provided by the above method embodiment. Figure 3 or Figure 4 The method shown.

[0261] It should be noted that the logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be specifically implemented in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purposes of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection portion with one or more wirings (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.

[0262] It should be understood that the various parts of the present application can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or their combination: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0263] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0264] In the description of the present application, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present application, the meaning of "plurality" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0265] In this application, unless otherwise clearly specified and limited, the terms "installed", "connected", "connected", "fixed" and the like should be understood in a broad sense, for example, it can be a fixed connection, a detachable connection, or an integral connection; it can be a mechanical connection or an electrical connection; it can be a direct connection or an indirect connection through an intermediate medium, it can be the internal connection of two elements or the interaction relationship between two elements, unless otherwise clearly defined. For ordinary technicians in this field, the specific meanings of the above terms in this application can be understood according to specific circumstances.

[0266] Although the embodiments of the present application have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations on the present application. Ordinary technicians in this field can change, modify, replace and modify the above embodiments within the scope of the present application.

Claims

1. A data reading and writing method, characterized in that: A processor applied to an embedded microcontroller, wherein the embedded microcontroller further comprises: a random access memory RAM and a flash memory FLASH, wherein the FLASH comprises a plurality of storage units arranged in sequence, wherein each of the plurality of storage units stores a flag value; and the method comprises: After the embedded microcontroller is initialized, first data stored in a first storage unit among the multiple storage units is written into the RAM for the processor to read, wherein the first storage unit is a valid storage unit among the multiple storage units before the embedded microcontroller is initialized, and the valid storage unit refers to: a storage unit to which data was written most recently, and a flag value of the valid storage unit is an extreme value among the flag values ​​of the multiple storage units; After obtaining the second data to be stored in the EEPROM, writing the second data into the RAM, and obtaining a valid second storage unit from the plurality of storage units; If the remaining capacity of the second storage unit is less than the capacity threshold, the multiple data stored in the RAM and the target address of each data in the multiple data are written into the next storage unit of the second storage unit, and the multiple data are all the data in the RAM that need to be stored in the EEPROM; Updating the flag value of the next storage unit to use the next storage unit as a valid storage unit among the multiple storage units, wherein the flag value of the next storage unit after update is an extreme value among the flag values ​​of the multiple storage units; The multiple data include the second data, and the target address of each of the data is the EEPROM address of the data in the EEPROM, or the RAM address in the RAM corresponding to the EEPROM address of the data.

2. The method according to claim 1, characterized in that The flag value is used to indicate whether the storage unit stores data, the flag value of the storage unit that does not store data in the multiple storage units is a default value, and the difference between the flag values ​​of any two adjacent storage units that store data is a target value; before writing the multiple data stored in the RAM and the target address of each data in the multiple data into the next storage unit of the second storage unit, the method also includes: A storage unit whose flag value is an extreme value among the multiple storage units is determined as the second storage unit.

3. The method according to claim 2, characterized in that The extreme value is a minimum value; The updated flag value of the next storage unit is a value obtained by subtracting the target value from the flag value of the second storage unit.

4. The method according to claim 2, characterized in that: Each of the storage units further stores: a verification value of the flag value, wherein the verification value is generated based on the flag value; and determining a storage unit with an extreme flag value among the plurality of storage units as the second storage unit comprises: For each storage unit in the plurality of storage units, verifying a flag value of the storage unit based on a verification value of the storage unit; If the flag value of the storage unit passes the verification and the flag value of the storage unit is the minimum value of the flag values ​​of the multiple storage units, the storage unit is determined to be the second storage unit.

5. The method according to any one of claims 1 to 4, characterized in that: The first storage unit further stores a check value of the first data, where the check value is obtained by processing the first data using a check algorithm; Writing the first data stored in a first storage unit among the plurality of storage units into the RAM comprises: Verifying the first data according to the verification value; If the verification is successful, the first data is written into the RAM.

6. The method according to any one of claims 1 to 4, characterized in that: Writing the first data stored in a first storage unit among the plurality of storage units into the RAM comprises: Writing first data stored in a first storage unit among the plurality of storage units into a first storage area of ​​the RAM; Writing the second data into the RAM comprises: Writing the second data into a second storage area of ​​the RAM; The address of the first storage area is determined based on a first EEPROM address of the first data in the EEPROM, and the address of the second storage area is determined based on a second EEPROM address of the second data in the EEPROM.

7. The method according to claim 6, characterized in that The first storage area and the second storage area are both located in a target storage space of the RAM, and a capacity of the target storage space is smaller than a capacity of a storage space of the RAM; The step of writing the plurality of data stored in the RAM and the target address of each of the plurality of data into a next storage unit of the second storage unit comprises: The multiple data stored in the target storage space of the RAM and the target address of each data in the multiple data are written into the next storage unit of the second storage unit.

8. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: If the remaining capacity of the second storage unit is greater than or equal to the capacity threshold, the second data and the target address of the second data are written into the second storage unit.

9. The method according to any one of claims 1 to 4, characterized in that: Writing the first data stored in a first storage unit among the plurality of storage units into the RAM comprises: If the EEPROM emulation function of the embedded microcontroller is enabled, the first data stored in the first storage unit among the plurality of storage units is written into the RAM.

10. An embedded microcontroller, characterized in that: The embedded microcontroller comprises: a processor, a random access memory RAM and a flash memory FLASH, wherein the FLASH comprises a plurality of storage units arranged in sequence, each of the plurality of storage units stores a flag value; the processor is used for: After the embedded microcontroller is initialized, first data stored in a first storage unit among the multiple storage units is written into the RAM for the processor to read, wherein the first storage unit is a valid storage unit among the multiple storage units before the embedded microcontroller is initialized, and the valid storage unit refers to: a storage unit to which data was written most recently, and a flag value of the valid storage unit is an extreme value among the flag values ​​of the multiple storage units; After obtaining the second data to be stored in the EEPROM, writing the second data into the RAM, and obtaining a valid second storage unit from the plurality of storage units; If the remaining capacity of the second storage unit is less than the capacity threshold, the multiple data stored in the RAM and the target address of each data in the multiple data are written into the next storage unit of the second storage unit, and the multiple data are all the data in the RAM that need to be stored in the EEPROM; Updating the flag value of the next storage unit to use the next storage unit as a valid storage unit among the multiple storage units, wherein the flag value of the next storage unit after update is an extreme value among the flag values ​​of the multiple storage units; The multiple data include the second data, and the target address of each of the data is the EEPROM address of the data in the EEPROM, or the RAM address in the RAM corresponding to the EEPROM address of the data.

11. The embedded microcontroller according to claim 10, characterized in that: The flag value is used to indicate whether the storage unit stores data, the flag value of the storage unit that does not store data in the multiple storage units is a default value, and the difference between the flag values ​​of any two adjacent storage units that store data is a target value; the processor is also used to: A storage unit whose flag value is an extreme value among the multiple storage units is determined as the second storage unit.

12. The embedded microcontroller according to claim 11, characterized in that: The extreme value is the minimum value; the updated mark value of the next storage unit is a value obtained by subtracting the target value from the mark value of the second storage unit.

13. The embedded microcontroller according to claim 12, characterized in that: Each of the storage units further stores: a verification value of the flag value, the verification value being generated based on the flag value; the processor is configured to: For each storage unit in the plurality of storage units, verifying a flag value of the storage unit based on a verification value of the storage unit; If the flag value of the storage unit passes the verification and the flag value of the storage unit is the minimum value of the flag values ​​of the multiple storage units, the storage unit is determined to be the second storage unit.

14. The embedded microcontroller according to any one of claims 10 to 13, characterized in that: The first storage unit further stores a check value of the first data, where the check value is obtained by processing the first data using a check algorithm; and the processor is used for: Verifying the first data according to the verification value; If the verification is successful, the first data is written into the RAM.

15. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the data reading and writing method according to any one of claims 1 to 9 is implemented.