If there are several setting parameters that need to be stored in Flash, how do we generally store them? Will the different parameters be stored in different pages, or will these parameters be bundled into a single structure, and each modification will be written once?
By storing the parameters to a fixed address, each parameter will occupy one block of Flash. And all the parameters are bundled and stored in the Flash block, then only one parameter is modified, it is also necessary to save all the parameters together. So what better way?
Learning Msos some time ago, I saw that the parameter storage method used in it is well designed, and it stores the parameter variable address and value together in Flash. The highlight is to use the variable address of the parameter to mark different variables.
First, the data structureThis storage method uses two data structures:
Typedef struct
{
Uint Address; //The address of the parameter variable
Uint Data; //value of the parameter variable
}CellStruct;
To store a variable, you need to store the address of this variable along with its value in the memory area. The core of this storage method is this data structure. This allows you to assign a stored value to the corresponding variable directly using *((uint *)(Address)) = Data. Simply put, each parameter is marked according to the address value.
2. Data structure of the storage area

This storage method uses two functions:
Read the value of the variable in the memory area and update the value of the variable
Variable storage function
2.1 Reading of parameters
The flow chart is as above, the main steps are as follows:
Update the value of the variable according to the variable address stored in the Flash;
The address value stored in the flash is stored in a temporary array, and according to the address value, it is determined whether there is invalid data stored repeatedly, and the invalid array is invalidated;
Empty the Flash memory area and save the valid variables in the temporary array to Flash.
Through these steps, the variables stored in the storage area are read out, and the duplicate invalid data in the storage area is cleared. Here is the source code:
The writing of parameters is very simple. According to the writing point in the data structure, the address and value of the variable are written into Flash.
Instructions:
Calling a function that reads all variables each time the power is turned on;
When modifying a parameter, call the write parameter function;
Third, matters needing attentionWhen reading parameters, you need to create an array of ParameterSpace size in RAM. If this value is too large, it will exceed the size of the stack, causing memory overflow. Therefore, the storage area cannot be opened too much.
This method is easy to use, especially when updating variable values, updating the corresponding values ​​based on the stored variable address. In fact, its essence is the same as we use variable names to mark different variables. However, there are also disadvantages:
First, it stores the address of the variable and the value of the variable at the same time, which is equivalent to using twice as much storage space;
As mentioned in the note above, the memory area cannot be opened too large, otherwise the temporary array will exceed the size of the stack.
Corona Resistance Enameled Round Copper Wire
About Corona Resistance Enameled Round Copper Wire. |
Capable of working under extreme situations where strong resistibility against very high and low temperature, powerful cryogn,hard radiation and forceful heat shock are needed.
Be suitable for refrigerator compressor and aire condition compressor, microwave oven electric instrument and other pressuring motor.
Products Feature. |
Name |
Corona Resistance Enameled Round Copper Wire |
Conductor |
Copper |
Dimension(mm) |
Diameter: 0.20 ~ 2.50 |
Thermal Class(℃) |
200(Class C); |
Standard |
J B / T 10930-2010 |
Packing |
PT 4 – PT 200 or ply-wood spool |
Application |
Variable frequency motor, speed regulating motor, lifting motor, elevator motor and other fields. |
Enamelled Copper Wire,Corona Resistance Enameled Round Copper Wire,Corona Resistant Wire,Resistant Wire Enamelled Copper Wire
HENAN HUAYANG ELECTRICAL TECHNOLOGY GROUP CO.,LTD , https://www.huaonwire.com