A data storage and retrieval method that can improve the lifespan of flash memory cells.

By partitioning the flash memory cell into high-order and low-order data, and combining the erase/write strategy with position swapping, the problem of excessive erasure of high-order data is solved, thus extending the lifespan of the flash memory cell.

CN115132260BActive Publication Date: 2025-10-28SHANGHAI ENJIE ELECTRONIC TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210802144.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-07
Publication Date
2025-10-28
Estimated Expiration
2042-07-07

AI Technical Summary

Technical Problem

In existing technologies, when recording the number of times a solenoid valve is switched on and off, the flash memory cell erases and writes high-order data less frequently, resulting in a reduced overall lifespan.

Method used

The high-order and low-order characters of the data are stored in two different sectors. The decision to erase and write both units simultaneously is made by checking whether the high-order character has changed, thus avoiding repeated erasure and writing, balancing the wear and tear, and swapping the storage locations when the maximum number of erasures and writes is reached.

Benefits of technology

It extends the lifespan of the flash memory unit, increases the number of times the memory unit can be erased and rewritten, and extends the data retention capacity.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115132260B_ABST
    Figure CN115132260B_ABST
Patent Text Reader

Abstract

This invention discloses a data storage and retrieval method that can improve the lifespan of flash memory units. The storage method includes: setting a starting storage address for data in the flash memory, wherein there are two starting storage addresses, each corresponding to a storage unit in a different sector. The two storage units are used to store the high-order and low-order characters of the data in a preset order; determining whether the high-order character has changed; if so, erasing and writing both sectors simultaneously; otherwise, erasing and writing only the sector corresponding to the low-order character, and recording the number of erasures and writes; determining whether the number of erasures and writes has reached the maximum count value; if so, clearing the data and storing the high-order and low-order characters of subsequently received data in the two storage units in reverse order, and clearing the data again after the number of erasures and writes reaches the maximum count value, while simultaneously enabling the other two storage units; otherwise, continuing to execute the previous step. This invention can balance the number of erasures and writes of each storage unit, thereby improving the lifespan of the flash memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of flash technology, and in particular to a data storage and retrieval method that can improve the lifespan of flash memory cells. Background Technology

[0002] FLASH is a type of memory chip that allows data to be modified through a specific program. In the electronics and semiconductor fields, FLASH often stands for Flash Memory, which is commonly known as "flash memory". Its full name is Flash EEPROM Memory. It combines the advantages of ROM and RAM. It not only has the performance of electronically erasable programmable (EEPROM) but also can quickly read data (the advantage of NVRAM), so that data will not be lost due to power failure.

[0003] Flash memory is typically divided into several sectors, each sector being 128 bytes in size. Each sector includes several storage units, which are the smallest units for data operations. Each storage unit has a unique hexadecimal address, and data is written to and read from the corresponding storage unit based on this address.

[0004] When saving data to a memory cell in flash memory, the entire sector containing that memory cell must be erased first, and then the data must be written to that memory cell. Therefore, flash memory sectors have a limited lifespan, typically measured by the number of times all memory cells in a flash sector are erased to 0xFF and then rewritten to a non-0xFF value. The minimum number of erase / write cycles for a flash memory cell is generally 100,000.

[0005] In some intelligent monitoring systems, it is necessary to count the number of times a solenoid valve is opened and closed and store the data in the built-in flash memory of the microcontroller. Since the flash memory needs to be rewritten to store the new data every time the number of times the solenoid valve is opened increases, in practical applications, two storage units (two bytes) in the same sector are usually used to store the number of times the solenoid valve is opened and closed. That is, one storage unit is used to record the high-order data and the other storage unit is used to record the low-order data.

[0006] However, as the number of times the binary data recording the number of solenoid valve switching increases, the number of changes in the high-order bits of the binary data is much less than the number of changes in the low-order bits. This causes the storage unit used to record the high-order data to perform too many unnecessary erase and write operations when saving data to flash memory, resulting in a reduction in the overall number of erase and write cycles of the flash memory unit. Summary of the Invention

[0007] In view of the problem that some flash memory cells are discarded after a few erase / write cycles when storing data, resulting in a short lifespan, the present invention aims to provide a data storage and retrieval method that can improve the lifespan of flash memory cells.

[0008] To achieve the above object, the technical solution of the present invention is:

[0009] In a first aspect, the present invention provides a data storage method that can improve the lifespan of a flash memory cell, the method comprising the following steps:

[0010] S1. Set the starting storage address of the data in the flash. The starting storage address has two addresses and corresponds to two storage units belonging to two sectors. The two storage units are used to store the high-order character and low-order character of the data in a preset order.

[0011] S2. For newly received data, determine whether its high-order character has changed. If so, erase and write two of the storage units and sectors at the same time. Otherwise, erase and write only the storage unit and sector corresponding to the low-order character, and record the number of times the storage unit and sector used to store the low-order character has been erased and written.

[0012] S3. Determine whether the number of erase / write operations has reached the maximum count value of the two storage units. If yes, clear the data and store the high-order and low-order characters of the subsequently received data in the two storage units in reverse order. Otherwise, continue to execute S2.

[0013] S4. For the subsequently received data, determine whether the high-order character has changed. If so, erase and write two of the storage units and sectors at the same time. Otherwise, erase and write only the storage unit and sector corresponding to the low-order character, and record the number of times the storage unit and sector used to store the low-order character has been erased and written.

[0014] S5. Determine whether the number of erase / write operations has reached the maximum count value of the two memory cells again. If yes, clear the data and enable the other two memory cells located after the two starting memory addresses to save the data received later, and repeat S2. Otherwise, continue to execute S4.

[0015] Preferably, in S1, the starting storage address is stored in a read sector of the flash memory that is different from the sector used to store the data, and the read sector also stores the current storage address corresponding to the storage unit that is in use.

[0016] Preferably, the two storage units are respectively configured with identifier A and identifier B. One of the storage units identified by identifier A and identifier B is used to store the high-order character, and the other storage unit identified by identifier A and identifier B is used to store the low-order character. Identifier A and identifier B are stored in the read sector. The read sector also stores a sequence identifier, which includes a preset sequence identifier for indicating that the two storage units store the high-order character and the low-order character respectively in the preset order, and a reverse sequence identifier for indicating that the two storage units store the high-order character and the low-order character respectively in the reverse order.

[0017] Preferably, when the sequence identifier stored in the read sector is a preset sequence identifier, it means that the storage unit identified by identifier A is used to store the high-order character and the storage unit identified by identifier B is used to store the low-order character; when the sequence identifier stored in the read sector is a reverse sequence identifier, it means that the storage unit identified by identifier B is used to store the high-order character and the storage unit identified by identifier A is used to store the low-order character, and the storage unit identified by identifier A has already been used to store the high-order character and the storage unit identified by identifier B has already been used to store the low-order character.

[0018] Preferably, the identifier A and the identifier B are the storage addresses corresponding to the two storage units, respectively.

[0019] Preferably, the storage unit, the high-order character, and the low-order character of the data each have eight bits.

[0020] Preferably, the maximum count value of the two storage cells is 65536.

[0021] Preferably, the sector to be read is the last sector in the flash memory.

[0022] Preferably, the data is a binary number recording the number of times the solenoid valve is switched, such that the data increases sequentially.

[0023] Secondly, the present invention also provides a data reading method that can improve the lifespan of a flash memory cell. The method is used to read the total value of data stored in the flash memory according to the above method, and includes the following steps:

[0024] S10. Read the current storage address, starting storage address, and sequence identifier of the storage unit from the read sector;

[0025] S20. Read the current data stored in the two corresponding storage units according to the sequence identifier and the current storage address;

[0026] S30. Calculate the total value of the data based on the maximum count value of the two storage units, the difference between the current storage address and the starting storage address, and the current data.

[0027] The beneficial effects of the present invention using the above technical solution are as follows: Since the high-order and low-order characters of the data are stored in two different sectors, erasing or writing the sector containing the low-order character will not affect the sector containing the high-order character. When the number of switching operations of the solenoid valve or other devices increases, it is determined whether the high-order character has changed. If there is no change, the sector and storage unit containing the high-order character will not be erased or written. Therefore, when the recorded data reaches 65,536 times, the high-order character has only changed 256 times, that is, the flash storage unit containing the high-order character has only been erased or written 256 times, avoiding repeated erasing and writing. Then, the number of switching operations of the solenoid valve is reset to zero, and the storage positions of the high-order and low-order characters are swapped, thereby balancing the wear of the two storage units and enabling the two storage units to store twice as much data, thereby improving the lifespan of the flash. Attached Figure Description

[0028] Figure 1 This is a flowchart of a data storage method that can improve the lifespan of a flash memory cell according to the present invention;

[0029] Figure 2 This is a flowchart of a data reading method that can improve the lifespan of a flash memory unit according to the present invention. Detailed Implementation

[0030] The specific embodiments of the present invention will be further described below with reference to the accompanying drawings. It should be noted that these descriptions are for the purpose of aiding understanding the present invention, but do not constitute a limitation thereof. Furthermore, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.

[0031] It should be noted that in the description of this invention, the terms "upper", "lower", "left", "right", "front", "rear", etc., indicate the orientation or positional relationship based on the description of the structure of this invention shown in the accompanying drawings. They are only for the convenience of describing this invention and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on this invention.

[0032] The terms "first" and "second" in this technical solution are merely designations for corresponding structures that are identical or similar, or that perform similar functions. They do not represent an arrangement of the importance of these structures, nor do they imply any ranking, comparison of size, or other meaning.

[0033] Furthermore, unless otherwise explicitly specified and limited, the terms "installation" and "connection" should be interpreted broadly. For example, a connection 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 a connection within two structures. Those skilled in the art can understand the specific meaning of the above terms in this invention by considering the overall concept of the invention and the specific context of the solution.

[0034] Example 1

[0035] A data storage method for improving the lifespan of flash memory cells is disclosed. In this embodiment, the data stored in the flash represents the number of times a solenoid valve or other functional component is switched on and off. This data is characterized by increasing sequentially, and changes accordingly with each increase. Therefore, the memory cells in the flash need to be erased and rewritten. Each erase and rewrite operation reduces the lifespan of the flash. The method provided in this embodiment enables the flash memory cell to store as much data as possible representing the number of times a solenoid valve or other functional component is switched on and off, thereby relatively improving the lifespan of the flash memory cell.

[0036] like Figure 1 As shown, this method includes the following steps:

[0037] S1. Set the starting storage address of the data in the flash. There are two starting storage addresses, which correspond to two storage units belonging to two sectors respectively. The two storage units are used to store the high-order character and low-order character of the data in a preset order.

[0038] It is understandable that flash memory typically contains multiple sectors, each with multiple storage units. These storage units are used to store the characters that constitute the data, thereby enabling data preservation. In this embodiment, each storage unit has 8 bits, used to store 8-bit binary characters. Each storage unit corresponds to an address, configured as a 16-bit binary number. During use, this address is used to perform erase and write operations on the corresponding storage unit. In this embodiment, the data to be preserved consists of 16-bit binary characters, which are divided into 8 high-order bits and 8 low-order bits, and stored separately in two storage units. These two storage units belong to two different sectors within the flash memory, and the addresses corresponding to these two storage units are called the starting storage addresses.

[0039] Both storage units have corresponding identifiers to distinguish which storage unit the high-order character and the low-order character should be stored in during erase and write operations. At the same time, a sequence identifier should also be configured so that the high-order character and the low-order character can be stored in the correct order during erase and write operations.

[0040] In this embodiment, a read sector is also set in the flash memory that is different from the two sectors mentioned above (sectors of storage units used to store data). For example, it is the last sector in the flash memory. The starting storage address, the identifiers configured for the two storage units, and the sequence identifiers are all stored in this read sector.

[0041] For example, the two storage units mentioned above are configured with identifiers A and B, respectively. Identifiers A and B can be the storage addresses corresponding to the two storage units, or they can be other character-type identifiers used only for differentiation. The storage unit identified by identifier A is configured to store the 8 high-order bits of the data, and the storage unit identified by identifier B is configured to store the 8 low-order bits of the data, or vice versa.

[0042] The aforementioned sequence identifiers include a preset sequence identifier and a reverse sequence identifier. The preset sequence identifier indicates that two storage units store the high-order character and low-order character respectively in a preset order. For example, a storage unit with identifier A stores the 8 high-order characters of the data, and a storage unit with identifier B stores the 8 low-order characters of the data. The reverse sequence identifier indicates that two storage units store the high-order character and low-order character in reverse order. For example, a storage unit with identifier B stores the 8 high-order characters of the data, and a storage unit with identifier A stores the 8 low-order characters of the data.

[0043] In practical application, the solution of this embodiment stores only one sequence identifier in the read sector. Specifically, when the sequence identifier stored in the read sector is a preset sequence identifier, it indicates that the storage unit with identifier A is used to store 8 high-order characters, and the storage unit with identifier B is used to store 8 low-order characters. It also indicates that the storage unit with identifier A has not been used to store 8 low-order characters, and the storage unit with identifier B has not been used to store 8 high-order characters. When the sequence identifier stored in the read sector is a reverse sequence identifier, it indicates that the storage unit with identifier B is used to store 8 high-order characters, and the storage unit with identifier A is used to store 8 low-order characters. It also indicates that the storage unit with identifier A has already been used to store 8 high-order characters, and the storage unit with identifier B has already been used to store 8 low-order characters.

[0044] At the beginning of this method's execution, the following configuration is made: a storage unit with identifier A is used to store the 8-bit high-order character of the data, a storage unit with identifier B is used to store the 8-bit low-order character of the data, and the read sector stores the preset sequence identifier.

[0045] S2. For newly received data, determine whether its high-order character has changed. If so, erase and write two storage units and sectors simultaneously. Otherwise, erase and write only the storage unit and sector corresponding to the low-order character, and record the number of erase and write operations of the storage unit and sector used to store the low-order character.

[0046] Understandably, since data is added sequentially, in most cases only the 8 least significant bits change, while the 8 most significant bits rarely change. Based on this principle, to conserve memory resources, when the 8 most significant bits remain unchanged, the memory cell used to store them (the cell with identifier A) is not erased; only the memory cell used to store the 8 least significant bits (the cell with identifier B) is erased. Furthermore, both memory cells are erased simultaneously only when the 8 most significant bits of the data also change.

[0047] S3. Determine whether the number of erase / write cycles of the storage unit used to store the low-order character has reached the maximum count value of the two storage units. If yes, clear the data and store the high-order and low-order characters of the subsequently received data in the two storage units in reverse order. Otherwise, continue to execute S2.

[0048] In this embodiment, the storage unit has only 8 bits, so there is an upper limit to the number of times it can be erased and rewritten. Continuing to erase and rewrite will lead to data duplication. Since both storage units are used for counting simultaneously, totaling 16 bits, the maximum count value of the two storage units can be calculated to be 65536. The storage unit used to store the 8 high-order characters (the storage unit with identifier A) has only been erased and rewritten 256 times. It can be seen that its erase and rewrite count is much lower than that of the storage unit used to store the 8 low-order characters (the storage unit with identifier B). This results in an uneven wear and tear on the two storage units. If both units are discarded at the same time, the maximum calculation value of the flash memory will be greatly reduced, thereby greatly shortening its service life.

[0049] Therefore, when the erase / write count of the storage unit (the storage unit with identifier A) used to store the 8-bit high-order character is detected to reach 65536, this embodiment first clears the data and modifies the sequence identifier saved in the read sector to a directional sequence identifier. This ensures that the 8-bit high-order character of subsequently received data (restarting the count from zero) is stored in the storage unit with identifier B, and the 8-bit low-order character is stored in the storage unit with identifier A. After continuing to count, the erase / write count of the storage unit with identifier B is much greater than that of the storage unit with identifier A, thus balancing the wear of the two storage units and doubling the total count. When reading the total count, the sequence identifier in the read sector indicates whether the two storage units have swapped the high-order and low-order character storage functions. If the sequence identifier is a reverse sequence identifier, the total count is obtained by adding 65536 to the 16-bit binary number currently stored in the two storage units.

[0050] S4. For subsequently received data, determine whether the high-order character has changed. If so, erase and write both storage units and sectors simultaneously. Otherwise, erase and write only the storage unit and sector corresponding to the low-order character, and record the number of times the storage unit and sector used to store the low-order character has been erased and written.

[0051] This step is the same as S2, except that the storage order of the 8-bit high-order character and the 8-bit low-order character in the two storage units is reversed.

[0052] S5. Determine whether the number of erase / write operations has reached the maximum count value of the two memory cells again. If yes, clear the data and enable the other two memory cells located after the two starting memory addresses to save the data received later, and repeat S2. Otherwise, continue to execute S4.

[0053] Understandably, even if the functions of two storage units are swapped, the total calculated value only doubles, i.e., 2 × 65536. Therefore, once this value is reached, the data needs to be cleared, and two additional storage units need to be enabled. For example, the two newly enabled storage units are located after the two previously used storage units, and the above process is repeated until all storage units in all sectors of the flash memory, except for the read sector, are enabled. Understandably, the read sector also stores the current memory address corresponding to the storage unit currently in use.

[0054] Example 2

[0055] This invention also provides a data reading method that can improve the lifespan of a flash memory cell. This method is used to read the total value of data stored in the flash memory according to the method described in Embodiment 1, such as... Figure 2 As shown, it includes the following steps:

[0056] S10. Read the current storage address, starting storage address, and sequence identifier of the storage unit from the read sector;

[0057] S20. Read the current data stored in the two corresponding storage units according to the sequence identifier and the current storage address;

[0058] S30. Calculate the total value of the data based on the maximum count value of the two storage units, the difference between the current storage address and the starting storage address, and the current data.

[0059] According to the method steps in Embodiment 1, the maximum countable value between two storage units is 2×65536. Therefore, based on the current storage address and the starting storage address, it can be known how many storage units have been enabled, for example, n pairs; based on the 16-bit character data stored in the two currently used storage units, it can be directly converted into the current decimal data, for example, m; and based on the sequence identifier, it can be known whether the two currently used storage units have undergone functional interchange.

[0060] That is: when the sequence identifier is the reverse sequence identifier, the total count is 2×65536×n+m+65536; when the sequence identifier is the preset sequence identifier, the total count is 2×65536×n+m.

[0061] The embodiments of the present invention have been described in detail above with reference to the accompanying drawings, but the present invention is not limited to the described embodiments. For those skilled in the art, various changes, modifications, substitutions, and variations can be made to these embodiments without departing from the principles and spirit of the present invention, and these variations still fall within the protection scope of the present invention.

Claims

1. A data storage method that can improve the lifespan of flash memory cells, characterized in that: The method includes the following steps: S1. Set the starting storage address of the data in the flash. The starting storage address has two addresses and corresponds to two storage units belonging to two sectors. The two storage units are used to store the high-order character and low-order character of the data in a preset order. S2. For newly received data, determine whether its high-order character has changed. If so, erase and write two of the storage units and sectors at the same time. Otherwise, erase and write only the storage unit and sector corresponding to the low-order character, and record the number of times the storage unit and sector used to store the low-order character has been erased and written. S3. Determine whether the number of erase / write operations has reached the maximum count value of the two storage units. If yes, clear the data and store the high-order and low-order characters of the subsequently received data in the two storage units in reverse order. Otherwise, continue to execute S2. S4. For the subsequently received data, determine whether the high-order character has changed. If so, erase and write two of the storage units and sectors at the same time. Otherwise, erase and write only the storage unit and sector corresponding to the low-order character, and record the number of times the storage unit and sector used to store the low-order character has been erased and written. S5. Determine whether the number of erase / write operations has reached the maximum count value of the two memory cells again. If yes, clear the data and enable the other two memory cells located after the two starting memory addresses to save the data received later, and repeat S2. Otherwise, continue to execute S4.

2. The method according to claim 1, characterized in that: In S1, the starting storage address is stored in a read sector of the flash memory that is different from the sector used to store the data, and the read sector also stores the current storage address corresponding to the storage unit that is in use.

3. The method according to claim 2, characterized in that: The two storage units are respectively configured with identifier A and identifier B. One of the storage units identified by identifier A and identifier B is used to store the high-order character, and the other of the storage units identified by identifier A and identifier B is used to store the low-order character. Identifier A and identifier B are stored in the read sector. The read sector also stores a sequence identifier, which includes a preset sequence identifier for indicating that the two storage units store the high-order character and the low-order character respectively in the preset order, and a reverse sequence identifier for indicating that the two storage units store the high-order character and the low-order character respectively in the reverse order.

4. The method according to claim 3, characterized in that: When the sequence identifiers stored in the read sector are preset sequence identifiers, it means that the storage unit identified by identifier A is used to store the high-order character and the storage unit identified by identifier B is used to store the low-order character; when the sequence identifiers stored in the read sector are reverse sequence identifiers, it means that the storage unit identified by identifier B is used to store the high-order character and the storage unit identified by identifier A is used to store the low-order character, and the storage unit identified by identifier A has already been used to store the high-order character and the storage unit identified by identifier B has already been used to store the low-order character.

5. The method according to claim 3, characterized in that: The identifier A and the identifier B are the storage addresses corresponding to the two storage units, respectively.

6. The method according to claim 1, characterized in that: The storage unit and the data both have eight bits in their high-order and low-order characters.

7. The method according to claim 6, characterized in that: The maximum count value of the two storage cells is 65536.

8. The method according to claim 2, characterized in that: The sector being read is the last sector in the flash memory.

9. The method according to claim 1, characterized in that: The data is a binary number recording the number of times the solenoid valve is switched, and the data is incremented one by one.

10. A data reading method for improving the lifespan of a flash memory cell, the method being used to read the total value of data stored in flash memory according to any one of claims 1-9, characterized in that: Includes the following steps: S10. Read the current storage address, starting storage address, and sequence identifier of the storage unit from the read sector; S20. Read the current data stored in the two corresponding storage units according to the sequence identifier and the current storage address; S30. Calculate the total value of the data based on the maximum count value of the two storage units, the difference between the current storage address and the starting storage address, and the current data.

Citation Information

Patent Citations

  • Nand Flash parameter reading method

    CN105280240A

  • STM32 single-chip microcomputer FLASH memory storage and reading algorithm

    CN112286452A