An off-chip memory reading and writing method, device, and computer-readable storage medium
By dividing off-chip storage into basic rewritten units and finding units with stored data, the data read errors and shortened product life caused by frequent off-chip FLASH rewritten are solved, and an efficient fault-tolerant read and write solution is realized, extending the product service life.
Patent Information
- Application Number
- CN202411758094.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-12-03
- Publication Date
- 2025-06-20
- Estimated Expiration
- 2044-12-03
AI Technical Summary
In the prior art, off-chip FLASH is easily damaged when frequently rewritten, resulting in data reading errors and shortening of product service life. After the software is upgraded, data reading errors are caused from FLASH due to changes in the number of data structure members.
By dividing off-chip storage into a plurality of basic erase units, the start page of each unit is used for bad block identification and the remaining pages are used for data storage. The basic erase unit with stored data is searched, the header of the data block that was recently executed for data storage is retrieved, and the header address of the data block is determined in the basic erase unit that meets the read and write conditions is performed according to the header information.
A off-chip storage read and write solution with better fault tolerance performance is realized, effectively avoiding data read errors and FLASH damage caused by changes in the number of data structure members and frequent rewrittening, and extending the service life of the product.
Smart Images

Figure CN119248202B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data storage, and particularly to an off-chip storage reading and writing method, device, and computer-readable storage medium. Background Art
[0002] In the prior art, off-chip FLASH (flash memory, i.e., non-volatile memory) is relative to the FLASH built in the MCU (Micro Controller Unit). Generally, the nominal erasing and writing life of FLASH is greater than 100,000 times.
[0003] Generally, the FLASH built in the MCU has a small capacity and is mainly used to store program codes, and is not frequently erased and written. If it is frequently erased and written, it will cause damage to the on-chip FLASH, thus affecting the service life of the MCU.
[0004] In actual projects, a lot of data needs to be frequently written into the FLASH. Considering the above factors, it is obviously inappropriate to use the on-chip FLASH of the MCU. Therefore, many projects will match a suitable off-chip FLASH.
[0005] However, in the process of using off-chip FLASH, there are still three technical problems to be solved:
[0006] First, the data read from the FLASH is incorrect.
[0007] Second, after software upgrade, due to the change in the number of data structure members, the data read from the FLASH is incorrect.
[0008] Third, due to frequent erasing and writing of the FLASH, the FLASH is damaged, reducing the service life of the product. Summary of the Invention
[0009] In order to overcome the deficiencies in the prior art, the purpose of the present invention is to provide an off-chip storage reading and writing method, device, and computer-readable storage medium, which are used to solve the problems that the data read from the current FLASH is incorrect, the data read from the FLASH is incorrect after software upgrade due to the change in the number of data structure members, and the FLASH is damaged due to frequent erasing and writing of the FLASH, reducing the service life of the product.
[0010] The present invention provides an off-chip storage reading and writing method. The off-chip storage is divided into multiple basic erasing and writing units. The starting page of each basic erasing and writing unit is used for bad block identification, and the remaining pages are used for data storage. Among them, the data block for executing data storage includes a header and a data field. The method includes:
[0011] Search for the basic erasing and writing unit with stored data to retrieve the header of the data block that executed data storage most recently;
[0012] According to the header information of the header, in the basic erasable and programmable unit that meets the read condition, determine the starting address of the data field of the data block, and read the data according to the starting address;
[0013] Or,
[0014] According to the header information, in the basic erasable and programmable unit that meets the write condition, determine the starting address of the data block, and write the data according to the starting address.
[0015] Optionally, the searching for the basic erasable and programmable unit with stored data specifically includes:
[0016] Sequentially read the bad block identifiers of the basic erasable and programmable units, and calculate the starting address of the first page without bad blocks;
[0017] Read the byte data of the header according to the starting address, and determine whether the byte data is all reset values.
[0018] Optionally, the determining whether the byte data is all reset values further includes:
[0019] If the byte data is all reset values, determine that the current basic erasable and programmable unit is empty;
[0020] Jump to the next basic erasable and programmable unit to continue executing the operation of sequentially reading the bad block identifiers of the basic erasable and programmable units.
[0021] Optionally, the continuing to execute the operation of sequentially reading the bad block identifiers of the basic erasable and programmable units further includes:
[0022] If it is determined that all basic erasable and programmable units are empty, return to the first basic erasable and programmable unit;
[0023] Start writing a preset default value from the starting address of the first page without bad blocks of the first basic erasable and programmable unit, and perform a preset read-back verification operation;
[0024] If the read-back verification fails, mark the page currently involved as a page with bad blocks, and if the read-back verification passes, determine that the default value is successfully written and end this operation.
[0025] Optionally, the determining whether the byte data is all reset values further includes:
[0026] If the byte data is not all reset values, calculate the check value of the front segment bytes of the read header, and compare it with the check code of the back segment bytes pre-stored in the header;
[0027] If there is a match, determine that the data of the header is valid, read the header of the next data block according to the data of the header, and perform the header verification of the next data block;
[0028] If there is no match, determine that the data of the header is invalid, erase the current basic erase-write unit, and mark the page involved currently as a page with a bad block.
[0029] Optionally, the performing the header verification of the next data block further includes:
[0030] Determine whether the byte data of the header of the next data block is all reset values;
[0031] If the byte data is not all reset values, continue to execute the step of calculating the verification value of the previous segment of bytes of the read header and comparing it with the verification code of the latter segment of bytes pre-stored in the header;
[0032] If the byte data is all reset values, determine that the header of the data block with stored data for the last time has been retrieved.
[0033] Optionally, the if the verification fails, mark the page involved currently as a page with a bad block further includes:
[0034] Write the bad block information of the page with a bad block to the starting page of the current basic erase-write unit;
[0035] Transfer to the next basic erase-write unit, calculate the starting address of the first page without a bad block;
[0036] Start writing the default value from the starting address and perform the read-back verification operation;
[0037] If the read-back verification fails, erase the current basic erase-write unit, mark the page involved currently as a page with a bad block, and if the read-back verification passes, determine that the default value is written successfully and end this operation.
[0038] Optionally, the according to the header information of the header, determine the starting address of the data field of the data block in the basic erase-write unit that meets the read condition, and read the data according to the starting address further includes:
[0039] Calculate the verification code of the data field and compare it with the verification code of the data field pre-stored in the header;
[0040] If there is a match, determine that the data of the read data field is valid and end the read operation;
[0041] If there is no match, erase the current basic erase-write unit, mark the page involved currently as a page with a bad block.
[0042] Optionally, based on the header information, in a basic erase-write unit that meets the write condition, determining the starting address of a data block and writing data according to the starting address further includes:
[0043] Obtaining the starting address where the next data block is stored according to the header information, and combining the byte length of the next data block to determine whether the ending address of the next data block exceeds the ending address of the current basic erase-write unit;
[0044] If it exceeds, erasing the current basic erase-write unit, and writing the bad block information of the current basic erase-write unit to the starting page of the current basic erase-write unit; transferring to the next basic erase-write unit, and continuing to execute the step of determining the starting address of the data block in the basic erase-write unit that meets the write condition according to the header information of the header;
[0045] If it does not exceed, calculating the header information of the current header and updating the member values of the data field.
[0046] Optionally, after writing data according to the starting address, it further includes:
[0047] Reading back the data of the written data block and performing verification;
[0048] If the verification fails, marking the page currently involved as a page with a bad block, erasing the current basic erase-write unit, and writing the bad block information to the starting page of the current basic erase-write unit; transferring to the next basic erase-write unit, and continuing to execute the step of determining the starting address of the data block in the basic erase-write unit that meets the write condition according to the header information of the header;
[0049] If the verification passes, determining that the data of the written data block is valid and ending the write operation.
[0050] The present invention also provides an off-chip storage read-write device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, it implements the steps of the off-chip storage read-write method described in any one of the above.
[0051] The present invention also provides a computer-readable storage medium, on which an off-chip storage read-write program is stored. When the off-chip storage read-write program is executed by a processor, it implements the steps of the off-chip storage read-write method described in any one of the above.
[0052] Implementing the off-chip storage reading and writing method, device, and computer-readable storage medium of the present invention, by searching for the basic erasable and writable units with stored data to retrieve the head of the data block where the data storage was last executed; according to the header information of the head, in the basic erasable and writable units that meet the read condition, determine the starting address of the data field of the data block and read the data according to the starting address; or, according to the header information, in the basic erasable and writable units that meet the write condition, determine the starting address of the data block and write the data according to the starting address. An off-chip storage reading and writing scheme with better fault tolerance performance is realized, effectively avoiding data reading errors from the FLASH after software upgrade due to changes in the number of data structure members, or FLASH damage caused by frequent erasure and writing of the FLASH, and extending the service life of the product. BRIEF DESCRIPTION OF THE DRAWINGS
[0053] The present invention will be further described below in conjunction with the drawings and embodiments. In the drawings:
[0054] Figure 1 is the first flowchart of the off-chip storage reading and writing method of the present invention;
[0055] Figure 2 is the second flowchart of the off-chip storage reading and writing method of the present invention;
[0056] Figure 3 is the third flowchart of the off-chip storage reading and writing method of the present invention;
[0057] Figure 4 is the fourth flowchart of the off-chip storage reading and writing method of the present invention;
[0058] Figure 5 is the fifth flowchart of the off-chip storage reading and writing method of the present invention;
[0059] Figure 6 is the sixth flowchart of the off-chip storage reading and writing method of the present invention;
[0060] Figure 7 is the seventh flowchart of the off-chip storage reading and writing method of the present invention;
[0061] Figure 8 is the eighth flowchart of the off-chip storage reading and writing method of the present invention;
[0062] Figure 9 is the ninth flowchart of the off-chip storage reading and writing method of the present invention;
[0063] Figure 10 is the tenth flowchart of the off-chip storage reading and writing method of the present invention;
[0064] Figure 11 is the eleventh flowchart of the off-chip storage reading and writing method of the present invention;
[0065] Figure 12 is the twelfth flowchart of the off-chip memory read / write method of the present invention;
[0066] Figure 13 is the thirteenth flowchart of the off-chip memory read / write method of the present invention;
[0067] Figure 14 is the working schematic diagram of the minimum application system of the off-chip memory read / write method of the present invention;
[0068] Figure 15 is the data structure design diagram of the data block of the off-chip memory read / write method of the present invention. Specific Embodiments
[0069] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not used to limit the present invention.
[0070] In the following description, suffixes such as "module", "component", or "unit" used to represent elements are only for the convenience of describing the present invention and have no specific meaning in themselves. Therefore, "module", "component", or "unit" can be used interchangeably.
[0071] Figure 1 is the first flowchart of the off-chip memory read / write method of the present invention. This embodiment proposes an off-chip memory read / write method, where the off-chip memory is divided into multiple basic erase / write units, the starting page of each basic erase / write unit is used for bad block identification, and the remaining pages are used for data storage. Among them, the data block for performing data storage includes a header and a data field. The method includes:
[0072] S1. Search for the basic erase / write unit with stored data to retrieve the header of the data block that was last used to perform data storage;
[0073] S2. According to the header information of the header, in the basic erase / write unit that meets the read condition, determine the starting address of the data field of the data block and read the data according to the starting address;
[0074] Or,
[0075] S2`. According to the header information, in the basic erase / write unit that meets the write condition, determine the starting address of the data block and write the data according to the starting address.
[0076] Please refer to Figure 14The working principle diagram of the minimum application system of the off-chip memory reading and writing method of the present invention is shown. In this embodiment, the minimum system applying the off-chip memory reading and writing method includes an MCU, a FLASH, and a super capacitor. Among them, the MCU is used to implement the logic algorithm and control algorithm of the method described in this embodiment, the FLASH is the operation object in the method described in this embodiment, and the super capacitor is used to ensure that when the external power supply has an abnormal power failure, this minimum system can still maintain normal operation for a period of time, ensure that the FLASH safely completes the write operation before powering off, and avoid the loss of important data. Optionally, in this embodiment, the MCU can be replaced by an MPU (Micro Processor Unit, microprocessor), or a single-chip microcomputer.
[0077] In this embodiment, the erasing and writing methods of the FLASH include sector erase, block erase, and chip erase. In actual projects, generally sector erase or block erase is selected. Therefore, the basic unit of erasing and writing is divided according to sectors or blocks. Among them, the difference between a sector and a block is that the storage space of a block is much larger than that of a sector. Optionally, in this embodiment, the off-chip memory chip W25Q64FV is taken as an example for illustration. This chip has a total of 8 Mbytes, is divided into 2048 sectors, and each sector has 16 pages; it is divided into 128 blocks, and each block has 256 pages; each page has 256 bytes.
[0078] Please refer to Figure 15 The data structure design diagram of the data block of the off-chip memory reading and writing method of the present invention is shown. In this embodiment, in order to accurately and effectively read the data stored in the FLASH, before writing data to the FLASH, it is necessary to reasonably design the data block structure. The data block structure includes a "header" and a "data field". Among them, the "header" includes: Last_Addr, Next_Addr, Data_Len, CRC_Data, CRC_Head; the "data field" includes: Data_Filed. Specifically, Last_Addr refers to the starting address of the data written last time; Next_Addr refers to the starting address of the data to be written next time; Data_Len refers to the total number of bytes filled in the data field; CRC_Data refers to the check code of the data field, that is, the check code of all data in Data_Filed; CRC_Head refers to the check code of the header, that is, the data check code of the header from Last_Addr to CRC_Data segment; Data_Filed refers to the data field, that is, the data that really needs to be stored.
[0079] In this embodiment, the FLASH read operation method includes three main steps: First, find the basic erase-write unit with stored data; second, retrieve the header information of the most recently stored data; finally, determine the start address of the data field according to the header information of the most recently stored data, and thus read the data based on this. Among them, it is designed with Sector as the basic erase-write unit, and the first page of each Sector (i.e., the 0th page) is used as the bad block information identification page; after power-on, start retrieving from the first basic erase-write unit until the header information of the most recently stored data block is obtained, and then read the data field data of the data block to end the read operation.
[0080] In this embodiment, the FLASH write operation method includes three main steps: First, find the basic erase-write unit with stored data; second, retrieve the header information of the most recently stored data; finally, determine the start address of the next data to be written according to the header information of the most recently stored data block, and write the data.
[0081] The beneficial effect of this embodiment is that by finding the basic erase-write unit with stored data, the header of the data block where the most recent data storage was performed is retrieved; according to the header information of the header, in the basic erase-write unit that meets the read condition, the start address of the data field of the data block is determined, and the data is read according to the start address; or, according to the header information, in the basic erase-write unit that meets the write condition, the start address of the data block is determined, and the data is written according to the start address. A better fault-tolerant off-chip storage read-write scheme is realized, effectively avoiding data reading errors from the FLASH after software upgrade due to changes in the number of data structure members, or FLASH damage caused by frequent FLASH erasure and write operations, and extending the product service life.
[0082] Figure 2 It is the second flowchart of the off-chip storage read-write method of the present invention. Based on the above embodiment, the step of finding the basic erase-write unit with stored data specifically includes:
[0083] S100. Read the bad block identifier of the basic erase-write unit in sequence, and calculate the start address of the first page without bad blocks;
[0084] S200. Read the byte data of the header according to the start address, and determine whether the byte data is all reset values.
[0085] Figure 3 It is the third flowchart of the off-chip storage read-write method of the present invention. Based on the above embodiment, the step of determining whether the byte data is all reset values further includes:
[0086] S210. If the byte data is all reset values, it is determined that the current basic erase-write unit is empty;
[0087] S211. Jump to the next basic erasable and programmable unit to continue the operation of sequentially reading the bad block identification of the basic erasable and programmable unit.
[0088] Figure 4 This is the fourth flowchart of the off-chip memory read / write method of the present invention. Based on the above embodiments, the steps for continuing the operation of sequentially reading the bad block identification of the basic erasable and programmable unit further include:
[0089] S212. If it is determined that all basic erasable and programmable units are empty, return to the first basic erasable and programmable unit.
[0090] S213. Start writing a preset default value from the start address of the first page without bad blocks in the first basic erasable and programmable unit, and perform a preset read-back verification operation.
[0091] S214. If the read-back verification fails, mark the currently involved page as a page with bad blocks. If the read-back verification passes, determine that the default value is successfully written and end this operation.
[0092] Figure 5 This is the fifth flowchart of the off-chip memory read / write method of the present invention. Based on the above embodiments, the steps for determining whether the byte data is all reset values further include:
[0093] S220. If the byte data is not all reset values, calculate the check value of the front-segment bytes of the read header and compare it with the check code of the back-segment bytes pre-stored in the header.
[0094] S221. If they match, determine that the data in the header is valid, read the header of the next data block according to the data in the header, and perform the header check of the next data block.
[0095] S222. If they do not match, determine that the data in the header is invalid, erase the current basic erasable and programmable unit, and mark the currently involved page as a page with bad blocks.
[0096] Figure 6 This is the sixth flowchart of the off-chip memory read / write method of the present invention. Based on the above embodiments, the steps for performing the header check of the next data block further include:
[0097] S230. Determine whether the byte data of the header of the next data block is all reset values.
[0098] S231. If the byte data is not all reset values, continue to execute the step of calculating the check value of the front-segment bytes of the read header and comparing it with the check code of the back-segment bytes pre-stored in the header.
[0099] S232. If all the byte data are reset values, it is determined that the head of the data block with the most recently stored data has been retrieved.
[0100] Figure 7 It is the seventh flowchart of the off-chip memory read / write method of the present invention. Based on the above embodiments, if the verification fails, the step of marking the page currently involved as a page with bad blocks further includes:
[0101] S240. Write the bad block information of the page with bad blocks to the starting page of the current basic erase / write unit;
[0102] S241. Transfer to the next basic erase / write unit and calculate the starting address of the first page without bad blocks;
[0103] S242. Write the default value starting from the starting address and perform the read-back verification operation;
[0104] S243. If the read-back verification fails, erase the current basic erase / write unit and mark the page currently involved as a page with bad blocks. If the read-back verification passes, it is determined that the default value is successfully written and this operation ends.
[0105] Figure 8 It is the eighth flowchart of the off-chip memory read / write method of the present invention. Based on the above embodiments, according to the header information of the head, in the basic erase / write unit that meets the read condition, the step of determining the starting address of the data field of the data block and reading the data according to the starting address further includes:
[0106] S300. Calculate the check code of the data field and compare it with the pre-stored check code of the data field in the head;
[0107] S310. If they match, it is determined that the data of the read data field is valid and the read operation ends;
[0108] S320. If they do not match, erase the current basic erase / write unit and mark the page currently involved as a page with bad blocks.
[0109] Figure 9 It is the ninth flowchart of the off-chip memory read / write method of the present invention. Based on the above embodiments, according to the header information, in the basic erase / write unit that meets the write condition, the step of determining the starting address of the data block and writing the data according to the starting address further includes:
[0110] S300`. Obtain the starting address where the next data block is stored according to the header information, and combine the byte length of the next data block to determine whether the end address of the next data block exceeds the end address of the current basic erase / write unit;
[0111] S310`: If it exceeds, erase the current basic erase / write unit, and write the bad block information of the current basic erase / write unit to the starting page of the current basic erase / write unit; transfer to the next basic erase / write unit, and continue to execute the step of determining the starting address of the data block in the basic erase / write unit that meets the write condition according to the header information of the header;
[0112] S320`: If it does not exceed, calculate the header information of the current header and update the member values of the data field.
[0113] Figure 10 It is the tenth flowchart of the off-chip memory read / write method of the present invention. Based on the above embodiment, after the step of writing data according to the starting address, it further includes:
[0114] S330`: Read back the data of the written data block and perform verification;
[0115] S340`: If the verification fails, mark the current page involved as a page with a bad block, erase the current basic erase / write unit, and write the bad block information to the starting page of the current basic erase / write unit; transfer to the next basic erase / write unit, and continue to execute the step of determining the starting address of the data block in the basic erase / write unit that meets the write condition according to the header information of the header;
[0116] S350`: If the verification passes, determine that the data of the written data block is valid and end the write operation.
[0117] Please refer to Figure 11 the eleventh flowchart of the off-chip memory read / write method of the present invention shown in. In this embodiment, the operation process of retrieving the header information of the most recently stored data block is as follows:
[0118] Step 1, read the bad block information of the basic erase / write unit, calculate the starting address of the first page without a bad block, and execute Step 2.
[0119] Step 2, read 14 bytes of data of the header from the starting address, and execute Step 3.
[0120] Step 3, determine whether the 14 bytes of data of the header are all reset values; if not, execute Step 4; if so, determine that the current basic erase / write unit is empty, jump to the next basic erase / write unit, and return to Step 1 to continue execution; if all basic erase / write units are empty, return to the first basic erase / write unit, write a preset default value starting from the starting address of the first page without a bad block, and perform a read-back verification operation; if the verification fails, jump to Step 9 to execute; if the verification succeeds, determine that the preset default value is written successfully and end the current operation of the memory.
[0121] Step 4: Calculate the check value of the first 12 bytes of the read header information, and compare it with the pre-stored check code (the last 2 bytes); if the comparison result matches, determine that the header data is valid, read the 14-byte data of the header of the next data block according to Next_Addr in the header information, and execute Step 5; if the comparison result does not match, determine that the header data is invalid, execute Step 8, and erase the current basic erase-write unit.
[0122] Step 5: Determine whether the 14-byte data of the header is all reset values; if not, determine that the header information of the last stored data block has not been retrieved yet, and return to execute Step 4; if so, determine that the header information of the last stored data block has been retrieved.
[0123] In this embodiment, regarding the above-mentioned Step 9, it is a processing method for exceptions. In this step, mark the current page involved as a page with a bad block, write the bad block information to the specified position of the bad block identification page of the current basic erase-write unit, then transfer to the next basic erase-write unit, calculate the starting address of the first page without a bad block, write the preset default value starting from the starting address, and perform a read-back verification operation; if the verification fails, jump to Step 8 to execute; if the verification is successful, determine that the preset default value is written successfully, and end this operation of the memory.
[0124] Further, in this embodiment, for the read operation of the FLASH, selectively perform a reverse data search, that is, search for the past modification records; at this time, the header information of the valid data block is required, and a reverse search is performed according to the starting address (Last_Addr) written in the previous data block.
[0125] Please refer to Figure 12 The twelfth flow chart of the off-chip memory read-write method of the present invention shown. In this embodiment, according to the header information of the header, in the basic erase-write unit that meets the read condition, determine the starting address of the data field of the data block, and read the data according to the starting address, specifically including:
[0126] Step 6: Calculate the starting address of the data field according to the header information of the last stored data block, and read the data field data, and execute Step 7.
[0127] Step 7: Calculate the data field check code, and compare it with the reserved data field check code in the header information; if the comparison result matches, it indicates that the read data field data is valid, and end the memory read operation; if the comparison result does not match, then execute Step 8.
[0128] Step 8: Erase the current basic erase-write unit, and execute Step 9.
[0129] Step 9: Mark the currently involved page as a page with bad blocks, write the bad block information to the specified position of the bad block identification page of the current basic erase-write unit, then transfer to the next basic erase-write unit, calculate the starting address of the first page without bad blocks, write the preset default value starting from the starting address, and perform a read-back verification operation; if the verification fails, jump to Step 8 for execution; if the verification is successful, determine that the preset default value is successfully written, and end the memory read operation.
[0130] Please refer to Figure 13 the thirteenth flowchart of the off-chip memory read-write method of the present invention shown in Figure 13 . In this embodiment, according to the header information, in the basic erase-write unit that meets the write condition, determine the starting address of the data block and write the data according to the starting address, which specifically includes:
[0131] Step 1: Retrieve the header information of the data block stored most recently, and execute Step 2.
[0132] Step 2: Obtain the starting address of the next data block to be stored according to the header information, and combine the byte length of the data block to determine whether the end address of the current data block will exceed the end address of the current basic erase-write unit; if it exceeds, execute Step 3; if it does not exceed, execute Step 4.
[0133] Step 3: Erase the current basic erase-write unit, write the bad block information of the current basic erase-write unit to the specified position of its bad block identification page; then transfer to the next basic erase-write unit; calculate the starting address of the data block stored in the next basic erase-write unit.
[0134] Step 4: Calculate the header information of the data block and update the data field member values; where calculating the header information includes calculating the starting address of the previous data block stored (Last_Addr), calculating the starting address of the next data block to be stored (Next_Addr), calculating the byte length of the data field of this data block (Data_Len), calculating the check value of the data field of this data block (CRC_Data), and calculating the check value of the header information of this data block (CRC_Head).
[0135] Step 5: Based on the starting address, write all the information of the data block to the memory, and read back the content just written for verification; if the verification fails, mark the currently involved page as a page with bad blocks, and then return to Step 3 to continue execution; if the verification is successful, it indicates that the data is successfully written, and end the memory write operation.
[0136] It can be seen that in this embodiment, data verification is performed on both the "header" and the "data field" of the data block, reducing the probability of parameter reading errors.
[0137] In this embodiment, by adopting the above data structure design, the dependence of the read operation and write operation of the FLASH on the length of the data structure is reduced. Thus, when the number of members in the data field changes (increases or decreases), the technical problem of incorrect FLASH data reading addressing after software upgrade will not occur, and the maintenance cost of the product can be reduced.
[0138] In this embodiment, based on the above data structure design, the previous and subsequent storages do not depend on the continuity of the storage address.
[0139] In this embodiment, multiple basic erase and write units are allocated for each group of parameters for cyclic erase and write, reducing the erase and write frequency of the same address of the FLASH, thereby extending the service life of the product.
[0140] Based on the above embodiments, the present invention further provides an off-chip storage read and write device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the computer program is executed by the processor, the steps of the off-chip storage read and write method described in any one of the above are implemented.
[0141] It should be noted that the above device embodiment and method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment, and the technical features in the method embodiment are all correspondingly applicable in the device embodiment, which will not be elaborated here.
[0142] Based on the above embodiments, the present invention further provides a computer-readable storage medium, on which an off-chip storage read and write program is stored. When the off-chip storage read and write program is executed by a processor, the steps of the off-chip storage read and write method described in any one of the above are implemented.
[0143] It should be noted that the above medium embodiment and method embodiment belong to the same concept. The specific implementation process is detailed in the method embodiment, and the technical features in the method embodiment are all correspondingly applicable in the medium embodiment, which will not be elaborated here.
[0144] Through the description of the above embodiments, those skilled in the art can clearly understand that the above embodiment methods can be implemented by means of software plus a necessary general hardware platform. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disc), and includes several instructions for causing a terminal (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in various embodiments of the present invention.
[0145] It should be noted that, in this text, the term "including", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, such that a process, method, article or device comprising a series of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article or device. Without further limitation, an element defined by the statement "comprising an..." does not exclude the presence of additional identical elements in the process, method, article or device comprising such element.
[0146] The embodiments of the present invention have been described above in conjunction with the accompanying drawings. However, the present invention is not limited to the above specific embodiments. The above specific embodiments are merely illustrative and not restrictive. Under the inspiration of the present invention, those of ordinary skill in the art can also make many forms without departing from the spirit and scope protected by the claims of the present invention. All of these fall within the protection scope of the present invention.
Claims
1. A method for reading and writing off-chip storage, characterized in that: The off-chip storage is divided into a plurality of basic erasing and writing units, the starting page of each basic erasing and writing unit is used for bad block identification, and the remaining pages are used for data storage, wherein the data block for performing data storage includes a header and a data field, and the method comprises: Finding a basic erase unit storing data to retrieve the head of a data block where data storage was performed most recently; According to the header information of the header, in the basic erasing unit that meets the read condition, the first address of the data field of the data block is determined, and the data is read according to the first address; wherein, the check code of the data field is calculated and compared with the check code of the data field pre-stored in the header; if they match, it is determined that the data of the read data field is valid, and the read operation is terminated; if they do not match, the current basic erasing unit is erased, and the page currently involved is marked as a page with a bad block; or, According to the header information, in the basic erasing unit that meets the writing conditions, the first address of the data block is determined, and the data is written according to the first address; wherein, according to the header information, the first address of the next data block storage is obtained, and in combination with the byte length of the next data block, it is determined whether the end address of the next data block exceeds the end address of the current basic erasing unit; if it exceeds, the current basic erasing unit is erased, and the bad block information of the current basic erasing unit is written to the starting page of the current basic erasing unit; transfer to the next basic erasing unit, and continue to perform the step of determining the first address of the data block in the basic erasing unit that meets the writing conditions according to the header information of the header; if it does not exceed, the header information of the current header is calculated, and the member value of the data field is updated; The step of searching for a basic erasable unit storing data specifically includes: Read the bad block identification of the basic erase unit in sequence, and calculate the first address of the first page without a bad block; Read the byte data of the header according to the first address, and determine whether the byte data are all reset values; The determining whether the byte data are all reset values further comprises: If the byte data are all reset values, it is determined that the current basic erasing unit is empty; Jump to the next basic erasing unit to continue to perform the operation of sequentially reading the bad block identification of the basic erasing unit; The method further comprises: continuing to perform the operation of sequentially reading the bad block identification of the basic erasing unit; If it is determined that all basic erasing units are empty, the first basic erasing unit is returned; Writing a preset default value from the first address of the first page without a bad block of the first basic erase unit, and performing a preset read-back verification operation; If the read-back check fails, the currently involved page is marked as a page with a bad block, and if the read-back check passes, it is determined that the default value is written successfully, and the operation ends; The determining whether the byte data are all reset values further includes: If the byte data are not all reset values, then the check value of the first byte of the header read is calculated and compared with the check code of the second byte pre-stored in the header; If they match, it is determined that the data in the header is valid, the header of the next data block is read according to the data in the header, and a header check of the next data block is performed; If they do not match, the data in the header is determined to be invalid, and the current basic erase unit is erased, and the currently involved page is marked as a page with a bad block; The step of performing header verification of the next data block further comprises: Determine whether all byte data in the header of the next data block are reset values; If the byte data are not all reset values, continue to perform the steps of calculating the check value of the first bytes of the read header and comparing it with the check code of the second bytes pre-stored in the header; If the byte data are all reset values, it is determined that the header of the data block having the most recent stored data has been retrieved; If the verification fails, marking the currently involved page as a page with a bad block further includes: Write the bad block information of the page with bad blocks into the starting page of the current basic erase unit; Move to the next basic erase unit and calculate the first address of the first page without bad blocks; Writing the default value starting from the first address and performing the read-back verification operation; If the read-back check fails, the current basic erase unit is erased, and the currently involved page is marked as a page with a bad block. If the read-back check passes, it is determined that the default value is written successfully, and the operation ends. After writing the data according to the first address, the method further comprises: Read back the data of the written data block and perform verification; If the check fails, the page currently involved is marked as a page with a bad block, the current basic erasing unit is erased, and the bad block information is written into the starting page of the current basic erasing unit; the next basic erasing unit is transferred to continue to perform the step of determining the first address of the data block in the basic erasing unit that meets the writing condition according to the header information of the header; If the verification passes, the data in the written data block is determined to be valid and the write operation ends.
2. An off-chip storage read-write device, characterized in that: The device includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the computer program is executed by the processor, the steps of the off-chip storage reading and writing method according to claim 1 are implemented.
3. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores an off-chip storage read-write program, and when the off-chip storage read-write program is executed by the processor, the steps of the off-chip storage read-write method according to claim 1 are implemented.
Citation Information
Patent Citations
Flash memory management based on sector access
CN101075211A
Method for erasing and writing data of FLASH memory
CN102306125A