A storage method based on flash storage device

By adopting a flash storage device-based storage method in a microcontroller, using index value acquisition and CRC verification, the problems of data prone to loss, errors and low efficiency in traditional sector reading and writing mechanisms are solved, and efficient and reliable data storage is achieved and prolong the life of the equipment.

CN118939202BActive Publication Date: 2024-12-31FUZHOU FUDA BEIDOU COMM TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411420253.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-10-12
Publication Date
2024-12-31
Estimated Expiration
2044-10-12

AI Technical Summary

Technical Problem

In microcontrollers, the traditional sector read and write mechanism leads to low data storage efficiency, easy loss and error, and frequent erasing operations shorten the service life of the equipment, especially in low-cost and small-capacity equipment.

Method used

Using the storage method based on flash storage device, the data index acquisition module, data reading module and data writing module work together to realize index value acquisition, rapid data positioning and cyclic writing, avoid unnecessary ergonomic operations , and ensure the integrity of the data through CRC verification.

Benefits of technology

It improves storage efficiency and reliability, extends the life of the device, reduces the risk of data loss and errors, and realizes balanced erasing and flexible data reading and writing mechanisms.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939202B_ABST
    Figure CN118939202B_ABST
Patent Text Reader

Abstract

The present invention belongs to the field of information technology, and particularly relates to a storage method based on a flash storage device, wherein the storage method is implemented based on the flash storage device, wherein the flash storage device includes: a data index acquisition module, used to acquire an index value and determine whether the index value is valid; a data writing module, connected to the data index acquisition module, used to write data according to the acquired index value, etc. The present invention significantly improves the performance and reliability of flash storage; through index optimization and empty packet checking, invalid operations are reduced and storage efficiency is improved; CRC check and automatic rollback mechanism ensure data accuracy; cyclic write strategy balances erasure and writing, and prolongs the life of the device; in addition, the present invention also shows a high degree of flexibility, can adapt to different storage requirements, provide a variety of read and write strategies, and meet a variety of application scenarios.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of information technology, and in particular relates to a storage method based on a flash storage device. Background Art

[0002] With the rapid development and popularization of Internet of Things technology, the demand for miniaturized, low-power, and low-cost devices is growing, especially in the field of single-chip microcomputers (MCUs). Such devices are widely used in smart homes, wearable devices, environmental monitoring, and other scenarios. However, in these low-cost, small-capacity MCU systems, data storage has become a problem that needs to be solved urgently.

[0003] The traditional data storage method in microcontrollers, especially on Flash storage media, usually adopts the sector read and write mechanism ( Figure 6 , 7 As shown in Figure 1), when reading data, this mechanism needs to locate a specific sector for reading operations; when writing data, due to the writing characteristics of Flash, the entire sector needs to be erased first, and then the data is written. This "erase first, write later" mode is not only inefficient, but also has significant defects:

[0004] 1. Limited number of sector erases: The number of erases of Flash storage media is limited. Frequent erase operations will accelerate the loss of storage media and shorten the service life of the device. This loss is particularly obvious in low-cost, small-capacity microcontroller applications, because the storage resources of the device are limited. Frequent erase operations will further limit the data storage capacity and reliability of the device.

[0005] 2. High risk of data loss and error: Since MCU devices often face power-on and power-off situations (such as battery exhaustion, system restart, etc.), if the device loses power during the data writing process, the sectors that have been erased but not yet written with new data will be in an uncertain state, which can easily lead to data loss or error. In addition, due to the complexity of the MCU system and the uncertainty of the external environment, data may also be disturbed during transmission and storage, further increasing the risk of data error;

[0006] 3. Low read and write efficiency: The traditional sector read and write mechanism is inefficient when processing a large number of small data blocks, because each write requires erasing the entire sector. Even if only one byte of data is modified, the entire sector needs to be erased and written. This not only increases the system response time, but also increases energy consumption and the burden on the equipment. Summary of the invention

[0007] 1. Technical issues to be resolved

[0008] In order to solve the problems that data in the data storage of the flash storage device is easy to be lost and erroneous, the read and write efficiency is low, and the storage capacity is unstable and reliable, the present invention provides a storage method based on the flash storage device.

[0009] (II) Technical solution

[0010] The present invention is implemented by the following technical solution: The present invention proposes a storage method based on a flash storage device, and the storage method is implemented based on a flash storage device, wherein the flash storage device includes:

[0011] The data index acquisition module is used to obtain the index value and determine whether the index value is valid;

[0012] A data writing module, connected to the data index acquisition module, is used to write data according to the acquired index value;

[0013] A data reading module, connected to the data index acquisition module, is used to read data according to the acquired index value;

[0014] The storage method comprises the following steps:

[0015] Index value acquisition process: The storage method first obtains the index value through the data index acquisition module, and then the data index acquisition module determines whether the index value is valid. After the determination is completed, the data reading process or the data writing process is entered;

[0016] During the data reading process, if the index value is valid, the data is directly read through the data reading module. If the index value is invalid, the default parameters of the flash storage device are initialized, and then the data is read through the data reading module.

[0017] During the data writing process, if the index value is valid, the data is directly written through the data writing module. If the index value is invalid, the data index acquisition module sets the index value to zero, and then writes the data through the data writing module.

[0018] The specific steps of the index value acquisition process are as follows:

[0019] S1 starts;

[0020] S2 sets p = 0, the data index acquisition module defines a variable p and initializes it to 0;

[0021] The S3 data index acquisition module reads 32 bytes of data from the pth sector;

[0022] S4 data index acquisition module obtains the index value b_index of the pth sector;

[0023] S5 data index acquisition module determines whether the index value b_index>0 is true, if yes, jump to S8, if no, jump to S6;

[0024] S6: The data index acquisition module determines whether p < n_size is true, if yes, jumps to S7, if no, jumps to S10; n_size is the number of sectors that can be stored in the storage area of ​​the flash storage device;

[0025] S7 sets p=p+1, the data index acquisition module iteration variable p increases by +1 to form a new p value, and jumps to S3;

[0026] S8: The data index acquisition module acquires the data of the index value b_index of the pth sector;

[0027] S9 index value Index = p×b_size + b_index, the data index acquisition module calculates the index value, and jumps to S11 after obtaining the index value Index, where b_size is the number of data packets that can be stored in a sector of the flash storage device;

[0028] S10 data index acquisition module sets Index = -1;

[0029] S11 ends;

[0030] The specific steps of the data reading process are as follows:

[0031] a. start;

[0032] b. The data reading module determines whether the index value Index>0 is true, if so, jump to step c, if not, jump to step g;

[0033] c. Reading sector location data, the data reading module reads the sector location data where the index value Index is located;

[0034] d. The data reading module determines whether the sector position data check is valid, if yes, jump to step f, if not, jump to step e;

[0035] e. Index = Index - 1, the data reading module iterates Index and decreases it by -1 to form a new Index value, and jumps to step b;

[0036] f. The data reading module reads the sector location data;

[0037] g. The data reading module reads empty data;

[0038] The specific steps of the data writing process are as follows:

[0039] I) Start;

[0040] II) The data writing module determines whether Index > b_size×n_size is true, if yes, jump to step IV, if no, jump to step III;

[0041] III) Erase all sectors, set the index value Index = 1, the data index acquisition module erases all sectors of the flash storage device, the data writing module sets the index value Index = 1, and jumps to step VII;

[0042] IV) Reading p_size data, the data writing module reads the size of the flash storage device data packet, which is p_size data;

[0043] V) Are the values ​​of the data all 0xFF? If yes, jump to step VII; if no, jump to step VI;

[0044] VI) Index = Index+1, the data writing module iterates Index and increments by +1 to form a new Index value, and then jumps to step II;

[0045] VII) The data writing module writes the 32-byte content of the sector where the index is located according to the index;

[0046] VIII) The data writing module writes the content into the sector location specified by the Index in the flash storage device.

[0047] Preferably, in step d of the data reading process, the sector position data check is a cyclic redundancy check.

[0048] Preferably, in step c of the data reading process, the sector position data calculation formula is: (Index / b_size)×4096 + (Index%b_size)×p_size + 32, wherein p_size is the size of the flash storage device data packet, b_size is the number of data packets that can be stored in a sector of the flash storage device, and % is the C++ modulus operator symbol.

[0049] Preferably, in step V) of the data writing process, 0xFF is a hexadecimal number, and its decimal value is 255.

[0050] Preferably, the RAM resource of the flash storage device is 20-128kb, and the ROM space is 128kb.

[0051] Preferably, a sector area of ​​the flash storage device is 4096 bytes, wherein each bit of the first 32 bytes of each sector area is used to store an index position. When the index position is 1, the first bit position of the first byte of the 32 bytes is 0, and the other positions are 1. If all 32 bytes are 0 or are not continuously 1 after 0, then this sector has no data, so 32 bytes can represent 32×8-1 index value positions.

[0052] Preferably, each sector area has a data area after 32 bytes, wherein the format of the data area is a data packet with a length that is an integer multiple of 16 bytes.

[0053] (III) Beneficial effects:

[0054] 1. High efficiency:

[0055] Through the index value acquisition process, the valid data location can be quickly located, which reduces invalid read and write operations and improves storage efficiency;

[0056] During the data writing process, by checking whether the data packet content is empty, unnecessary erase and write operations are avoided, further improving storage efficiency.

[0057] 2. Reliability:

[0058] Use CRC check to verify the integrity and correctness of data, ensure that the read data is valid, and avoid storage problems caused by data errors;

[0059] During the data reading process, if a data error is detected, it can automatically roll back to the last valid data location, improving data reliability.

[0060] 3. Balanced erase and write:

[0061] The data writing process realizes the cyclic writing of data, avoiding the over-erasing of certain sectors in the flash storage device, thereby extending the life of the flash storage device;

[0062] By erasing all sectors and resetting index values, the overall data update is achieved, avoiding the problem of local data fragmentation.

[0063] 4. Flexibility:

[0064] The method of the present invention is applicable to flash storage devices of different sizes and configurations, and can adapt to different storage requirements by simply adjusting corresponding parameters;

[0065] It provides a flexible data reading and writing mechanism, and different reading and writing strategies can be selected according to actual conditions. BRIEF DESCRIPTION OF THE DRAWINGS

[0066] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:

[0067] Figure 1 It is a basic flow chart of the data reading process of the present invention;

[0068] Figure 2 It is a basic flow chart of the data writing process of the present invention;

[0069] Figure 3 A detailed flow chart of the index value acquisition process of the present invention;

[0070] Figure 4 is a detailed flow chart of the data reading process of the present invention;

[0071] Figure 5 A detailed flow chart of the data writing process of the present invention;

[0072] Figure 6 This is a diagram of the traditional sector read and write mechanism;

[0073] Figure 7 This is the traditional sector read and write flow chart. DETAILED DESCRIPTION

[0074] The present invention provides a storage method based on a flash storage device, wherein the storage method is implemented based on the flash storage device, wherein the flash storage device includes:

[0075] The data index acquisition module is used to obtain the index value and determine whether the index value is valid;

[0076] A data writing module, connected to the data index acquisition module, is used to write data according to the acquired index value;

[0077] A data reading module, connected to the data index acquisition module, is used to read data according to the acquired index value;

[0078] The storage method comprises the following steps (refer to Figure 1-2 shown):

[0079] Index value acquisition process: The storage method first obtains the index value through the data index acquisition module, and then the data index acquisition module determines whether the index value is valid. After the determination is completed, the data reading process or the data writing process is entered;

[0080] During the data reading process, if the index value is valid, the data is directly read through the data reading module. If the index value is invalid, the default parameters of the flash storage device are initialized, and then the data is read through the data reading module.

[0081] During the data writing process, if the index value is valid, the data is directly written through the data writing module. If the index value is invalid, the data index acquisition module sets the index value to zero, and then writes the data through the data writing module.

[0082] The specific steps of the index value acquisition process are as follows (refer to Figure 3 shown):

[0083] S1 starts;

[0084] S2 sets p = 0, the data index acquisition module defines a variable p and initializes it to 0;

[0085] The S3 data index acquisition module reads 32 bytes of data from the pth sector;

[0086] S4 data index acquisition module obtains the index value b_index of the pth sector;

[0087] S5 data index acquisition module determines whether the index value b_index>0 is true, if yes, jump to S8, if no, jump to S6;

[0088] S6: The data index acquisition module determines whether p < n_size is true, if yes, jumps to S7, if no, jumps to S10; n_size is the number of sectors that can be stored in the storage area of ​​the flash storage device;

[0089] S7 sets p=p+1, the data index acquisition module iteration variable p increases by +1 to form a new p value, and jumps to S3;

[0090] S8: The data index acquisition module acquires the data of the index value b_index of the pth sector;

[0091] S9 index value Index = p×b_size + b_index, the data index acquisition module calculates the index value, and jumps to S11 after obtaining the index value Index, where b_size is the number of data packets that can be stored in a sector of the flash storage device;

[0092] S10 data index acquisition module sets Index = -1;

[0093] S11 ends;

[0094] Compared with the traditional process, the advantage of this process for reading the position is that it is efficient and simple;

[0095] The specific steps of the data reading process are as follows (refer to Figure 4 shown):

[0096] a. Start;

[0097] b. The data reading module determines whether the index value Index>0 is true, if yes, jump to step c, if no, jump to step g;

[0098] c. Read sector location data: the data reading module reads the sector location data where the index value Index is located;

[0099] d. The data reading module determines whether the sector position data check is valid. If yes, jump to step f; if not, jump to step e;

[0100] e.Index=Index-1, the data reading module iterates Index and decrements it by -1 to form a new Index value, and jumps to step b;

[0101] f. The data reading module reads the sector location data;

[0102] g. The data reading module reads empty data;

[0103] Compared with the traditional process, the advantage of this process is that it can realize error correction of erroneous data and rollback of historical data.

[0104] The specific steps of the data writing process are as follows (refer to Figure 5 shown):

[0105] I) Start;

[0106] II) The data writing module determines whether Index > b_size×n_size is true, if so, jump to step IV, if not, jump to step III;

[0107] III) Erase all sectors, set the index value Index = 1, the data index acquisition module erases all sectors of the flash storage device, the data writing module sets the index value Index = 1, and jumps to step VII;

[0108] IV) Read p_size data. The data writing module reads the size of the flash storage device data packet, which is p_size data;

[0109] V) Are the values ​​of the data all 0xFF? If yes, jump to step VII; if no, jump to step VI;

[0110] VI) Index = Index + 1, the data writing module iterates Index and increments by + 1 to form a new Index value, and jumps to step II;

[0111] VII) The data writing module writes the 32-byte content of the sector where the index is located;

[0112] VIII) The data writing module writes the content into the sector location specified by the Index in the flash storage device;

[0113] Compared with the traditional process, the advantage of this process is that it can effectively achieve erase and write leveling.

[0114] The RAM resource of the flash storage device is 20-128kb, and the ROM space is 128kb;

[0115] In order to solve the problems that data in the data storage of a flash storage device is easy to be lost and erroneous, the read-write efficiency is low, and the storage capacity is unstable and reliable (caused by too many times of erasing and writing the flash storage), the present invention is mainly implemented based on a flash storage device. The flash storage device includes a data index acquisition module, a data reading module, and a data writing module. The index value acquisition process, the data reading process, and the data writing process are respectively implemented through these three modules. The three processes are mainly as follows: the index value acquisition process mainly provides a correct index value for the data reading and writing process; the data reading process reads the correct data from the flash storage device, and even if there is an error in the data, it can be rolled back to the correct data position; the data writing process stores the data in a specified position cyclically according to the data content to realize balanced erasing and writing of the data. The three modules and method processes complete the present invention, thereby realizing a storage method based on a flash storage device.

[0116] Among them, in step d of the data reading process, the sector position data check is a cyclic redundancy check, the polynomial formula is x16+x15+x2+1, and the initial value is 0; the cyclic redundancy check (CRC), specifically the CRC16 check, is a method for detecting whether an error occurs during data transmission or storage. The data is calculated by a specific polynomial formula and an initial value to obtain a check value. The check value is recalculated at the receiving end or when reading, and compared with the check value generated at the sending end or when storing. If they are inconsistent, it indicates that the data may be erroneous.

[0117] In step c of the data reading process, the sector position data calculation formula is: (Index / b_size)×4096 + (Index%b_size)×p_size + 32, wherein p_size is the size of the flash storage device data packet, b_size is the number of data packets that can be stored in a sector of the flash storage device, and % is the C++ modulo operator symbol.

[0118] In step V) of the data writing process, 0xFF is a hexadecimal number, and its decimal value is 255.

[0119] Wherein, a sector area of ​​the flash storage device is 4096 bytes, wherein each bit of the first 32 bytes of each sector area is used to store the index position, when the index position is 1, the first bit position of the first byte of the 32 bytes is 0, and the other positions are 1. If the 32 bytes are all 0 or are not continuously 1 after being 0, then the sector has no data, so 32 bytes can represent 32×8-1 index value positions; the above is a relatively traditional process, and this process can quickly locate the location of data storage;

[0120] 1. The data area after 32 bytes of each sector area, wherein the format of the data area is a data packet of integer multiple length of 16 bytes; through the above-mentioned comparative traditional process, the data format is stipulated so that it is easy to judge whether the data is correct or not, and the data can be rolled back after the data is wrong, wherein the specific format is as follows:

[0121] .

[0122] The core of the storage method based on the flash storage device proposed in the present invention is to realize efficient and reliable data storage through the coordinated work of the data index acquisition module, the data reading module and the data writing module. The following is a detailed analysis of its principle:

[0123] 1. Index value acquisition process:

[0124] By traversing the sectors in the flash storage device, reading the first 32 bytes of each sector (these bytes are used to store index values) to find a valid index value;

[0125] Use variable p to iterate through each sector until a valid index value is found (that is, the index value is greater than 0) or all sectors are traversed;

[0126] The index value Index is calculated, which is determined by the sector number p and the index value b_index within the sector, ensuring the accurate positioning of the data.

[0127] 2. Data reading process:

[0128] Calculate the specific location of the data in the flash storage device according to the index value Index, and read the data at that location.

[0129] Use cyclic redundancy check (CRC) to verify whether the read data is valid. If the check fails, decrement the index value Index and read again until valid data is found or the index value is invalid;

[0130] If the index value is invalid (that is, Index is less than or equal to 0), empty data is read, avoiding the risk of reading invalid data.

[0131] 3. Data writing process:

[0132] Before writing data, first check whether the index value Index exceeds the capacity of the flash storage device;

[0133] If the capacity is within the limit, data is written directly; if the capacity is exceeded, all sectors are erased and the index value is reset to 1, thereby realizing cyclic writing of data;

[0134] When writing data, first check whether the data packets to be written are all 0xFF (i.e., empty data packets). If so, skip the writing process to avoid unnecessary erase and write operations, thereby increasing the life of the flash storage device.

[0135] Summarize:

[0136] 1. High efficiency:

[0137] Through the index value acquisition process, the valid data location can be quickly located, which reduces invalid read and write operations and improves storage efficiency;

[0138] During the data writing process, by checking whether the data packet content is empty, unnecessary erase and write operations are avoided, further improving storage efficiency.

[0139] 2. Reliability:

[0140] Use CRC check to verify the integrity and correctness of data, ensure that the read data is valid, and avoid storage problems caused by data errors;

[0141] During the data reading process, if a data error is detected, it can automatically roll back to the last valid data location, improving data reliability.

[0142] 3. Balanced erase and write:

[0143] The data writing process realizes the cyclic writing of data, avoiding the over-erasing of certain sectors in the flash storage device, thereby extending the life of the flash storage device;

[0144] By erasing all sectors and resetting index values, the overall data update is achieved, avoiding the problem of local data fragmentation.

[0145] 4. Flexibility:

[0146] The method of the present invention is applicable to flash storage devices of different sizes and configurations, and can adapt to different storage requirements by simply adjusting corresponding parameters;

[0147] It provides a flexible data reading and writing mechanism, and different reading and writing strategies can be selected according to actual conditions.

[0148] In summary, the storage method based on the flash storage device proposed in the present invention performs well in terms of efficiency, reliability, balanced erasing and flexibility, and provides a new solution for data storage of the flash storage device.

[0149] Example 1: Storing a text file

[0150] background:

[0151] Assume that we need to store a small text file (such as "hello.txt") in a flash storage device; the text file content is "Hello, World!", and we know that the size of each packet (packet) p_size is 512 bytes, and each sector can store b_size 8 packets;

[0152] Index value acquisition process:

[0153] Initialize p=0;

[0154] Read 32 bytes of data from sector 0 and get the index value b_index;

[0155] Assume that the first valid index value is in the first sector, that is, b_index is 1 (indicating that the first data packet is in this sector);

[0156] Calculate the index value Index = p×b_size + b_index = 0×8 + 1 = 1;

[0157] Data writing process:

[0158] Verify that Index is within the range (Index <= b_size×n_size);

[0159] Check the contents of the data packet to be written (here is "Hello, World!" and its necessary padding and CRC check) to make sure that they are not all 0xFF.

[0160] Write the data packet to the location specified by the index value Index (i.e. the first data packet location of the first sector);

[0161] Update the sector index value (if necessary);

[0162] Data reading process:

[0163] Use index value Index=1 to read data;

[0164] Verify the CRC checksum of the data packet to ensure data integrity;

[0165] If the CRC check passes, the data "Hello, World!" is read successfully.

[0166] Example 2: Storing and updating large amounts of log data

[0167] background:

[0168] Assume that a system needs to frequently write log data to a flash storage device. The amount of data written each time is small but the frequency is high.

[0169] Index value acquisition process:

[0170] Similar to embodiment 1, but it may be necessary to traverse multiple sectors to find the latest valid index value;

[0171] Data writing process:

[0172] Frequently check if the Index is out of range;

[0173] If the Index is out of range, erase all sectors, reset Index=1, and start writing again;

[0174] Each time a new log data packet is written, the Index is incremented and the location of the data packet in the flash is calculated based on the Index;

[0175] After writing the data packet, update the index value of the corresponding sector;

[0176] Data reading process:

[0177] To read the latest log data, you can start reading from the current largest Index value;

[0178] If CRC check fails or data is corrupted, try to roll back to the last valid Index value;

[0179] Read and process all valid log packets.

[0180] Example 3: Storing and reading image files

[0181] background:

[0182] A JPEG image file needs to be stored in a flash storage device and can be read correctly when needed;

[0183] Index value acquisition process:

[0184] Since image files are usually large, they may need to span multiple sectors;

[0185] The index value acquisition process may need to traverse multiple sectors to find the sector containing the starting part of the image file;

[0186] Data writing process:

[0187] Split the image file into multiple data packets (the size of each data packet does not exceed p_size);

[0188] Write packets to the flash storage device one by one, incrementing the Index to track the location of each packet;

[0189] Update the index value of each sector containing the start of the data packet;

[0190] Data reading process:

[0191] Use the index value at the beginning of the image file to start reading;

[0192] Read each packet one by one and use CRC check to verify the integrity of each packet;

[0193] Reassemble all packets into a complete picture file.

[0194] Summarize

[0195] These embodiments demonstrate how to use the flash storage device-based storage method of the present invention in different application scenarios; through the coordinated work of index value acquisition, data writing and data reading processes, efficient and reliable data storage can be ensured, and problems such as data loss, errors and unstable storage capacity can be handled.

[0196] The above are only preferred embodiments of the present application, and are not intended to limit the present application in any form. Although the present application has been disclosed as above with preferred embodiments, it is not intended to limit the present application. Any technical personnel in the field can make some changes or modify the technical contents disclosed above into equivalent embodiments without departing from the scope of the technical solution of the present application. However, any brief modifications, equivalent changes and modifications made to the above embodiments based on the technical essence of the present application without departing from the content of the technical solution of the present application are still within the scope of the technical solution of the present application.

Claims

1. A storage method based on a flash storage device, wherein the storage method is implemented based on a flash storage device, and is characterized in that: Flash storage devices include: The data index acquisition module is used to obtain the index value and determine whether the index value is valid; A data writing module, connected to the data index acquisition module, is used to write data according to the acquired index value; A data reading module, connected to the data index acquisition module, is used to read data according to the acquired index value; The storage method comprises the following steps: Index value acquisition process: The storage method first obtains the index value through the data index acquisition module, and then the data index acquisition module determines whether the index value is valid. After the determination is completed, the data reading process or the data writing process is entered; During the data reading process, if the index value is valid, the data is directly read through the data reading module. If the index value is invalid, the default parameters of the flash storage device are initialized, and then the data is read through the data reading module. During the data writing process, if the index value is valid, the data is directly written through the data writing module. If the index value is invalid, the data index acquisition module sets the index value to zero, and then writes the data through the data writing module. The specific steps of the index value acquisition process are as follows: S1 starts; S2 sets p = 0, the data index acquisition module defines a variable p and initializes it to 0; The S3 data index acquisition module reads 32 bytes of data from the pth sector; S4 data index acquisition module obtains the index value b_index of the pth sector; S5 data index acquisition module determines whether the index value b_index>0 is true, if yes, jump to S8, if no, jump to S6; S6: The data index acquisition module determines whether p < n_size is true, if yes, jumps to S7, if no, jumps to S10; n_size is the number of sectors that can be stored in the storage area of ​​the flash storage device; S7 sets p=p+1, the data index acquisition module iteration variable p increases by +1 to form a new p value, and jumps to S3; S8: The data index acquisition module acquires the data of the index value b_index of the pth sector; S9 index value Index = p×b_size + b_index, the data index acquisition module calculates the index value, and jumps to S11 after obtaining the index value Index, where b_size is the number of data packets that can be stored in a sector of the flash storage device; S10 data index acquisition module sets Index = -1; S11 ends; The specific steps of the data reading process are as follows: a. Start; b. The data reading module determines whether the index value Index>0 is true, if yes, jump to step c, if no, jump to step g; c. Read sector location data: the data reading module reads the sector location data where the index value Index is located; d. The data reading module determines whether the sector position data check is valid. If yes, jump to step f; if not, jump to step e; e.Index=Index-1, the data reading module iterates Index and decrements it by -1 to form a new Index value, and jumps to step b; f. The data reading module reads the sector location data; g. The data reading module reads empty data; The specific steps of the data writing process are as follows: I) Start; II) The data writing module determines whether Index > b_size×n_size is true, if so, jump to step IV, if not, jump to step III; III) Erase all sectors, set the index value Index = 1, the data index acquisition module erases all sectors of the flash storage device, the data writing module sets the index value Index = 1, and jumps to step VII; IV) Read p_size data. The data writing module reads the size of the flash storage device data packet, which is p_size data; V) Are the values ​​of the data all 0xFF? If yes, jump to step VII; if no, jump to step VI; VI) Index = Index + 1, the data writing module iterates Index and increments by + 1 to form a new Index value, and jumps to step II; VII) The data writing module writes the 32-byte content of the sector where the index is located; VIII) The data writing module writes the content into the sector location specified by the Index in the flash storage device.

2. The storage method based on a flash storage device according to claim 1, characterized in that: In step d of the data reading process, the sector position data check is a cyclic redundancy check.

3. The storage method based on a flash storage device according to claim 1, characterized in that: In step c of the data reading process, the sector position data calculation formula is: (Index / b_size)×4096 + (Index%b_size)×p_size + 32, where p_size is the size of the flash storage device data packet, b_size is the number of data packets that can be stored in a sector of the flash storage device, and % is the C++ modulo operator symbol.

4. The storage method based on a flash storage device according to claim 1, characterized in that: In step V) of the data writing process, 0xFF is a hexadecimal number, and its decimal value is 255.

5. The storage method based on a flash storage device according to claim 1, characterized in that: The RAM resource of the flash storage device is 20-128kb, and the ROM space is 128kb.

6. The storage method based on a flash storage device according to claim 1, characterized in that: A sector area of ​​the flash storage device is 4096 bytes, wherein each bit of the first 32 bytes of each sector area is used to store an index position. When the index position is 1, the first bit position of the first byte of the 32 bytes is 0, and the other positions are 1. If all 32 bytes are 0 or are not continuously 1 after 0, then this sector has no data, so 32 bytes can represent 32×8-1 index value positions.

7. The storage method based on a flash storage device according to claim 6, characterized in that: The data area after 32 bytes of each sector area, wherein the format of the data area is a data packet with a length that is an integer multiple of 16 bytes.