A method and device for implementing data writing
By dividing the FLASH chip into a write area and a backup area, and switching pages after successful writing, the problem of short chip service life caused by frequent erasing and writing is solved, and flexible and safe data writing is achieved and the chip life is extended. Effect.
Patent Information
- Application Number
- CN202410741944.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-11
- Publication Date
- 2024-08-27
- Estimated Expiration
- 2044-06-11
AI Technical Summary
In the existing technology, the FLASH chip has a short service life when it is frequently erased and written, especially in applications with small data files that require multiple erases and writes, resulting in poor chip performance and inability to write data flexibly and safely.
Divide the FLASH chip into a write area and a backup area, divide it into the same number of write pages and backup pages according to the space management configuration table, and use the backup page as a new write page after the write is successful, and erase the full page The old data page is used as a new backup page to extend the service life of the chip and rewrite other free memory cells when writing is abnormal.
Without increasing FLASH space requirements, the service life of the chip is extended, flexible and safe data writing is achieved, and writing reliability is improved.
Smart Images

Figure CN118331506B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information security, and in particular to a method and device for implementing data writing. Background Art
[0002] In the current chip industry, FLASH chips have been widely promoted and applied in low-cost, fast-paced practical applications. Limited by the manufacturing process, the erase and write life of the FLASH chip itself is generally 100,000 times. However, in some application files, such as wallet files of bus cards, gas usage files of gas meters and other small data files, due to frequent updates, the erase and write life of the FLASH chip is required to be more than 1 million times, and multiple erases will affect the service life of the chip. Each update of the file requires erasing the entire page of FLASH, which is inflexible to use and has relatively poor performance. Therefore, how to write data flexibly and safely and be able to erase and write multiple times is a problem that needs to be solved in the prior art. Summary of the invention
[0003] The purpose of the present invention is to overcome the deficiencies of the prior art and to provide a method and device for implementing data writing.
[0004] In a first aspect, an embodiment of the present invention provides a method for implementing data writing, including:
[0005] Step S1: When receiving a write instruction from the host computer, determine whether the FLASH chip is writing data for the first time, if yes, execute step S2, otherwise execute step S3;
[0006] Step S2: Divide the FLASH chip into two data areas and initialize them, divide the two data areas into corresponding numbers of data pages according to the number of data lengths in the space management configuration table, divide the two data pages corresponding to the serial number of the storage position of the data length into storage units with the same capacity according to each data length, and execute step S3;
[0007] Step S3: acquiring two corresponding data pages according to the serial number in the write instruction, and determining whether the acquired two data pages are in the initial state, if yes, executing step S4, otherwise executing step S6;
[0008] Step S4: taking the data page with a smaller physical address as a write page, taking another data page as a backup page, taking the first storage unit in the write page as the current storage unit, and executing step S5;
[0009] Step S5: Start writing the data to be written and the serial number into the current storage unit and determine whether the writing is successful. If yes, set the current storage unit to be valid and the writing is finished. Otherwise, set the current storage unit to be invalid and the writing is finished.
[0010] Step S6: Determine whether the data page where the valid storage unit is located is full. If yes, set a to-be-erased mark on the data page where the valid storage unit is located, use another data page as a write page, and use the first free storage unit in the write page as the current storage unit, and execute step S7; otherwise, use the data page where the valid storage unit is located as a write page, use another data page as a backup page, and use the first free storage unit in the write page as the current storage unit, and execute step S7;
[0011] Step S7: Start writing the data to be written and the serial number into the current storage unit and determine whether the writing is successful. If yes, set the current storage unit to be valid, set the valid storage unit with a smaller serial number to be invalid, and execute step S8. Otherwise, set the current storage unit to be invalid, and execute step S8.
[0012] Step S8: Determine whether there is a data page with a to-be-erased mark set. If yes, erase the data page with the to-be-erased mark set and use it as a backup page, and this writing is completed. Otherwise, this writing is completed.
[0013] In a second aspect, an embodiment of the present invention provides a data writing implementation device, including:
[0014] The receiving and judging module determines whether the FLASH chip is writing data for the first time when receiving the writing instruction sent by the host computer. If yes, the obtaining and judging module is triggered, otherwise, the splitting module is triggered;
[0015] The splitting module is used to divide the FLASH chip into two data areas and initialize them, divide the two data areas into a corresponding number of data pages according to the number of data lengths in the space management configuration table, and divide the two data pages corresponding to the sequence number of the storage position of the data length into storage units with the same capacity according to each data length, and trigger the acquisition judgment module;
[0016] The acquisition judgment module is used to acquire the corresponding two data pages according to the sequence number in the write instruction, and judge whether the acquired two data pages are in the initial state, and if so, trigger the first action module, otherwise, trigger the first judgment setting module;
[0017] The first as module is used to use a data page with a smaller physical address as a write page, another data page as a backup page, and the first storage unit in the write page as a current storage unit to trigger a first write judgment setting module;
[0018] The first write judgment setting module is used to start writing the data to be written and the serial number into the current storage unit and judge whether the writing is successful. If yes, the current storage unit is set to be valid and the writing is finished. Otherwise, the current storage unit is set to be invalid and the writing is finished.
[0019] The first judgment setting module is used to judge whether the data page where the valid storage unit is located is full, if yes, set the data page where the valid storage unit is located to be erased, use another data page as a write page, use the first free storage unit in the write page as the current storage unit, and trigger the second write judgment setting module; otherwise, use the data page where the valid storage unit is located as a write page, use another data page as a backup page, use the first free storage unit in the write page as the current storage unit, and trigger the second write judgment setting module;
[0020] The second writing judgment setting module is used to start writing the data to be written and the serial number into the current storage unit and judge whether the writing is successful. If yes, the current storage unit is set to be valid, and the valid storage unit with a smaller serial number is set to be invalid, triggering the second judgment setting module; otherwise, the current storage unit is set to be invalid, triggering the second judgment setting module;
[0021] The second determination setting module is used to determine whether there is a data page with a to-be-erased mark set, if yes, erase the data page with the to-be-erased mark set and use it as a backup page, and the current writing is terminated, otherwise the current writing is terminated.
[0022] In a third aspect, an embodiment of the present invention further provides an electronic device, comprising at least one processor, a memory, and instructions stored in the memory and executable by the at least one processor, wherein the at least one processor executes the instructions to implement the aforementioned data writing implementation method.
[0023] In a fourth aspect, an embodiment of the present invention further provides a computer-readable storage medium, wherein the computer-readable storage medium includes a computer program. When the computer program is executed on an electronic device, the electronic device executes the aforementioned data writing implementation method.
[0024] In a fifth aspect, an embodiment of the present invention further provides a chip system, including a chip, wherein the chip is coupled to a memory and is used to execute a computer program stored in the memory to execute the aforementioned data writing implementation method.
[0025] Compared with the prior art, the present invention has the following advantages: in the technical solution of the present invention, the FLASH chip is divided into a write area and a backup area, and the write area and the backup area are divided into the same number of write pages and backup pages according to the number of data lengths in the space management configuration table, and then the write pages and backup pages corresponding to the serial numbers of the storage positions of the data lengths are divided into a plurality of storage units with the same capacity according to the data lengths, and a piece of data only needs to be written into one storage unit, and only when the entire write page is full will the backup page be written next time, and after the writing is successful, the backup page will be used as a new write page, and the old data page that is full can be erased as a new backup page, and data can be written multiple times after erasing once, thereby extending the service life of the chip without increasing the FLASH space requirement; if an exception occurs when writing data and the writing fails, it can be rewritten into other idle storage units, and data can be written flexibly and safely. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 A flow chart of a method for implementing data writing provided in Embodiment 1 of the present invention;
[0027] Figure 2 and Figure 3 A flow chart of a method for implementing data writing provided in Embodiment 2 of the present invention;
[0028] Figure 4 This is a block diagram of a data writing implementation device provided in Embodiment 3 of the present invention. DETAILED DESCRIPTION
[0029] The present application proposes a method and device for implementing data writing. The specific implementation methods of the present application are described in detail below in conjunction with the accompanying drawings. Examples of the embodiments are shown in the accompanying drawings. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present application, and cannot be interpreted as limiting the present application.
[0030] It will be understood by those skilled in the art that, unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as generally understood by those skilled in the art to which this application belongs. It should also be understood that terms such as those defined in common dictionaries should be understood to have meanings consistent with the meanings in the context of the prior art, and will not be interpreted with idealized or overly formal meanings unless specifically defined as here.
[0031] In order to make the objectives, technical solutions and advantages of the present invention more clear, the embodiments of the present invention are further described in detail below with reference to the accompanying drawings.
[0032] Embodiment 1
[0033] Embodiment 1 of the present invention provides a method for implementing data writing, such as Figure 1 As shown, including:
[0034] Step S1: When receiving a write instruction from the host computer, determine whether the FLASH chip is writing data for the first time, if yes, execute step S2, otherwise execute step S3;
[0035] In this embodiment, the step before step S1 also includes: after the FLASH chip is powered on, determining whether the FLASH chip has completed the initialization of the space structure, if yes, waiting to receive the instruction sent by the host computer, otherwise initializing the space management configuration table in the FLASH chip, marking that the initialization of the space structure has been completed, and waiting to receive the instruction sent by the host computer;
[0036] When receiving the read space configuration instruction, the space management configuration table is returned to the host computer;
[0037] Optionally, marking that the initialization of the spatial structure has been completed includes: setting an initialization completion mark;
[0038] Accordingly, judging whether the FLASH chip has completed the initialization of the space structure includes: judging whether an initialization completion flag is set, if yes, the initialization of the space structure is completed, otherwise, the initialization of the space structure is not completed;
[0039] Step S2: Divide the FLASH chip into two data areas and initialize them, divide the two data areas into corresponding numbers of data pages according to the number of data lengths in the space management configuration table, divide the two data pages corresponding to the serial number of the storage position of the data length into storage units with the same capacity according to each data length, and execute step S3;
[0040] In this embodiment, the data length is stored in the space management configuration table, and the storage position in the space management configuration table is recorded as a sequence number, which corresponds one-to-one with the sequence number of the data page;
[0041] Optionally, in this embodiment, dividing the FLASH chip into two data areas includes: dividing the rest of the FLASH chip except the space management configuration table into two data areas;
[0042] Step S3: Obtain the corresponding two data pages according to the serial number in the write instruction, and determine whether the two acquired data pages are in the initial state. If yes, execute step S4; otherwise, execute step S6;
[0043] Step S4: Use the data page with a smaller physical address as the write page, use another data page as the backup page, use the first storage unit in the write page as the current storage unit, and execute step S5;
[0044] Step S5: Start writing the data to be written and the serial number into the current storage unit and determine whether the writing is successful. If yes, set the current storage unit to be valid and the writing is finished. Otherwise, set the current storage unit to be invalid and the writing is finished.
[0045] Step S6: Determine whether the data page where the valid storage unit is located is full. If yes, set the data page where the valid storage unit is located to be erased, use another data page as the write page, and use the first free storage unit in the write page as the current storage unit, and execute step S7; otherwise, use the data page where the valid storage unit is located as the write page, use another data page as the backup page, and use the first free storage unit in the write page as the current storage unit, and execute step S7;
[0046] Step S7: Start writing the data to be written and the serial number into the current storage unit and determine whether the writing is successful. If yes, set the current storage unit to be valid, set the valid storage unit with a smaller serial number to be invalid, and execute step S8. Otherwise, set the current storage unit to be invalid, and execute step S8.
[0047] In this embodiment, if an abnormal situation such as power failure occurs between setting the current storage unit to be valid and setting the valid storage unit with a smaller serial number to be invalid, there are two valid storage units in the data page;
[0048] Optionally, before starting to write the data to be written and the serial number into the current storage unit in step S7, the step further includes: setting a write start flag in the current storage unit to be valid; for example, setting the write start flag to 55;
[0049] Accordingly, judging whether the data page where the valid storage unit is located is full includes: judging whether the write start flag in each storage unit in the data page is valid, if so, the data page is full, otherwise, the data page is not full;
[0050] In this embodiment, setting the current storage unit to be valid specifically includes: setting the write completion flag in the current storage unit to a first value;
[0051] Setting the current storage unit to be invalid specifically includes: setting the write completion flag in the current storage unit to a second value;
[0052] For example, the first value is AA and the second value is 00;
[0053] Step S8: Determine whether there is a data page with a to-be-erased mark set. If yes, erase the data page with the to-be-erased mark set and use it as a backup page, and this writing is completed. Otherwise, this writing is completed.
[0054] Optionally, in this embodiment, before step S6, the following steps are included:
[0055] Step A1: Determine the total number of valid storage cells in the two acquired data pages, if it is 1, execute step S6, if it is 2, execute step A2, if it is 0, execute step A5;
[0056] In this embodiment, if the storage unit to which data is successfully written is set to be valid and the previous valid storage unit is set to be invalid, there is only one valid storage unit in the data page; if an abnormal situation such as power failure occurs between setting the storage unit to which data is successfully written to be valid and setting the previous valid storage unit to be invalid, there are two valid storage units in the data page; if the data is not successfully written at the beginning, there is no valid storage unit in the data page;
[0057] Step A2: Determine whether the two valid storage units are in the same data page, if yes, execute step A3, otherwise execute step A4;
[0058] Step A3: set the valid storage unit with the smaller serial number to be invalid, use the data page where the two valid storage units are located as the write page, and the other data page as the backup page, use the first free storage unit in the write page as the current storage unit, and execute step S7;
[0059] Specifically, step A3 in this embodiment includes:
[0060] Step A31: Set the valid storage unit with the smaller serial number as invalid, and determine whether the data page where the two valid storage units are located is full. If yes, execute step A32; otherwise, execute step A33;
[0061] Optionally, determining whether the data page where the two valid storage units are located is full includes: determining whether the write enable flag in each storage unit in the data page is valid, if so, the data page is full, otherwise, the data page is not full;
[0062] Step A32: setting a to-be-erased mark on the data page where the two valid storage units are located, taking the other data page as a write page, taking the first free storage unit in the write page as a current storage unit, and executing step S7;
[0063] Step A33: Use the data page where the two valid storage units are located as a write page, use the other data page as a backup page, use the first free storage unit in the write page as the current storage unit, and execute step S7.
[0064] Step A4: setting a to-be-erased mark on the data page where the storage unit with a smaller serial number is located, taking the data page where the storage unit with a larger serial number is located as the write page, taking the first free storage unit in the write page as the current storage unit, and executing step S7;
[0065] Specifically, step A4 in this embodiment includes:
[0066] Step A41: Erase the data page where the valid storage unit with a smaller serial number is located, and determine whether the data page where the valid storage unit with a larger serial number is located is full. If yes, execute step A42; otherwise, execute step A43;
[0067] Optionally, judging whether the data page where the valid storage unit with a larger serial number is located is full includes: judging whether the write start flag in each storage unit in the data page is valid, if so, the data page is full, otherwise, the data page is not full;
[0068] Step A42: setting a to-be-erased mark on the data page where the valid storage unit with a larger serial number is located, taking the data page where the erased valid storage unit with a smaller serial number is located as the write page, taking the first free storage unit in the write page as the current storage unit, and executing step S7;
[0069] Step A43: the data page where the storage unit with a larger serial number is located is used as the write page, the data page where the erased valid storage unit with a smaller serial number is located is used as the backup page, the first free storage unit in the write page is used as the current storage unit, and step S7 is executed;
[0070] Step A5: Determine whether there is an idle storage unit in the data page with a smaller physical address, if yes, execute step A6, otherwise execute step A7;
[0071] That is, in the embodiment, the data page with a smaller physical address is the write page by default, and the data page with a larger physical address is the backup page. In step A5, it is determined whether there is an idle storage unit in the default write page;
[0072] If the data writing operation has been started in all storage units in the default data page but has not been successfully written, the judgment result of step A5 is no;
[0073] Step A6: Use the data page with a smaller physical address as the write page, another data page as the backup page, and the first free storage unit in the write page as the current storage unit, and execute step S7;
[0074] Step A7: Use the data page with a larger physical address as the write page, set another data page as an erase mark, use the first free storage unit in the write page as the current storage unit, and execute step S7.
[0075] In the technical solution of the present invention in the method of this embodiment, the FLASH chip is divided into a write area and a backup area. According to the number of data lengths in the space management configuration table, the write area and the backup area are divided into the same number of write pages and backup pages. Then, according to the data length, the write pages and backup pages corresponding to the serial number of the storage position of the data length are divided into multiple storage units with the same capacity. A piece of data only needs to be written into one storage unit. Only when the entire write page is full will the backup page be written next time. After the write is successful, the backup page will be used as a new write page. The old data page that is full will be erased as a new backup page. Data can be written multiple times after erasing once. Under the premise of not increasing the FLASH space demand, the service life of the chip is extended. If an exception occurs when writing data and the writing fails, the data can be rewritten into other free storage units again, so that data can be written flexibly and safely.
[0076] Embodiment 2
[0077] Embodiment 2 of the present invention provides a method for implementing data writing, such as Figure 2 and Figure 3 As shown, including:
[0078] Step 200: Power on the FLASH chip and determine whether the FLASH chip has completed the initialization of the space structure. If yes, wait to receive the instruction sent by the host computer. Otherwise, initialize the space management configuration table in the FLASH chip, mark that the initialization of the space structure has been completed, and wait to receive the instruction sent by the host computer.
[0079] When receiving the read space configuration instruction sent by the host computer, the space management configuration table is returned to the host computer, and waits for receiving the instruction sent by the host computer;
[0080] Specifically, in this embodiment, marking that the initialization of the spatial structure has been completed includes: setting an initialization completion mark;
[0081] Accordingly, judging whether the FLASH chip has completed the initialization of the space structure includes: judging whether an initialization completion flag is set, if yes, the initialization of the space structure is completed, otherwise, the initialization of the space structure is not completed;
[0082] The space management configuration table in this embodiment stores the data length (i.e., the sum of the valid data length, the serial number length, the write start mark length, and the write completion mark length), and the storage location is recorded as a sequence number;
[0083] For example, in this embodiment, the FLASH page size is 0x200, the physical address of the space management configuration table is 0xFE00, and the initialized space management configuration table is shown in Table 1;
[0084] Table 1:
[0085]
[0086] Among them, the first 8 bytes of data (0X0A, 0X1A, 0X5A, 0X30, 0X40, 0X55, 0X60, 0X5A) are the data length (corresponding to 8 bytes, each byte of data represents the capacity of the storage unit in the data page corresponding to the serial number of the storage location of the byte data, and the serial numbers of the storage locations are 0, 1, 2, 3, 4, 5, 6, 7 respectively), and the last 4 bytes of data AAAA5555 are the initialization completion mark;
[0087] Optionally, in the present embodiment, step 200 may also be implemented in other ways, that is, step 200 is replaced by step 200': the FLASH chip is powered on, and waits for receiving instructions from the host computer. When receiving the configuration initialization instruction from the host computer, it is determined whether the FLASH chip has completed the initialization of the space structure. If so, it continues to wait for receiving the instruction from the host computer and returns a response to the host computer. Otherwise, the space management configuration table in the FLASH chip is initialized, and the initialization of the space structure is marked to be completed. The space management configuration table is returned to the host computer, and the instruction from the host computer is waited for;
[0088] Step 201: when receiving a write instruction from a host computer, determine whether the FLASH chip is writing data for the first time, if yes, execute step 202, otherwise execute step 203;
[0089] The write instruction in this embodiment includes the data to be written and the sequence number of the data page where the data to be written is to be written;
[0090] Step 202: Divide the rest of the FLASH chip except the space management configuration table into two data areas and initialize them. Divide the two data areas into corresponding numbers of data pages according to the number of data lengths in the space management configuration table. Divide the two data pages corresponding to the sequence number of the storage position of the data length into storage units with the same capacity according to each data length, and execute step 203;
[0091] In this embodiment, one of the two data areas is a write area and the other is a backup area. The data page in the write area is a write page, and the data page in the backup area is a backup page. The write page in the write area and the backup page in the backup area correspond to each other one by one, and the capacity of all storage units in the corresponding write page and backup page is the same. When the FLASH chip is powered on for the first time, the data area with a smaller physical address is the write area by default, and the other data area is the backup area.
[0092] The roles of the write page and the backup page in this embodiment are interchangeable, that is, when the write page is full, the backup page will be used as a new write page. After the write is successful, the old write page will be erased and used as a new backup page. Under normal circumstances, there is only one valid storage unit in the write page and the backup page.
[0093] For example, in this embodiment, the physical space size of the data area is 0x1000, the initial physical address of the write area is 0x8000, and the initial physical address of the backup area is 0x9000. According to the number of data lengths in Table 1, the two data areas are divided into 8 data pages (the serial numbers of the data pages are 0, 1, 2, 3, 4, 5, 6, and 7, respectively). The capacities of the storage units in the 8 data pages in each data area are 0X0A, 0X1A, 0X5A, 0X30, 0X40, 0X55, 0X60, and 0X5A, respectively. The storage unit structure includes: Data, serial number (a serial number used to identify data writing), write start mark, write completion mark, where the serial number length is fixed to 4 bytes, the write start mark length is fixed to 1 byte, the write completion mark length is fixed to 1 byte, and the length of valid data that can be written in the storage unit is variable; for example, the capacity of the storage unit structure in the data page with serial number 0 is 10 (0X0A) bytes, the capacity of the storage unit structure in the data page with serial number 1 is 26 (0X1A) bytes, and the capacity of the storage unit structure in the data page with serial number 7 is 90 (0X5A) bytes;
[0094] If the data page size is 512 bytes and the storage unit capacity is 16 bytes, there are 32 storage units in the data page, of which the length of valid data is 10 bytes, the length of the serial number is 4 bytes, the length of the write start mark is 1 byte, and the length of the write completion mark is 1 byte;
[0095] For example, the write page with sequence number 0 is shown in Table 2, and the backup page is shown in Table 3, the write page with sequence number 1 is shown in Table 4, and the backup page is shown in Table 5;
[0096] Table 2:
[0097]
[0098] Table 3:
[0099]
[0100] Table 4:
[0101]
[0102] Table 5:
[0103]
[0104] Step 203: Obtain the corresponding two data pages according to the sequence number in the write instruction, and determine whether the two acquired data pages are in the initial state. If yes, execute step 204; otherwise, execute step 206;
[0105] Optionally, determining whether the two acquired data pages are in an initial state is specifically: determining whether the data in the two acquired data pages are both FF, if yes, it is an initial state, otherwise it is not an initial state;
[0106] Step 204: Use the data page with a smaller physical address as a write page, another data page as a backup page, and the first storage unit in the write page as the current storage unit, and execute step 205;
[0107] For example, the current storage unit in step 204 is shown in Table 6;
[0108] Table 6:
[0109]
[0110] Step 205: Start writing the data to be written and the serial number in the write instruction into the current storage unit and determine whether the writing is successful. If yes, set the current storage unit to be valid and the writing is finished. Otherwise, set the current storage unit to be invalid and the writing is finished.
[0111] Optionally, setting the current storage unit to be valid specifically includes: setting the write completion flag in the current storage unit to AA; setting the current storage unit to be invalid specifically includes: setting the write completion flag in the current storage unit to 00;
[0112] In this embodiment, if the write completion mark in the storage unit is AA, it means that the storage unit is a valid storage unit, if the write completion mark is 00, it means that the storage unit is an invalid storage unit, that is, a non-free storage unit, and if the write completion mark is FF, it means that the storage unit is in the initial state, that is, the storage unit is a free storage unit;
[0113] Step 206: Determine the total number of valid storage units in the two acquired data pages, if it is 1, execute step 207, if it is 2, execute step 210, if it is 0, execute step 217;
[0114] Specifically, step 206 includes: determining the total number of write completion marks AA in the two acquired data pages, if it is 1, executing step 207, if it is 2, executing step 210, if it is 0, executing step 217;
[0115] Step 207: Determine whether the data page where the valid storage unit is located is full, if yes, execute step 208, otherwise execute step 209;
[0116] For example, in this embodiment, the data pages with valid storage units are shown in Table 7;
[0117] Table 7:
[0118]
[0119] Step 208: setting a to-be-erased mark on the data page where the valid storage unit is located, taking another data page as a write page, taking the first free storage unit in the write page as the current storage unit, and executing step 220;
[0120] For example, the write page in step 208 is shown in Table 8;
[0121] Table 8:
[0122]
[0123] Step 209: Use the data page with valid storage units as a write page, another data page as a backup page, and the first free storage unit in the write page as the current storage unit, and execute step 220;
[0124] Step 210: Determine whether the two valid storage units are in the same data page, if yes, execute step 211, otherwise execute step 214;
[0125] Step 211: Set the valid storage unit with the smaller serial number as invalid, and determine whether the data page where the two valid storage units are located is full. If yes, execute step 212; otherwise, execute step 213;
[0126] In this embodiment, determining whether the write page is full specifically includes: determining whether the write enable flag in each storage unit in the write page is valid, if so, the write page is full, otherwise, the write page is not full;
[0127] If the write start flags of all storage units in a data page are 55, it means that the data page is full;
[0128] Step 212: setting a to-be-erased mark on the data page where the two valid storage units are located, taking the other data page as a write page, taking the first free storage unit in the write page as a current storage unit, and executing step 220;
[0129] Step 213: the data page where the two valid storage units are located is used as a write page, the other data page is used as a backup page, the first free storage unit in the write page is used as a current storage unit, and step 220 is executed;
[0130] Step 214: Erase the data page where the valid storage unit with a smaller serial number is located, and determine whether the data page where the valid storage unit with a larger serial number is located is full. If yes, execute step 215; otherwise, execute step 216;
[0131] Step 215: set a to-be-erased mark on the data page where the valid storage unit with a larger serial number is located, use the erased data page where the valid storage unit with a smaller serial number is located as the write page, use the first free storage unit in the write page as the current storage unit, and execute step 220;
[0132] Step 216: the data page where the storage unit with a larger serial number is located is used as the write page, the data page where the erased valid storage unit with a smaller serial number is located is used as the backup page, the first free storage unit in the write page is used as the current storage unit, and step 220 is executed;
[0133] In this embodiment, if the valid data, serial number, write start flag and write completion flag in the storage unit are all FF, it indicates an idle storage unit;
[0134] Step 217: Determine whether there is an idle storage unit in the data page with a smaller physical address, if yes, execute step 218, otherwise execute step 219;
[0135] In the embodiment, the data page with a smaller default physical address is the write page, and the data page with a larger default physical address is the backup page, that is, in step 217, it is determined whether there is an idle storage unit in the default write page. If data writing operations have been performed in all storage units in the default data page but the writing has not been successful, the determination result in step 217 is no;
[0136] Step 218: Use the data page with a smaller physical address as the write page, use another data page as the backup page, use the first free storage unit in the write page as the current storage unit, and execute step 220;
[0137] Step 219: set a to-be-erased mark for the data page with a smaller physical address, use the data page with a larger physical address as a write page, use the first free storage unit in the write page as the current storage unit, and execute step 220;
[0138] Step 220: Set the write start flag in the current storage unit to be valid, and start writing the data to be written and the serial number in the write instruction into the current storage unit;
[0139] Optionally, setting the write enable flag in the current storage unit to be valid includes: setting the write enable flag in the current storage unit to 55;
[0140] For example, the current storage unit after step 220 is shown in Table 9;
[0141] Table 9:
[0142]
[0143] Step 221: determine whether the data to be written and the serial number are successfully written into the current storage unit. If yes, set the write completion flag of the current storage unit to be valid, set the write completion flag of the valid storage unit with a smaller serial number to be invalid, and execute step 222; otherwise, set the write completion flag of the current storage unit to be invalid, and execute step 222;
[0144] In this embodiment, setting the write completion flag of the current storage unit to be valid specifically includes: setting the write completion flag to AA, and setting the write completion flag of the current storage unit to be invalid specifically includes: setting the write completion flag to 00;
[0145] If an abnormal situation such as power failure occurs during the writing process, it is determined in step 221 that the data to be written is not successfully written into the current storage unit, that is, the write completion flag of the current storage unit is set to 00, but because the write start flag is 55 (that is, the storage unit has been written with data), it cannot be used as an idle storage unit next time;
[0146] For example, the business data is successfully written into the current storage unit, and the storage unit is shown in Table 10;
[0147] Table 10:
[0148]
[0149] In this embodiment, if an abnormal situation (such as power failure) occurs between setting the write completion flag of the current storage unit to be valid and setting the write completion flag of the storage unit with a smaller serial number to be invalid, there will be two valid storage units, and the storage unit with a smaller serial number and the current storage unit may be in two data pages or in the same data page;
[0150] After successful writing in step 221, there is only one valid record in the write page, that is, only one storage unit has a write completion mark of AA, and the write page is shown in Table 11;
[0151] Table 11:
[0152]
[0153] Step 222: determine whether there is a data page with a to-be-erased mark set, if yes, erase the data page with the to-be-erased mark set and use it as a backup page, and this writing is completed, otherwise this writing is completed;
[0154] Optionally, in an embodiment, if the chip needs to write data again without losing power, that is, when the write instruction from the host computer is received again, the judgment in step 222 is yes or no and the program will return to step 201. If the chip needs to continue writing data after losing power, the judgment in step 222 is yes or no and the program will return to step 200.
[0155] The method of this embodiment divides the FLASH chip into a write area and a backup area, and divides the write area and the backup area into the same number of write pages and backup pages according to the number of data lengths in the space management configuration table, and then divides the write pages and backup pages corresponding to the serial numbers storing the data lengths in the space management configuration table into multiple storage units with the same capacity according to the data length. A piece of data only needs to be written into one storage unit. Only when the entire write page is full will the backup page be written next time. After the write is successful, the backup page will be used as a new write page, and the old data page that is full will be erased as a new backup page. Data can be written multiple times after erasing once, thereby extending the service life of the chip without increasing the FLASH space requirement. If an exception occurs when writing data and the writing fails, the data can be rewritten into other free storage units again, so that data can be written flexibly and safely.
[0156] Embodiment 3
[0157] Embodiment 3 of the present invention provides a data writing implementation device, such as Figure 4 As shown, including:
[0158] The receiving judgment module is used to judge whether the FLASH chip is writing data for the first time when receiving the writing instruction sent by the host computer. If yes, it triggers the acquisition judgment module, otherwise it triggers the splitting module;
[0159] The splitting module is used to divide the FLASH chip into two data areas and initialize them. The two data areas are divided into a corresponding number of data pages according to the number of data lengths in the space management configuration table. The two data pages corresponding to the serial number of the storage position of the data length are divided into storage units with the same capacity according to each data length, and the acquisition judgment module is triggered.
[0160] Specifically, the splitting module is used to divide the FLASH chip into two data areas, including: a splitting module is used to divide the other parts of the FLASH chip except the space management configuration table into two data areas;
[0161] In this embodiment, the data length is stored in the space management configuration table, and the storage position in the space management configuration table is recorded as a sequence number, which corresponds one-to-one with the sequence number of the data page;
[0162] An acquisition judgment module, used for acquiring two corresponding data pages according to the sequence number in the write instruction, and judging whether the acquired two data pages are in the initial state, and if so, triggering the first action module, otherwise triggering the first judgment setting module;
[0163] The first module is used to use a data page with a smaller physical address as a write page, another data page as a backup page, and the first storage unit in the write page as a current storage unit to trigger a first write judgment setting module;
[0164] The first write judgment setting module is used to start writing the data to be written and the serial number into the current storage unit and judge whether the writing is successful. If yes, the current storage unit is set to be valid and the writing is finished. Otherwise, the current storage unit is set to be invalid and the writing is finished.
[0165] A first judgment setting module is used to judge whether the data page where the valid storage unit is located is full, if yes, the data page where the valid storage unit is located is set with a to-be-erased mark, another data page is used as a write page, the first free storage unit in the write page is used as a current storage unit, and the second write judgment setting module is triggered; otherwise, the data page where the valid storage unit is located is used as a write page, another data page is used as a backup page, the first free storage unit in the write page is used as a current storage unit, and the second write judgment setting module is triggered;
[0166] A second write judgment setting module, used to start writing the data to be written and the serial number into the current storage unit and judge whether the writing is successful. If yes, the current storage unit is set to be valid, and the valid storage unit with a smaller serial number is set to be invalid, triggering the second judgment setting module; otherwise, the current storage unit is set to be invalid, triggering the second judgment setting module;
[0167] The second determination setting module is used to determine whether there is a data page with a to-be-erased mark set, if yes, erase the data page with the to-be-erased mark set and use it as a backup page, and this writing is ended, otherwise this writing is ended.
[0168] Optionally, the device in this embodiment further includes:
[0169] The judgment initialization module is used to judge whether the FLASH chip has completed the initialization of the space structure after the FLASH chip is powered on. If yes, it waits to receive the instruction sent by the host computer; otherwise, it initializes the space management configuration table in the FLASH chip, marks that the initialization of the space structure has been completed, and waits to receive the instruction sent by the host computer;
[0170] Specifically, in this embodiment, marking that the initialization of the spatial structure has been completed includes: setting an initialization completion mark;
[0171] Correspondingly, the initialization module determines whether the FLASH chip has completed the initialization of the space structure, specifically: the initialization module determines whether the initialization completion mark is set, if yes, the initialization of the space structure is completed, otherwise the initialization of the space structure is not completed;
[0172] The device in this embodiment may further include: a receiving and returning module, configured to return the space management configuration table to the host computer when receiving the read space configuration instruction;
[0173] Optionally, the device in this embodiment further includes:
[0174] A first judgment module is used to judge the total number of valid storage units in the two acquired data pages when the acquisition judgment module judges to be no, and if it is 1, the first judgment setting module is triggered, if it is 2, the second judgment module is triggered, and if it is 9, the third judgment module is triggered;
[0175] A second judging module, used for judging whether two valid storage units are in the same data page, and triggering the first setting module if so, otherwise triggering the second setting module;
[0176] A first setting module is used to set the valid storage unit with a smaller serial number to be invalid, use the data page where the two valid storage units are located as a write page, another data page as a backup page, and use the first free storage unit in the write page as the current storage unit, triggering the second write judgment setting module;
[0177] Furthermore, the first setting module includes:
[0178] A judgment unit is set to set the valid storage unit with a smaller serial number to be invalid, and to judge whether the data page where the two valid storage units are located is full, and if so, the first setting is triggered as a unit, otherwise, the second setting is triggered as a unit;
[0179] The first setting is used as a unit, which is used to set a to-be-erased mark on the data page where the two valid storage units are located, use the other data page as a write page, use the first free storage unit in the write page as a current storage unit, and trigger the second write judgment setting module;
[0180] The second setting is used as a unit to use the data page where the two valid storage units are located as a write page, another data page as a backup page, and the first free storage unit in the write page as the current storage unit to trigger the second write judgment setting module.
[0181] The second setting module is used to set the data page where the storage unit with a smaller serial number is located to be erased, use the data page where the storage unit with a larger serial number is located as the write page, and use the first free storage unit in the write page as the current storage unit to trigger the second write judgment setting module.
[0182] Furthermore, the second setting module includes:
[0183] An erasure judgment unit, used for erasing a data page where a valid storage unit with a smaller serial number is located, and judging whether a data page where a valid storage unit with a larger serial number is located is full, and if so, triggering a third setting as a unit, otherwise triggering a fourth setting as a unit;
[0184] The third setting is used as a unit, which is used to set a to-be-erased mark on the data page where the valid storage unit with a larger serial number is located, and to use the data page where the erased valid storage unit with a smaller serial number is located as the write page, and to use the first free storage unit in the write page as the current storage unit, so as to trigger the second write judgment setting module;
[0185] The fourth setting is used as a unit, which is used to use the data page where the storage unit with a larger serial number is located as the write page, the data page where the erased valid storage unit with a smaller serial number is located as the backup page, and the first free storage unit in the write page as the current storage unit, triggering the second write judgment setting module;
[0186] A third judging module is used to judge whether there is an idle storage unit in the data page with a smaller physical address, and if so, trigger the third setting module, otherwise, trigger the fourth setting module;
[0187] That is, in the embodiment, the data page with a smaller physical address is a write page by default, and the data page with a larger physical address is a backup page, and the third judgment module is used to judge whether there is an idle storage unit in the default write page;
[0188] If the data writing operation has been started in all storage units in the default data page but has not been successfully written, the judgment result of the third judgment module is no;
[0189] A third setting module is used to use a data page with a smaller physical address as a write page, another data page as a backup page, and the first free storage unit in the write page as the current storage unit to trigger the second write judgment setting module;
[0190] The fourth setting module is used to use the data page with a larger physical address as the write page, set another data page as an erase mark, use the first free storage unit in the write page as the current storage unit, and trigger the second write judgment setting module.
[0191] Optionally, the second write judgment setting module in this embodiment is further used to set the write start flag in the current storage unit to be valid;
[0192] Correspondingly, the first judgment setting module is used to judge whether the data page where the valid storage unit is located is full, including: the first judgment setting module is specifically used to judge whether the write start mark in each storage unit in the data page where the valid storage unit is located is valid, if so, the data page where the valid storage unit is located is full, otherwise the data page where the valid storage unit is located is not full;
[0193] A judgment unit is set to judge whether the data page where the two valid storage units are located is full, including: the judgment unit is set to be specifically used to judge whether the write start mark in each storage unit in the data page where the two valid storage units are located is valid, if so, the data page where the two valid storage units are located is full, otherwise the data page where the two valid storage units are located is not full.
[0194] The erase judgment unit is used to judge whether the data page where the valid storage unit with a larger serial number is located is full. The erase judgment unit is specifically used to judge whether the write start mark in each storage unit in the data page where the valid storage unit with a larger serial number is located is valid. If so, the data page where the valid storage unit with a larger serial number is located is full, otherwise, the data page where the valid storage unit with a larger serial number is located is not full.
[0195] Optionally, in this embodiment, the first write judgment setting module and the second write judgment setting module set the current storage unit to be valid specifically as follows: the first write judgment setting module and the second write judgment setting module set the write completion mark in the current storage unit to a first value;
[0196] The first writing judgment setting module and the second writing judgment setting module set the current storage unit to be invalid specifically as follows: the first writing judgment setting module and the second writing judgment setting module set the writing completion mark in the current storage unit to a second value;
[0197] For example, the first value is AA, and the second value is 00.
[0198] Optionally, an embodiment of the present application further provides an electronic device, the electronic device comprising at least one processor, a memory, and instructions stored in the memory and executable by at least one processor, and at least one processor executes the instructions to implement a data writing implementation method in the above embodiment. When the electronic device is a chip system, it can be composed of a chip, or it can include a chip and other discrete devices, which is not specifically limited in the embodiment of the present application; the chip is coupled to the memory and is used to execute a computer program stored in the memory to execute a data writing implementation method disclosed in the above embodiment.
[0199] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using a software program, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer programs. When a computer program is loaded and executed on an electronic device, the process or function described in the embodiment of the present application is generated in whole or in part. The computer program can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a base station, electronic device, server or data center to another base station, electronic device, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode. The computer-readable storage medium can be any available medium that can be accessed by an electronic device or a data storage device such as a server or data center that contains one or more media that can be integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid state disk (SSD)), etc. In the embodiment of the present application, the electronic device may include the device described above.
[0200] Although the present application is described herein in conjunction with various embodiments, in the process of implementing the claimed application, those skilled in the art may understand and implement other variations of the disclosed embodiments by viewing the drawings, the disclosure, and the appended claims. In the claims, the word "comprising" does not exclude other components or steps, and "one" or "an" does not exclude multiple situations. A single processor or other unit may implement several functions listed in a claim. Certain measures are recorded in different dependent claims, but this does not mean that these measures cannot be combined to produce good results.
[0201] Although the present application has been described in conjunction with specific features and embodiments thereof, it is obvious that various modifications and combinations may be made thereto without departing from the spirit and scope of the present application. Accordingly, this specification and the drawings are merely exemplary illustrations of the present application as defined by the appended claims, and are deemed to have covered any and all modifications, variations, combinations or equivalents within the scope of the present application. Obviously, those skilled in the art may make various modifications and variations to the present application without departing from the spirit and scope of the present application. Thus, if these modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is also intended to include these modifications and variations.
Claims
1. A method for implementing data writing, It is characterized in that include: Step S1: When receiving a write instruction from the host computer, determine whether the FLASH chip is writing data for the first time, if yes, execute step S2, otherwise execute step S3; Step S2: Divide the FLASH chip into two data areas and initialize them, divide the two data areas into corresponding numbers of data pages according to the number of data lengths in the space management configuration table, divide the two data pages corresponding to the serial number of the storage position of the data length into storage units with the same capacity according to each data length, and execute step S3; Step S3: acquiring two corresponding data pages according to the serial number in the write instruction, and determining whether the acquired two data pages are in the initial state, if yes, executing step S4, otherwise executing step S6; Step S4: taking the data page with a smaller physical address as a write page, taking another data page as a backup page, taking the first storage unit in the write page as the current storage unit, and executing step S5; Step S5: Start writing the data to be written and the serial number into the current storage unit and determine whether the writing is successful. If yes, set the current storage unit to be valid and the writing is finished. Otherwise, set the current storage unit to be invalid and the writing is finished. Step S6: Determine whether the data page where the valid storage unit is located is full. If yes, set a to-be-erased mark on the data page where the valid storage unit is located, use another data page as a write page, and use the first free storage unit in the write page as the current storage unit, and execute step S7; otherwise, use the data page where the valid storage unit is located as a write page, use another data page as a backup page, and use the first free storage unit in the write page as the current storage unit, and execute step S7; Step S7: Start writing the data to be written and the serial number into the current storage unit and determine whether the writing is successful. If yes, set the current storage unit to be valid, set the valid storage unit with a smaller serial number to be invalid, and execute step S8. Otherwise, set the current storage unit to be invalid, and execute step S8. Step S8: Determine whether there is a data page with a to-be-erased mark set. If yes, erase the data page with the to-be-erased mark set and use it as a backup page, and this writing is completed. Otherwise, this writing is completed.
2. The data writing implementation method according to claim 1, It is characterized in that Before step S1, the following steps are also included: After the FLASH chip is powered on, determine whether the FLASH chip has completed the initialization of the space structure, if yes, wait to receive the instruction sent by the host computer, otherwise initialize the space management configuration table in the FLASH chip, mark that the initialization of the space structure has been completed, wait to receive the instruction sent by the host computer, and store the data length in the space management configuration table; When receiving the read space configuration instruction, returning the space management configuration table to the host computer; The dividing the FLASH chip into two data areas includes: dividing the other parts of the FLASH chip except the space management configuration table into two data areas.
3. The data writing implementation method as claimed in claim 2, It is characterized in that The marking that the initialization of the spatial structure has been completed includes: setting an initialization completion mark; The determining whether the FLASH chip has completed the initialization of the space structure includes: determining whether the initialization completion mark is set, if yes, the initialization of the space structure is completed, otherwise, the initialization of the space structure is not completed.
4. The data writing implementation method according to claim 1, It is characterized in that The step S6 includes: Step A1: Determine the total number of valid storage units in the two acquired data pages, if the total number is 1, execute step S6, if the total number is 2, execute step A2, if the total number is 0, execute step A5; Step A2: Determine whether the two valid storage units are in the same data page, if yes, execute step A3, otherwise execute step A4; Step A3: Set the valid storage unit with the smaller serial number as invalid, use the data page where the two valid storage units are located as the write page, and the other data page as the backup page, use the first free storage unit in the write page as the current storage unit, and execute step S7; Step A4: setting a to-be-erased mark on the data page where the storage unit with a smaller serial number is located, taking the data page where the storage unit with a larger serial number is located as a write page, taking the first free storage unit in the write page as the current storage unit, and executing step S7; Step A5: Determine whether there is an idle storage unit in the data page with a smaller physical address, if yes, execute step A6, otherwise execute step A7; Step A6: Use the data page with a smaller physical address as a write page, another data page as a backup page, use the first free storage unit in the write page as the current storage unit, and execute step S7; Step A7: Use the data page with a larger physical address as a write page, set another data page as an erase mark, use the first free storage unit in the write page as the current storage unit, and execute step S7.
5. The data writing implementation method as claimed in claim 4, It is characterized in that The step A3 comprises: Step A31: Set the valid storage unit with the smaller serial number as invalid, and determine whether the data page where the two valid storage units are located is full. If yes, execute step A32; otherwise, execute step A33; Step A32: setting a to-be-erased mark on the data page where the two valid storage units are located, taking the other data page as a write page, taking the first free storage unit in the write page as a current storage unit, and executing step S7; Step A33: Use the data page where the two valid storage units are located as a write page, use another data page as a backup page, use the first free storage unit in the write page as a current storage unit, and execute step S7.
6. The data writing implementation method as claimed in claim 4, It is characterized in that The step A4 comprises: Step A41: Erase the data page where the valid storage unit with a smaller serial number is located, and determine whether the data page where the valid storage unit with a larger serial number is located is full. If yes, execute step A42; otherwise, execute step A43; Step A42: setting a to-be-erased mark on the data page where the valid storage unit with a larger serial number is located, taking the erased data page where the valid storage unit with a smaller serial number is located as the write page, taking the first free storage unit in the write page as the current storage unit, and executing step S7; Step A43: Use the data page where the storage unit with a larger serial number is located as the write page, the data page where the erased valid storage unit with a smaller serial number is located as the backup page, use the first free storage unit in the write page as the current storage unit, and execute step S7.
7. The data writing implementation method according to claim 1, It is characterized in that Before starting to write the data to be written and the serial number into the current storage unit, the method further includes: setting the write start flag in the current storage unit to be valid; The determining whether the data page where the valid storage unit is located is full includes: determining whether the write start mark in each storage unit in the data page where the valid storage unit is located is valid, if so, the data page where the valid storage unit is located is full, otherwise, the data page where the valid storage unit is located is not full.
8. The data writing implementation method as claimed in claim 5, It is characterized in that Before starting to write the data to be written and the serial number into the current storage unit, the method further includes: setting the write start flag of the current storage unit to be valid; The determining whether the data page where the two valid storage units are located is full includes: determining whether the write start mark in each storage unit in the data page where the two valid storage units are located is valid, if so, the data page where the two valid storage units are located is full, otherwise, the data page where the two valid storage units are located is not full.
9. The data writing implementation method as claimed in claim 6, It is characterized in that Before starting to write the data to be written and the serial number into the current storage unit, the method further includes: setting the write start flag in the current storage unit to be valid; The determining whether the data page where the valid storage unit with a larger serial number is located is full includes: determining whether the write start mark in each storage unit in the data page where the valid storage unit with a larger serial number is located is valid, if so, the data page where the valid storage unit with a larger serial number is located is full, otherwise, the data page where the valid storage unit with a larger serial number is located is not full.
10. The data writing implementation method according to claim 1, It is characterized in that The step S5 of setting the current storage unit to be valid specifically includes: setting the write completion flag in the current storage unit to a first value; The setting of the current storage unit to be invalid specifically includes: setting the write completion mark in the current storage unit to the second value.
11. A data writing implementation device, It is characterized in that include: The receiving judgment module determines whether the FLASH chip is writing data for the first time when receiving the write instruction sent by the host computer. If yes, it triggers the acquisition judgment module, otherwise it triggers the splitting module; The splitting module is used to divide the FLASH chip into two data areas and initialize them, divide the two data areas into a corresponding number of data pages according to the number of data lengths in the space management configuration table, and divide the two data pages corresponding to the sequence number of the storage position of the data length into storage units with the same capacity according to each data length, and trigger the acquisition judgment module; The acquisition judgment module is used to acquire the corresponding two data pages according to the sequence number in the write instruction, and judge whether the acquired two data pages are in the initial state, and if so, trigger the first action module, otherwise, trigger the first judgment setting module; The first as module is used to use a data page with a smaller physical address as a write page, another data page as a backup page, and the first storage unit in the write page as a current storage unit to trigger a first write judgment setting module; The first write judgment setting module is used to start writing the data to be written and the serial number into the current storage unit and judge whether the writing is successful. If yes, the current storage unit is set to be valid and the writing is finished. Otherwise, the current storage unit is set to be invalid and the writing is finished. The first judgment setting module is used to judge whether the data page where the valid storage unit is located is full, if yes, set the data page where the valid storage unit is located to be erased, use another data page as a write page, use the first free storage unit in the write page as the current storage unit, and trigger the second write judgment setting module; otherwise, use the data page where the valid storage unit is located as a write page, use another data page as a backup page, use the first free storage unit in the write page as the current storage unit, and trigger the second write judgment setting module; The second writing judgment setting module is used to start writing the data to be written and the serial number into the current storage unit and judge whether the writing is successful. If yes, the current storage unit is set to be valid, and the valid storage unit with a smaller serial number is set to be invalid, triggering the second judgment setting module; otherwise, the current storage unit is set to be invalid, triggering the second judgment setting module; The second determination setting module is used to determine whether there is a data page with a to-be-erased mark set, if yes, erase the data page with the to-be-erased mark set and use it as a backup page, and the current writing is terminated, otherwise the current writing is terminated.
12. An electronic device, It is characterized in that The electronic device includes at least one processor, a memory, and instructions stored in the memory and executable by the at least one processor, and the at least one processor executes the instructions to implement the data writing method according to any one of claims 1 to 10.
13. A computer-readable storage medium, It is characterized in that The computer-readable storage medium includes a computer program, and when the computer program is executed on an electronic device, the electronic device executes the data writing implementation method according to any one of claims 1 to 10.
14. A chip system, It is characterized in that The invention comprises a chip, wherein the chip is coupled to a memory and is used to execute a computer program stored in the memory to execute the data writing implementation method according to any one of claims 1 to 10.
