A data storage method and system applied to flash memory

By dividing variable data storage areas in flash memory and using overall erase and area writing methods, the service life problem of flash memory devices when frequently erasing and rewriting data is solved, and more stable and reliable data storage is achieved.

CN114816271BActive Publication Date: 2025-07-01SHANGHAI PANCHIP MICROELECTRONICS CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210622080.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-02
Publication Date
2025-07-01
Estimated Expiration
2042-06-02

AI Technical Summary

Technical Problem

When flash memory devices frequently erase and rewrite data, they can easily reach the limit of the number of erases allowed, resulting in corruption and failure of storage areas.

Method used

A variable data storage area is divided into the flash memory, and by erasing in advance and writing by region, the data is uniformly stored and multiplexed, reducing the number of erased times of flash memory.

Benefits of technology

It effectively extends the service life of flash memory, reduces the number of erases, and improves the stability and reliability of data storage.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114816271B_ABST
    Figure CN114816271B_ABST
Patent Text Reader

Abstract

The present invention provides a data storage method and system applied to a flash memory, relating to the technical field of data storage, including: when it is judged that the writable space in the volatile data storage area is sufficient to store the data to be written according to the write data length of the data to be written and the storage start address of the currently stored data in the volatile data storage area, the volatile data storage area is erased as a whole, and then the data to be written is written starting from the area start address of the volatile data storage area; when it is not sufficient to store the data to be written, the read data with the write data length is read starting from the storage start address, and the data with the data to be written is written when it can be written starting from the storage start address; when it cannot be written starting from the storage start address, all-0 data with the write data length is written starting from the storage start address, and the next address after the end address of the all-0 data is used as the storage start address. The beneficial effect is to effectively reduce the number of flash memory erasures and increase the service life of the flash memory.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data storage, and in particular, to a data storage method and system applied to flash memory. Background Art

[0002] Currently, when flash memory stores data, it usually first erases the flash memory storage area and then writes the data to be stored. Erasing flash memory data is either page-by-page erasure or block-by-block erasure. However, the number of erasure times of flash memory is limited. Most flash memories support 100,000 erasure operations. After that, when the flash memory is erased and stored again, the stability cannot be guaranteed.

[0003] When using flash memory to store data, in many cases, the stored data needs to be changed, so there is a need for frequent erasure and then rewriting. According to the traditional data storage operation mode of first erasing and then storing, when storing frequently changing data at an address location in flash memory, it is necessary to first erase the area and then write the changed data to that address location. For data with very frequent changes, according to this data storage operation mode, the allowable erasure times of the flash memory will soon be used up, resulting in damage and failure of the corresponding area of the flash memory. Summary of the Invention

[0004] In view of the problems existing in the prior art, the present invention provides a data storage method applied to flash memory, and a volatile data storage area is pre-divided in a flash memory; then the data storage method includes a data writing process, and the data writing process includes:

[0005] Step S1, obtaining a data to be written and the storage start address of the currently stored data in the volatile data storage area, and judging whether the writable space in the volatile data storage area is sufficient to store the data to be written according to the write data length of the data to be written and the storage start address:

[0006] If not, go to step S2;

[0007] If so, go to step S3;

[0008] Step S2, performing overall erasure on the volatile data storage area, then starting from the area start address of the volatile data storage area, writing the data to be written as the currently stored data, and then returning to step S1;

[0009] Step S3: Read a piece of data with the length of the data to be written starting from the storage start address, and determine whether the data to be written can be written starting from the storage start address based on the read data and the data to be written:

[0010] If so, write the data to be written as the current stored data starting from the storage start address, and then return to the step S1;

[0011] If not, write all 0 data with the length of the written data starting from the storage start address, and use the next address after the end address of the all 0 data as the storage start address, and then return to the step S1.

[0012] Preferably, in the step S1, the process of determining whether the writable space in the volatile data storage area is sufficient to store the data to be written includes:

[0013] Determine whether the remaining address length starting from the storage start address in the volatile data storage area is greater than the length of the written data:

[0014] If not, it means that the writable space is not sufficient to store the data to be written, and then go to the step S2;

[0015] If so, it means that the writable space is sufficient to store the data to be written, and then go to the step S3.

[0016] Preferably, in the step S3, the process of determining whether the data to be written can be written starting from the storage start address based on the read data and the data to be written includes:

[0017] Step A1: Determine whether the data to be written is all 0 data:

[0018] If so, go to step A2;

[0019] If not, go to step A3;

[0020] Step A2: Determine whether the read data is all 0xFF:

[0021] If so, it means that the data to be written can be written starting from the storage start address, no writing operation is performed, and the read data is used as the current stored data, and then return to the step S1;

[0022] If not, it means that the data to be written can be written starting from the storage start address, write the data to be written as the current stored data starting from the storage start address, and then return to the step S1;

[0023] Step A3: Determine whether the result of the bitwise AND operation between the data to be written and the read data is equal to the data to be written:

[0024] If so, it means that the data to be written can be written starting from the storage start address. Write the data to be written starting from the storage start address as the current stored data, and then return to the step S1;

[0025] If not, it means that the data to be written cannot be written starting from the storage start address. Write all 0 data with the length of the write data starting from the storage start address, and use the next address after the end address of the all 0 data as the storage start address, and then return to the step S1.

[0026] Preferably, in the step A2 and the step A3, after using the read data as the current stored data, it further includes recording the current storage address as the write start traversal address;

[0027] After writing the data to be written starting from the storage start address as the current stored data, it further includes recording the next address after the write end address of the data to be written as the write start traversal address;

[0028] Then in the step S1, the process of obtaining the storage start address includes:

[0029] Determine whether the write start traversal address is queried:

[0030] If so, start traversing the volatile data storage area from the write start traversal address to use the first non-zero data address as the storage start address;

[0031] If not, start traversing the volatile data storage area from the area start address of the volatile data storage area to use the first non-zero data address as the storage start address.

[0032] Preferably, the data storage method further includes a data reading process, and the data reading process includes:

[0033] Step B1: Obtain a read start address in the volatile data storage area according to an external read request;

[0034] Step B2: Determine whether the remaining address length starting from the read start address in the volatile data storage area is greater than the read data length;

[0035] If not, return the data reading result that the current stored data is all zeros, and then return to the step B1;

[0036] If so, go to step B3;

[0037] Step B3: Determine whether the current stored data that is not all 0xFF is found within the remaining address length;

[0038] If so, return the found current stored data as the data read result, and then return to step B1;

[0039] If not, return a data read result with all zeros for the current stored data, and then return to step B1.

[0040] Preferably, the read request includes a read data length; then step B3 includes:

[0041] Step B31: Determine whether the current stored data of the read data length starting from the read start address is all 0;

[0042] If so, use the next address after the end address of the current stored data as the read start address, and then return to step B31;

[0043] If not, go to step B32;

[0044] Step B32: Determine whether the current stored data is all 0xFF;

[0045] If so, return a data read result with all zeros for the current stored data, and then return to step B1;

[0046] If not, return the current stored data as the data read result, and then return to step B1.

[0047] Preferably, in step B2, when the remaining address length is not greater than the read data length, it further includes subtracting the read data length from the read start address to obtain a data address and recording it as the read start traversal address;

[0048] In step B31, when the current stored data of the read data length starting from the read start address is not all 0, it further includes using the read start address as the read start traversal address;

[0049] Then in step B1, the process of obtaining the read start address includes:

[0050] Determine whether the read start traversal address is found;

[0051] If so, start traversing the volatile data storage area from the read start traversal address to use the first data address that is not 0 as the read start address;

[0052] If not, traverse the volatile data storage area starting from the area start address of the volatile data storage area, and use the data address of the first non-zero data as the read start address.

[0053] The present invention also provides a data storage system applied to a flash memory, which applies the above data storage method. The data storage system includes:

[0054] A data writing module, connected to a volatile data storage area of a flash memory. The data writing module includes:

[0055] A first judgment unit, configured to obtain a data to be written and a storage start address of the currently stored data in the volatile data storage area, and output an erase signal when judging that the writable space in the volatile data storage area is not sufficient to store the data to be written according to the write data length of the data to be written and the storage start address, and output a write signal when the writable space is sufficient to store the data to be written;

[0056] An erase-and-write unit, connected to the first judgment unit, configured to perform an overall erase on the volatile data storage area according to the erase signal, and then write the data to be written starting from the area start address of the volatile data storage area as the currently stored data;

[0057] A second judgment unit, connected to the first judgment unit, configured to read a read data of the write data length starting from the storage start address according to the write signal, and when judging that the data to be written can be written starting from the storage start address according to the read data and the data to be written, write the data to be written starting from the storage start address as the currently stored data,

[0058] and when it is not possible to write the data to be written starting from the storage start address, write all 0 data with the write data length starting from the storage start address, and use the next address of the end address of the all 0 data as the storage start address.

[0059] Preferably, the second judgment unit includes:

[0060] A first judgment sub-unit, configured to output a first signal when judging that the data to be written is all 0 data, and output a second signal when judging that the data to be written is not all 0;

[0061] A second judgment subunit, connected to the first judgment subunit, is configured to, according to the first signal, when it is determined that all the read data is 0xFF, not perform a write operation and use the read data as the current stored data, and when it is determined that the read data is not all 0xFF, write the data to be written starting from the storage start address as the current stored data;

[0062] A third judgment subunit, connected to the first judgment subunit, is configured to, according to the second signal, when the result of the bitwise AND operation between the data to be written and the read data is equal to the data to be written, write the data to be written starting from the storage start address as the current stored data,

[0063] and when it is determined that the result is not equal to the data to be written, write all-0 data with the write data length starting from the storage start address, and use the next address of the end address of the all-0 data as the storage start address.

[0064] Preferably, it further includes a data reading module connected to the volatile data storage area. The data reading module includes:

[0065] An address acquisition unit is configured to acquire a read start address in the volatile data storage area according to an external read request;

[0066] A third judgment unit, connected to the address acquisition unit, is configured to, when it is determined that the remaining address length starting from the read start address in the volatile data storage area is not greater than the read data length, return a data reading result with all-zero current stored data, and output a third signal when the remaining address length is greater than the read data length;

[0067] A fourth judgment unit, connected to the third judgment unit, is configured to, according to the third signal, when it is determined that the current stored data that is not all 0xFF can be queried within the remaining address length, return the queried current stored data as the data reading result, and when the current stored data that is not all 0xFF cannot be queried, return a data reading result with all-zero current stored data.

[0068] The above technical solution has the following advantages or beneficial effects:

[0069] 1) Divide a volatile data storage area in the flash memory, so that when writing data, it can start writing from the starting address of the area of the volatile data storage area until the end address of the area of the volatile data storage area is used up, then perform an overall erasure on the volatile data storage area, and then start writing from the starting address of the area, and so on, which can evenly use the volatile data storage area, effectively reduce the number of flash memory erasures, and thus increase the service life of the flash memory;

[0070] 2) Apply the characteristic that the bit of the flash memory can only be written from 1 to 0. When writing changing data, it can realize writing all the current storage areas of the volatile data storage area as 0, and then writing the changing data to the next adjacent storage area. Furthermore, when reading data, starting from the starting address of the area of the volatile data storage area until reading data that is not 0 is the current stored data. If all are 0xFF, it means the current stored data is 0. BRIEF DESCRIPTION OF THE DRAWINGS

[0071] Figure 1 In a preferred embodiment of the present invention, it is a schematic flow chart of the data writing process;

[0072] Figure 2 In a preferred embodiment of the present invention, it is a schematic flow chart of the process of judging whether the data to be written can be written starting from the storage starting address according to the read data and the data to be written;

[0073] Figure 3 In a preferred embodiment of the present invention, it is a schematic flow chart of the data reading process;

[0074] Figure 4 In a preferred embodiment of the present invention, it is a schematic sub - flow chart of step B3;

[0075] Figure 5 In a preferred embodiment of the present invention, it is a schematic structural diagram of the data storage system;

[0076] Figure 6 In a preferred implementation manner of the present invention, it is a schematic diagram of the storage of off - line programming information in the flash memory FLASH. DETAILED DESCRIPTION OF THE INVENTION

[0077] The present invention will be described in detail below with reference to the accompanying drawings and specific embodiments. The present invention is not limited to this embodiment. As long as it conforms to the gist of the present invention, other embodiments can also fall within the scope of the present invention.

[0078] In a preferred embodiment of the present invention, based on the above - mentioned problems existing in the prior art, a data storage method applied to a flash memory is provided. A volatile data storage area is pre - divided in a flash memory; then the data storage method includes a data writing process, asFigure 1 As shown in the figure, the data writing process includes:

[0079] Step S1: Obtain a piece of data to be written and the storage start address of the currently stored data in the volatile data storage area, and determine whether the writable space in the volatile data storage area is sufficient to store the data to be written according to the write data length of the data to be written and the storage start address:

[0080] If not, go to step S2;

[0081] If so, go to step S3;

[0082] Step S2: Erase the entire volatile data storage area, then start writing the data to be written from the area start address of the volatile data storage area as the currently stored data, and then return to step S1;

[0083] Step S3: Read a piece of read data with the write data length starting from the storage start address, and determine whether the data to be written can be written starting from the storage start address according to the read data and the data to be written:

[0084] If so, write the data to be written starting from the storage start address as the currently stored data, and then return to step S1;

[0085] If not, write all 0 data with the write data length starting from the storage start address, and use the next address after the end address of the all 0 data as the storage start address, and then return to step S1.

[0086] Specifically, in this embodiment, the above-mentioned volatile data storage area includes, but is not limited to, a page area or a block area in a flash memory. Utilizing the characteristic that the bit in the flash memory can only be written from 1 to 0, after performing an overall erasure on the volatile data storage area, each bit in the volatile data storage area is 1. Subsequently, the data to be written is written starting from the area start address of the volatile data storage area. At this time, the storage start address of the currently stored data in the volatile data storage area is the area start address. Taking the size of the volatile data storage area as 128 bytes and the write data length of the data to be written as 32 bits (4 bytes) as an example, at this time, the writable space in the volatile data storage area is sufficient to store the data to be written. Based on this, 4 bytes of read data are read starting from the storage start. It can be seen that each bit of the read data is 1 at this time. Utilizing the characteristic that the bit in the flash memory can only be written from 1 to 0, at this time, no matter what value the data to be written is, it can be written starting from the storage start address.

[0087] After a one-time write is completed, if the data to be written needs to change again, the above steps are executed again. At this time, the storage start address is still the start address of the area. It can be seen that the writable space of the volatile data storage area is still sufficient to store the data to be written. Based on this, 4 bytes of read data are obtained by reading starting from the storage start address. It can be known that each bit of the read data at this time is the data to be written last time. Using the characteristic that the bits of the flash memory can only be written from 1 to 0, taking one bit of the data to be written last time as 0 and this bit of the data to be written currently as 1 as an example, since the bit cannot be written from 0 to 1, it is considered that the data to be written cannot be written starting from the storage start address at this time. At this time, first, 4 bytes of all-0 data are written starting from the storage start address, and the next address after the end address of the all-0 data is used as the storage start address. Then, it is determined again whether 4 bytes can be accommodated between this storage start address and the end address of the volatile data storage area. If it can be accommodated, the data to be written currently is written starting from the next address after the end address of the all-0 data, and so on, until the writable space of the volatile storage area is not sufficient to store the data to be written. Then, a whole erasure of the volatile storage area is required, and then the data to be written is written starting from the start address of the volatile data storage area, and the data storage operation is performed in a loop.

[0088] It can be seen that in the data storage method adopting this technical solution, taking the data to be written that often changes as 4 bytes and the size of the volatile data storage area as 128 bytes as an example, the data to be written needs to change at least 128 / 4 = 32 times before an erasure operation is performed on this volatile data storage area, realizing the uniform use of the volatile data storage area, reducing the number of erasures of the flash memory at the same time, and thus increasing the service life of the flash memory. Preferably, the size of the volatile data storage area can be configured according to the change frequency of the data to be written that often changes. If the change frequency is relatively large, a volatile data storage area with a larger storage space can be configured correspondingly to reduce the number of erasures of the flash memory.

[0089] In a preferred embodiment of the present invention, in step S1, the process of determining whether the writable space of the volatile data storage area is sufficient to store the data to be written includes:

[0090] Determining whether the remaining address length starting from the storage start address in the volatile data storage area is greater than the length of the written data:

[0091] If not, it means that the writable space is not sufficient to store the data to be written, and then it turns to step S2;

[0092] If so, it means that the writable space is sufficient to store the data to be written, and then it turns to step S3.

[0093] Specifically, in this embodiment, the remaining address length represents the storage space size between the storage start address and the area end address of the volatile data storage area.

[0094] In a preferred embodiment of the present invention, in step S3, as Figure 2 shown, the process of judging whether the data to be written can be written starting from the storage start address according to the read data and the data to be written includes:

[0095] Step A1, judge whether the data to be written is all 0 data:

[0096] If so, go to step A2;

[0097] If not, go to step A3;

[0098] Step A2, judge whether the read data is all 0xFF:

[0099] If so, it means that the data to be written can be written starting from the storage start address, no write operation is performed, and the read data is used as the current stored data, and then return to step S1;

[0100] If not, it means that the data to be written can be written starting from the storage start address, and the data to be written is written starting from the storage start address as the current stored data, and then return to step S1;

[0101] Step A3, judge whether the result of the bitwise AND of the data to be written and the read data is equal to the data to be written:

[0102] If so, it means that the data to be written can be written starting from the storage start address, and the data to be written is written starting from the storage start address as the current stored data, and then return to step S1;

[0103] If not, it means that the data to be written cannot be written starting from the storage start address, and all 0 data with the write data length is written starting from the storage start address, and the next address after the end address of the all 0 data is used as the storage start address, and then return to step S1.

[0104] Specifically, in this embodiment, when the data to be written is all-0 data, if the read data is all 0xFF, it can indicate that the current stored data in the volatile storage area is already 0. At this time, it can be considered that the data to be written has not changed, and there is no need to perform the write operation again. When the data to be written is all-0 data and the read data is not all 0xFF, it indicates that the data to be written has changed, and a write operation needs to be performed. Since the data to be written is all 0, using the characteristic that the bit of the flash memory can only be written from 1 to 0, the data to be written can be successfully written as the current stored data starting from the storage start address, and the overwrite write method is adopted without the need to erase first and then write, realizing the reuse of this storage space and further reducing the number of erasures of the flash memory.

[0105] When the data to be written is not all-0 data, the data to be written is bitwise ANDed with the read data. If one of the bits of the data to be written is 0, regardless of whether the value of the corresponding bit of the read data is 1 or 0, the result of the bitwise AND is 0. If one of the bits of the data to be written is 1, the value of the corresponding bit of the read data needs to be 1 for the result of the bitwise AND to be equal to the corresponding bit of the data to be written. If one of the bits of the data to be written is 1 and the value of the corresponding bit of the read data is 0, the result of the bitwise AND is 0, which is not equal to the corresponding bit of the data to be written. Using the characteristic that the bit of the flash memory can only be written from 1 to 0, if the overwrite write method is still adopted at this time, the write cannot be successful. Based on this, in this embodiment, when the result of the bitwise AND of the data to be written and the read data is equal to the data to be written, the overwrite write method is adopted to realize the reuse of this storage space in the volatile data storage area. When the result of the bitwise AND of the data to be written and the read data is not equal to the data to be written, all-0 data with the write data length is written starting from the storage start address, and the next address after the end address of the all-0 data is used as the storage start address, and then step S1 is returned to repeat the above process to realize successful writing of the data to be written while reducing the number of erasures of the flash memory.

[0106] In a preferred embodiment of the present invention, in steps A2 and A3, after taking the read data as the current stored data, it further includes recording the current storage address as the write start traversal address;

[0107] After writing the data to be written as the current stored data starting from the storage start address, it further includes recording the next address after the write end address of the data to be written as the write start traversal address;

[0108] Then in step S1, the process of obtaining the storage start address includes:

[0109] Determine whether the write start traversal address is queried:

[0110] If so, traverse the volatile data storage area starting from the write start traversal address, and use the first data address that is not 0 as the storage start address;

[0111] If not, traverse the volatile data storage area starting from the area start address of the volatile data storage area, and use the first data address that is not 0 as the storage start address.

[0112] Specifically, in this embodiment, by recording the write start traversal address, when writing the data to be written next time, there is no need to query the storage start address starting from the area start address of the volatile data storage area, effectively improving the query efficiency. At the same time, considering that when the flash memory is initialized, there may be no write start traversal address, so at this time, query starts from the area start address of the volatile data storage area to obtain the storage start address.

[0113] In a preferred embodiment of the present invention, the data storage method further includes a data reading process, as Figure 3 shown, the data reading process includes:

[0114] Step B1, obtain a read start address in the volatile data storage area according to an external read request;

[0115] Step B2, determine whether the remaining address length starting from the read start address in the volatile data storage area is greater than the read data length:

[0116] If not, return the data reading result that the current stored data is all zero, and then return to step B1;

[0117] If so, go to step B3;

[0118] Step B3, determine whether the current stored data that is not all 0xFF is found within the remaining address length:

[0119] If so, return the found current stored data as the data reading result, and then return to step B1;

[0120] If not, return the data reading result that the current stored data is all zero, and then return to step B1.

[0121] In a preferred embodiment of the present invention, the read request includes a read data length; as Figure 4 shown, then step B3 includes:

[0122] Step B31, determine whether the current stored data of the read data length starting from the read start address is all 0:

[0123] If so, use the next address of the end address of the current stored data as the read start address, and then return to step B31;

[0124] If not, go to step B32;

[0125] Step B32: Determine whether all the currently stored data is 0xFF:

[0126] If so, return the data reading result that the currently stored data is all zeros, and then return to step B1;

[0127] If not, return the currently stored data as the data reading result, and then return to step B1.

[0128] In a preferred embodiment of the present invention, in step B2, when the remaining address length is not greater than the data reading length, it further includes subtracting the data reading length from the reading start address to obtain a data address and recording it as the reading start traversal address;

[0129] In step B31, when not all of the currently stored data of the data reading length starting from the reading start address is 0, it further includes using the reading start address as the reading start traversal address;

[0130] Then in step B1, the process of obtaining the reading start address includes:

[0131] Determine whether the reading start traversal address is queried:

[0132] If so, start traversing the volatile data storage area from the reading start traversal address to use the first non-zero data address as the reading start address;

[0133] If not, start traversing the volatile data storage area from the area start address of the volatile data storage area to use the first non-zero data address as the reading start address.

[0134] Specifically, in this embodiment, by recording the reading start traversal address, when data needs to be read next time, there is no need to start querying the reading start address from the area start address of the volatile data storage area, effectively improving the reading efficiency.

[0135] The present invention also provides a data storage system applied to a flash memory, applying the above data storage method, as Figure 5 shown, the data storage system includes:

[0136] A data writing module 1, connected to a volatile data storage area 2 of a flash memory, and the data writing module 1 includes:

[0137] The first judgment unit 11 is configured to obtain a data to be written and a storage start address of the currently stored data in the volatile data storage area, and output an erase signal when it is determined that the writable space in the volatile data storage area is not sufficient to store the data to be written according to the write data length of the data to be written and the storage start address, and output a write signal when the writable space is sufficient to store the data to be written;

[0138] The erase-and-write unit 12 is connected to the first judgment unit 11 and is configured to perform an overall erasure on the volatile data storage area according to the erase signal, and then write the data to be written starting from the area start address of the volatile data storage area as the currently stored data;

[0139] The second judgment unit 13 is connected to the first judgment unit 11 and is configured to read a read data of the write data length starting from the storage start address according to the write signal, and when it is determined that the data to be written can be written starting from the storage start address according to the read data and the data to be written, write the data to be written starting from the storage start address as the currently stored data,

[0140] and when it is determined that the data to be written cannot be written starting from the storage start address, write all-0 data with the write data length starting from the storage start address, and use the next address after the end address of the all-0 data as the storage start address.

[0141] In a preferred embodiment of the present invention, the second judgment unit 13 includes:

[0142] The first judgment subunit 131 is configured to output a first signal when it is determined that the data to be written is all-0 data, and output a second signal when it is determined that the data to be written is not all-0;

[0143] The second judgment subunit 132 is connected to the first judgment subunit 131 and is configured to, according to the first signal, when it is determined that the read data is all 0xFF, not perform a write operation and use the read data as the currently stored data, and when it is determined that the read data is not all 0xFF, write the data to be written starting from the storage start address as the currently stored data;

[0144] The third judgment subunit 133 is connected to the first judgment subunit 132 and is configured to, according to the second signal, when it is determined that the result of the bitwise AND operation between the data to be written and the read data is equal to the data to be written, write the data to be written starting from the storage start address as the currently stored data,

[0145] and when the judgment result is not equal to the data to be written, write all-0 data with the write data length starting from the storage start address, and use the next address after the end address of the all-0 data as the storage start address.

[0146] In a preferred embodiment of the present invention, it further includes a data reading module 3, which is connected to the volatile data storage area 2. The data reading module 3 includes:

[0147] An address acquisition unit 31, configured to acquire a reading start address in the volatile data storage area according to an external reading request;

[0148] A third judgment unit 32, connected to the address acquisition unit 31, is configured to return a data reading result that the currently stored data is all zeros when the remaining address length starting from the reading start address in the volatile data storage area is not greater than the reading data length, and output a third signal when the remaining address length is greater than the reading data length;

[0149] A fourth judgment unit 33, connected to the third judgment unit 32, is configured to return the currently stored data found as the data reading result when it is determined according to the third signal that the currently stored data that is not all 0xFF can be found within the remaining address length, and return a data reading result that the currently stored data is all zeros when the currently stored data that is not all 0xFF cannot be found.

[0150] As a preferred implementation manner, this technical solution can be applied to the application scenario where a flash memory FLASH is used in a burner to record the number of times of offline programming of the chip program. After the preset allowable number of times of offline programming of the chip, each time after a successful download, the usage times need to be recorded and subtracted by one.

[0151] Specifically, the offline programming information in the flash memory FLASH is stored as Figure 6 shown. The total number of programming is stored in a Sector 4K area. Since the maximum value of the total number of programming is set to 9,999,999 times, it is stored in units of 32-bit data (4 bytes) as the minimum unit.

[0152] When setting the total number of programming, first query and store from the starting area of the total number of programming storage area until the end area is all stored and cannot be stored again, then the total number of programming storage area will be erased once, and then stored from the starting area again.

[0153] The used times storage area is also stored in a Sector 4K area, storing 32-bit (4-byte) used times data. The storage method is also to first query and store from the starting area of the used times storage area until the end area is all stored and cannot be stored again, then the used times storage area will be erased once.

[0154] When setting the total number of programming, it is necessary to clear the used times, read and judge whether the data in the used times storage area is 0. If it is not 0, write it as 0 first.

[0155] The total number of times used storage area is also stored in a 4K Sector area. The minimum storage unit is 1 byte (4 bytes). When the 1 bit of the minimum unit changes from 1 to 0 during counting, it is counted as one use. Therefore, 1 byte can record 8 times of use. According to this recording method, when all 1s in the 4K area are written as 0s, the count can reach 4096 * 8 = 32768 times.

[0156] When setting the total number of burn-in, it is necessary to detect whether there is a count in the total number of times used storage area. If there is a count, it needs to be erased and cleared.

[0157] If the count in the total number of times used storage area exceeds 32768 times, only need to erase the total number of times used storage area once to change all the data in this area to 1. Then, after adding 32768 times to the 32-bit data stored in the total number of times used, it is stored.

[0158] Storing and counting according to this technical solution can more effectively reduce the number of erasures of the FLASH memory, and at the same time increase the service life of the FLASH memory.

[0159] The above are only the preferred embodiments of the present invention, and do not limit the implementation manners and protection scope of the present invention. For those skilled in the art, it should be realized that all equivalent replacements and obvious changes made by using the content of this specification and the drawings should be included in the protection scope of the present invention.

Claims

1. A data storage method applied to a flash memory, characterized in that Pre-divide a volatile data storage area in a flash memory in advance; then the data storage method includes a data writing process, and the data writing process includes: Step S1, obtain a data to be written and the storage start address of the currently stored data in the volatile data storage area, and judge whether the writable space in the volatile data storage area is sufficient to store the data to be written according to the write data length of the data to be written and the storage start address: If not, go to step S2; If so, go to step S3; Step S2, perform an overall erasure on the volatile data storage area, then start writing the data to be written from the area start address of the volatile data storage area as the currently stored data, and then return to step S1; Step S3, read a read data of the write data length starting from the storage start address, and judge whether the data to be written can be written starting from the storage start address according to the read data and the data to be written: If so, start writing the data to be written from the storage start address as the currently stored data, and then return to step S1; If not, start writing all-0 data with the write data length from the storage start address, and use the next address after the end address of the all-0 data as the storage start address, and then return to step S1; Among them, the process of judging whether the data to be written can be written starting from the storage start address according to the read data and the data to be written includes: Step A1, judge whether the data to be written is all-0 data: If so, go to step A2; If not, go to step A3; Step A2, judge whether the read data is all 0xFF: If so, it means that the data to be written can be written starting from the storage start address, no writing operation is performed, and the read data is used as the currently stored data, and then return to step S1; If not, it means that the data to be written can be written starting from the storage start address, start writing the data to be written from the storage start address as the currently stored data, and then return to step S1; Step A3, judge whether the result of the bitwise AND of the data to be written and the read data is equal to the data to be written: If so, it means that the data to be written can be written starting from the storage start address, start writing the data to be written from the storage start address as the currently stored data, and then return to step S1; If not, it means that the data to be written cannot be written starting from the storage start address, start writing all-0 data with the write data length from the storage start address, and use the next address after the end address of the all-0 data as the storage start address, and then return to step S1.

2. The data storage method according to claim 1, wherein In step S1, the process of judging whether the writable space in the volatile data storage area is sufficient to store the data to be written includes: Determine whether the remaining address length starting from the storage start address in the volatile data storage area is greater than the length of the data to be written: If not, it means that the writable space is not sufficient to store the data to be written, and then proceed to step S2; If so, it means that the writable space is sufficient to store the data to be written, and then proceed to step S3.

3. The data storage method according to claim 1, wherein In steps A2 and A3, after using the read data as the current stored data, it further includes recording the current storage address as the write start traversal address; After writing the data to be written starting from the storage start address as the current stored data, it further includes recording the next address of the write end address of the data to be written as the write start traversal address; Then in step S1, the process of obtaining the storage start address includes: Determine whether the write start traversal address is queried: If so, traverse the volatile data storage area starting from the write start traversal address to use the first non-zero data address as the storage start address; If not, traverse the volatile data storage area starting from the area start address of the volatile data storage area to use the first non-zero data address as the storage start address.

4. The data storage method according to claim 1, wherein The data storage method further includes a data reading process, and the data reading process includes: Step B1, obtain a read start address in the volatile data storage area according to an external read request; Step B2, determine whether the remaining address length starting from the read start address in the volatile data storage area is greater than the length of the data to be read: If not, return a data reading result where the current stored data is all zeros, and then return to step B1; If so, proceed to step B3; Step B3, determine whether the current stored data that is not all 0xFF is queried within the remaining address length: If so, return the queried current stored data as the data reading result, and then return to step B1; If not, return a data reading result where the current stored data is all zeros, and then return to step B1.

5. The data storage method according to claim 4, characterized in that, The read request includes a read data length; then step B3 includes: Step B31, determine whether the current stored data of the read data length starting from the read start address is all 0: If so, use the next address of the end address of the current stored data as the read start address, and then return to step B31; If not, proceed to step B32; Step B32, determine whether the current stored data is all 0xFF: If so, return a data reading result where the current stored data is all zeros, and then return to step B1; If not, return the current stored data as the data reading result, and then return to step B1.

6. The data storage method according to claim 5, characterized in that In step B2, when the remaining address length is not greater than the length of the data to be read, it further includes subtracting the length of the data to be read from the read start address to obtain a data address and recording it as the read start traversal address; In the step B31, when the current stored data of the read data length starting from the read start address is not all 0, it further includes using the read start address as the read start traversal address; Then in the step B1, the process of obtaining the read start address includes: Judging whether the read start traversal address is queried: If so, starting from the read start traversal address, traverse the volatile data storage area to use the first non-0 data address as the read start address; If not, starting from the area start address of the volatile data storage area, traverse the volatile data storage area to use the first non-0 data address as the read start address.

7. A data storage system applied to a flash memory, characterized in that Applying the data storage method according to any one of claims 1-6, the data storage system includes: A data writing module connected to a volatile data storage area of a flash memory, and the data writing module includes: A first judgment unit for obtaining a data to be written and the storage start address of the current stored data in the volatile data storage area, and outputting an erase signal when judging that the writable space in the volatile data storage area is not sufficient to store the data to be written according to the write data length of the data to be written and the storage start address, and outputting a write signal when the writable space is sufficient to store the data to be written; An erase-then-write unit connected to the first judgment unit, for performing an overall erase on the volatile data storage area according to the erase signal, and then starting from the area start address of the volatile data storage area to write the data to be written as the current stored data; A second judgment unit connected to the first judgment unit, for reading a read data of the write data length starting from the storage start address according to the write signal, and when judging that the data to be written can be written starting from the storage start address according to the read data and the data to be written, writing the data to be written starting from the storage start address as the current stored data, And when it is not possible to write the data to be written starting from the storage start address, writing all 0 data with the write data length starting from the storage start address, and using the next address of the end address of the all 0 data as the storage start address.

8. The data storage system according to claim 7, wherein The second judgment unit includes: A first judgment subunit for outputting a first signal when judging that the data to be written is all 0 data, and outputting a second signal when judging that the data to be written is not all 0; A second judgment subunit connected to the first judgment subunit, for not performing a write operation and using the read data as the current stored data when judging that the read data is all 0xFF according to the first signal, and writing the data to be written starting from the storage start address as the current stored data when judging that the read data is not all 0xFF; The third judgment sub-unit, connected to the first judgment sub-unit, is configured to, when judging that the result of the bitwise AND of the data to be written and the read data is equal to the data to be written according to the second signal, write the data to be written starting from the storage start address as the current storage data. And when judging that the result is not equal to the data to be written, write all-0 data with the length of the written data starting from the storage start address, and use the next address of the end address of the all-0 data as the storage start address.

9. The data storage system according to claim 7, wherein It further includes a data reading module, connected to the volatile data storage area, and the data reading module includes: An address acquisition unit, configured to acquire a read start address in the volatile data storage area according to an external read request. A third judgment unit, connected to the address acquisition unit, is configured to return a data reading result that the current storage data is all zeros when judging that the remaining address length starting from the read start address in the volatile data storage area is not greater than the read data length, and output a third signal when the remaining address length is greater than the read data length. A fourth judgment unit, connected to the third judgment unit, is configured to return the queried current storage data as the data reading result when judging that the current storage data that is not all 0xFF can be queried within the remaining address length according to the third signal, and return a data reading result that the current storage data is all zeros when the current storage data that is not all 0xFF cannot be queried.

Citation Information

Patent Citations

  • Method for erasing and writing data of FLASH memory

    CN102306125A

  • Data storing method and embedded system

    CN105988722A

  • Flash memory process difference-based data layout method

    CN107368262A

  • Data storage method for serial flash memory

    CN110427161A