Data storage method of storage device, electronic device and storage medium
By splitting the stored data structure into two parts and defining the data interface, the data out of control problem of small device storage devices during software updates is solved, and a data storage solution with high reliability and resource saving is achieved.
Patent Information
- Application Number
- CN202510518871.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-04-23
- Publication Date
- 2025-08-19
AI Technical Summary
Storage devices of existing small devices need to occupy additional software and hardware resources during the data storage process, and software version updates can easily lead to data out of control.
The stored data structure is split into two stored data structures, and the corresponding data interface is defined to store configuration information and feature information, including IP address, port number, storage flag data, verification value data and quantity information of configuration parameters to ensure the legality and integrity of the data.
Without adding additional storage resources, data out of control during software version upgrade is prevented, and high reliability and flexible data storage is achieved.
Smart Images

Figure CN120508246A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of data storage, and in particular relates to a data storage method of a storage device, an electronic device, and a storage medium. Background Art
[0002] In the product design of small devices (such as mobile phones, pads, smart watches and Bluetooth headsets, etc.), the storage devices inside small devices (such as microcontrollers) can realize data storage. Compared with large devices, they do not require additional software and hardware resources and have the advantages of rapid deployment and direct use.
[0003] Existing single-chip microcomputer data storage technology is implemented through database-like methods such as easyflash, but the above method requires additional software and hardware resources (such as interfaces), and the data members added by software version updates will cause the original data to be reset or disordered, resulting in data storage becoming out of control.
[0004] Therefore, a data storage method is urgently needed to solve the problem of data storage out of control during the update process of the above storage device. Summary of the Invention
[0005] The technical problem to be solved by the present invention is to provide a data storage method, an electronic device and a storage medium for a storage device, so as to solve the problem in the related art that storing data requires more software and hardware resources and is prone to loss of control.
[0006] In order to solve the above technical problems, this application provides the following technical solutions:
[0007] In a first aspect, the present application provides a data storage method for a storage device, comprising:
[0008] Setting a storage data structure and defining a data interface of the storage data structure; wherein the storage data structure includes: a first storage data structure and a second storage data structure;
[0009] Storing configuration information of storage data in the first storage data structure;
[0010] The characteristic information of the stored data is stored in the second stored data structure.
[0011] Furthermore, the configuration information includes: IP address information, port number and configuration parameters.
[0012] Furthermore, the characteristic information includes: storage mark data and check value data of the stored data.
[0013] Furthermore, the storage mark data is used to locate the location of the storage data.
[0014] Furthermore, the verification value data of the stored data is used to verify whether the stored data is legal.
[0015] Furthermore, the characteristic information also includes: quantity information of the configuration parameters.
[0016] Furthermore, the quantity information of the configuration parameters is used to verify whether the quantity of the configuration parameters has changed.
[0017] Furthermore, the storage device includes: a single chip microcomputer, an SPI flash memory, a NAND flash memory and an electrically erasable programmable read-only memory.
[0018] In a second aspect, the present application further provides a computer electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of any one of the above-mentioned data storage methods when executing the computer program.
[0019] In a third aspect, the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any one of the above-mentioned data storage methods are implemented.
[0020] The present application provides a data storage method for a storage device, an electronic device, and a storage medium, which have the following beneficial effects:
[0021] This application first splits the storage data structure into two storage data structures and defines a basic access interface. Then, based on the two storage data structures, corresponding storage techniques and storage configuration parameters are set. Finally, the data is stored according to the storage techniques and storage configuration parameters. Compared with related technologies, the solution of this application does not require additional storage resources and can also prevent data loss of control during software version upgrades. BRIEF DESCRIPTION OF THE DRAWINGS
[0022] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0023] Figure 1 This is a flow chart of a data storage method of a storage device according to an embodiment of the present application;
[0024] Figure 2 It is a structural diagram of a computer electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0025] The following will be combined with the drawings in the embodiments of this application to clearly and completely describe the technical solutions in the embodiments of this application. Obviously, the embodiments described are part of the embodiments of this application, not all of them. Based on the embodiments in this application, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of this application.
[0026] It should be noted that when an element is referred to as being "fixed to" another element, it may be directly on the other element or there may be an intermediate element. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be an intermediate element. Conversely, when an element is referred to as being "directly on" another element, there is no intermediate element. The terms "vertical," "horizontal," "left," "right," and similar expressions used herein are for illustrative purposes only.
[0027] In this application, unless otherwise expressly specified or limited, terms such as "mounted," "connected," "connect," and "fixed" should be understood in a broad sense. For example, they may refer to fixed connections, detachable connections, or integration; mechanical connections or electrical connections; direct connections or indirect connections through an intermediate medium; and internal connections between two components or interactions between two components. Those skilled in the art will understand the specific meanings of these terms in this application based on specific circumstances.
[0028] Furthermore, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance or implicitly specifying the number of the technical features being referred to. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features. Throughout the description of this application, "plurality" means two or more, unless otherwise specifically defined.
[0029] The terms used in one or more embodiments of the present application are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of the present application. The singular forms "a", "the", and "the" used in one or more embodiments of the present application are also intended to include plural forms unless the context clearly indicates otherwise.
[0030] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application belongs. The terms used in the template description herein are for the purpose of describing specific embodiments only and are not intended to limit this application. The term "and / or" as used herein includes any and all combinations of one or more of the associated listed items.
[0031] It should be understood that although the terms first, second, etc. may be used to describe various information in one or more embodiments of the present application, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from each other. For example, without departing from the scope of one or more embodiments of the present application, the first may also be referred to as the second, and similarly, the second may also be referred to as the first. Depending on the context, the word "if" as used herein may be interpreted as "when..." or "when...".
[0032] Existing data storage technology for small storage devices (such as single-chip microcomputers) is implemented through database-like methods such as easyflash, but the above method requires additional software and hardware resources (such as interfaces), and the data members added by software version updates will cause the original data to be reset or disordered, resulting in data storage becoming out of control.
[0033] The following specific embodiments describe in detail the technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes in certain embodiments will not be repeated. The embodiments of the present application will be described below in conjunction with the accompanying drawings.
[0034] Please refer to Figure 1 The present invention provides a data storage method for a storage device, which is applied to a small storage device and includes at least the following steps:
[0035] S10. Set a storage data structure and define a data interface of the storage data structure; wherein the storage data structure includes: a first storage data structure and a second storage data structure.
[0036] Specifically, in this embodiment, before storing data, a storage data structure may be set first, and a data interface for the storage structure data may be defined to facilitate subsequent operations on the data.
[0037] It should be noted that, in this embodiment, the storage data structure includes two structures, namely, a first storage data structure and a second storage data structure.
[0038] S20: Store configuration information of storage data in the first storage data structure.
[0039] Specifically, in this embodiment, the configuration information of the storage data is stored in the first storage data structure.
[0040] In one embodiment of the present application, the configuration information includes: IP address information, port number and configuration parameters.
[0041] S30: Store the characteristic information of the stored data in the second stored data structure.
[0042] Specifically, in this embodiment, the characteristic information of the stored data is stored in the second storage data structure.
[0043] In one embodiment of the present application, the characteristic information includes: storage flag data and check value data of the stored data.
[0044] In a specific embodiment of the present application, the storage mark data is used to locate the location of the storage data.
[0045] Specifically, the storage flag is used to indicate that the current storage address has been used to store data. It is mainly used to distinguish whether it is used to store data. For example, the original data of the STM32 flash after erasure is 0XFFFFFFF. If the address is detected to be this value, it is considered that the storage data is not used. For example, the value of the flag data can be set to OXAABBCCDD. If the data read back is not this value, it is considered that this area is not used to store data. The user can write this flag himself, and any binary number can be used. It only needs to distinguish the default original data.
[0046] In one embodiment of the present application, the verification value data of the stored data is used to verify whether the stored data is legal.
[0047] Specifically, legality refers to whether the read data is valid and whether there are any abnormal modifications. For example, in the configuration parameter list of a certain data, there are four parameters A, B, C, and D. The values written last time were 1, 2, 3, and 4 respectively. The verification method uses the sum of the configuration parameter values for verification. If the value read out next time is 1, 2, 2, 4, and the other checksums are 9 and the checksum written last time is 10, then the checksums are inconsistent and it is considered illegal.
[0048] It can be understood that the relationship between the data and the check value can be verified using a certain verification algorithm, such as the above-mentioned checksum algorithm, which adds up the values of all data to obtain a checksum; at this time, the relationship between the data and the check value is the relationship between the addend and the sum; if other methods are used to generate the check value, other methods need to be used for verification.
[0049] It should be noted that when verifying data, a separate data verification interface needs to be set up.
[0050] In one embodiment of the present application, the characteristic information further includes: quantity information of the configuration parameters.
[0051] Specifically, the quantity information of the configuration parameters is used to verify whether the quantity of the configuration parameters has changed.
[0052] It is understandable that due to the uncertainty of product requirements, the currently released software version may only require these parameters, but subsequent functional requirements will require the addition of other parameters. When the parameters are added and the data is verified, errors will inevitably occur, which will then lead to errors in the software upgrade.
[0053] Therefore, in this embodiment, a number of configuration parameters is added to the feature information, and this information is compared with the number of configuration parameters in the current version to determine whether there is a change in the number of stored data between two program versions.
[0054] In one embodiment of the present application, the storage device includes: a single chip microcomputer, an SPI flash memory, a NAND flash memory and an electrically erasable programmable read-only memory.
[0055] It is understandable that the solution in this application is an improvement solution for small storage devices. Since the software and hardware resources of small storage devices are limited, if other storage methods are used, they will occupy too many software and hardware resources.
[0056] The present application provides a data storage method for a storage device, an electronic device, and a storage medium, which have the following beneficial effects:
[0057] This application first splits the storage data structure into two storage data structures and defines a basic access interface. Then, based on the two storage data structures, corresponding storage techniques and storage configuration parameters are set. Finally, the data is stored according to the storage techniques and storage configuration parameters. Compared with related technologies, the solution of this application does not require additional storage resources and can also prevent data loss of control during software version upgrades.
[0058] In order to better understand the present invention, it can be understood through the following specific example, which is implemented using the STM32F103 microcontroller as an example:
[0059] Step 1. A product project uses STM32F103 to implement an IoT device. This device requires a FLASH sector inside the stm32f103. 1024 bytes (1KByte) is used to store data. This data is used to initialize the application, record parameter configuration, etc. It needs to be saved when the power is turned off and read for configuration when the power is turned on again.
[0060] Step 2. The HAL library in STM32F103 provides basic FLASH access interface, which is abstracted into three interfaces here: Flash_erase(), Flash_read(), and Flash_write().
[0061]
[0062] Step 3. Define the storage data structure: StoreCfgData_t. This structure is used to indicate which data needs to be stored, assuming there are IP addresses, port numbers, etc.
[0063]
[0064] Step 4. After the above three steps, the basic data storage, reading and writing process can be realized. A series of interfaces can be defined to realize the reading and writing of this structure, including SetCfgDataToDefault, ReadCfgData, and StoreCfgData.
[0065]
[0066] Step 5: Read data for configuration when power is turned on. Users can configure data and save it.
[0067]
[0068] Step 6. After the above five steps, a basic data storage framework is implemented, providing data storage for upper-layer applications while occupying very little additional resources. The above solution is the storage logic of the existing solution. It has a disadvantage: data unreliability, which is reflected in two aspects: First, due to the characteristics of the internal FLASH of the STM32F103, the data is all hexadecimal 0xFFFFFFF (based on 32 bits) when it is first powered on. Therefore, the data on the first power-on is incorrect and does not meet the user's requirements. Second, any storage medium is prone to data errors. Therefore, even after the data is reconfigured after the first power-on, the correctness of subsequent data storage cannot be guaranteed. Therefore, further optimization is needed.
[0069] Step 7. To achieve reliable data storage, in this embodiment, the StoreCfgData_t structure can be optimized and divided into two parts: StoreCfgData_t and CfgData_t.
[0070]
[0071] Step 8. Complete the operation interface in Step 4:
[0072] 1. After reading the FLASH data, the validity of the data must be determined. If the data is invalid, the default configuration is set and rewritten into the FLASH.
[0073] 2. When writing to FLASH, it is necessary to calculate the checksum of the written data.
[0074] 3. A data verification interface needs to be added.
[0075]
[0076]
[0077] Step 9. After the optimization of Step 8, this data storage framework can achieve high reliability and minimal resource consumption. It is a very good storage framework. However, due to the uncertainty of product requirements, the currently released software version may only require these parameters, but subsequent functional requirements may require additional parameters, such as cfgParaC. When compiling a new software version and upgrading it to an old version of the device, when the device is re-powered on and initialized, the Uint32 in the configuration function ReadCfgData is read. _ crc = GetDataCrc(pCfg->cfgData, sizeof(CfgData_t)); Calculating the checksum data will result in errors and setting the configuration to default parameters. This can cause existing field devices to experience unexpected upgrade consequences, such as going offline after the upgrade. Therefore, further optimization of this framework is needed.
[0078] Step 1 0. Add a member variable to the StoreCfgData_t structure to record the size of the cfgData_t structure. Use this length and the change in the size of the CfgData_t structure of the current version to determine whether there is a change in the number of stored data between the two program versions.
[0079]
[0080] Step 1 1. To achieve normal upgrade or rollback between two software versions with different numbers of storage parameters and ensure that the parameter configuration storage values shared by the two versions remain unchanged after the version change, it is necessary to optimize the ReadCfgData() and StoreCfgData() interfaces, and add the CheckDiffCfgDataSize() interface to determine the legitimacy of parameters that are more or less than the previous version when the number of storage parameters is inconsistent.
[0081]
[0082]
[0083]
[0084] Step 1 2. Through Step 1 to 11, a data storage framework with high reliability, minimal resource consumption, and the ability to dynamically change the number of parameters is gradually implemented.
[0085] See also Figure 2 An embodiment of the present application further provides a computer electronic device 200, comprising a storage 203 and a processor 202, wherein the storage 203 stores a computer program, and when the processor executes the computer program, the steps of any one of the above-mentioned data storage methods are implemented.
[0086] Specifically, the electronic device 200 includes: a transceiver 201, a bus interface and a processor 202, wherein the processor 302 is used to set up a storage data structure and define a data interface of the storage data structure; wherein the storage data structure includes: a first storage data structure and a second storage data structure; the configuration information of the storage data is stored in the first storage data structure; and the characteristic information of the storage data is stored in the second storage data structure.
[0087] In the embodiment of the present application, the electronic device 200 further includes a memory 203. Figure 2 In the embodiment of the present invention, the bus architecture can include any number of interconnected buses and bridges, specifically linking various circuits of one or more processors represented by processor 202 and memory represented by memory 203. The bus architecture can also link various other circuits such as peripheral devices, voltage regulators, and power management circuits, which are well known in the art and therefore will not be further described herein. The bus interface provides an interface. The transceiver 201 can be multiple components, that is, including a transmitter and a receiver, providing a unit for communicating with various other devices over a transmission medium. The processor 202 is responsible for managing the bus architecture and general processing, and the memory 203 can store data used by the processor 202 when performing operations.
[0088] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of any one of the above-mentioned data storage methods are implemented.
[0089] In this embodiment, the computer-readable storage medium may be a non-volatile storage medium or a volatile storage medium. For example, the computer storage medium may include, but is not limited to, various media capable of storing program code, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0090] In all examples shown and described herein, any specific values should be interpreted as merely exemplary and not limiting, and thus other examples of the exemplary embodiments may have different values.
[0091] It should be noted that similar reference numerals and letters denote similar items in the following drawings, and therefore, once an item is defined in one drawing, it does not need to be further defined or explained in subsequent drawings.
[0092] In the several embodiments provided in this application, it should be understood that the disclosed devices and methods can also be implemented in other ways. The device embodiments described above are merely schematic. For example, the flowcharts and structure diagrams in the accompanying drawings show the possible architectures, functions and operations of the devices, methods and computer program products according to the multiple embodiments of the present application. In this regard, each box in the flowchart or block diagram can represent a module, a program segment or a part of the code, and the module, program segment or a part of the code contains one or more executable instructions for implementing the specified logical functions. It should also be noted that in an alternative implementation, the functions marked in the box can also occur in an order different from that marked in the accompanying drawings. For example, two consecutive boxes can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the structure diagram and / or flowchart, and the combination of boxes in the structure diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or can be implemented using a combination of dedicated hardware and computer instructions.
[0093] In addition, the functional modules or units in the various embodiments of the present application can be integrated together to form an independent part, or each module can exist independently, or two or more modules can be integrated to form an independent part.
[0094] If the functions are implemented in the form of software function modules and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a terminal device (which can be a smart phone, personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of the present application.
[0095] The above is only a specific implementation method of the present application, but the scope of protection of the present application is not limited thereto. Any technician familiar with this technical field can easily think of changes or replacements within the technical scope disclosed in this application, which should be covered by the scope of protection of the present application.
Claims
1. A data storage method for a storage device, characterized in that: include: Setting a storage data structure and defining a data interface of the storage data structure; wherein the storage data structure includes: a first storage data structure and a second storage data structure; Storing configuration information of storage data in the first storage data structure; The characteristic information of the stored data is stored in the second stored data structure.
2. The data storage method according to claim 1, wherein: The configuration information includes: IP address information, port number and configuration parameters.
3. The data storage method according to claim 1, wherein: The characteristic information includes: storage mark data and verification value data of the stored data.
4. The data storage method according to claim 3, characterized in that: The storage mark data is used to locate the location of the storage data.
5. The data storage method according to claim 3, characterized in that: The verification value data of the stored data is used to verify whether the stored data is legal.
6. The data storage method according to claim 3, characterized in that: The characteristic information also includes: quantity information of the configuration parameters.
7. The data storage method according to claim 6, characterized in that: The quantity information of the configuration parameters is used to verify whether the quantity of the configuration parameters has changed.
8. The data storage method according to claim 1, wherein: The storage device includes: a single chip microcomputer, an SPI flash memory, a NAND flash memory and an electrically erasable programmable read-only memory.
9. A computer electronic device, characterized in that: The method comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the data storage method according to any one of claims 1 to 8 when executing the computer program.
10. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps of the data storage method according to any one of claims 1 to 8 are implemented.