Typedef
{
int a;
int b;
Char c [10];
Int d;
} A;
Then I create a structure variable, and assign all of its members, and finally to write structure into the flash specified address (that is written in the form of binary) directly,
After finished, now, an update structure has changed, the definition of A following
Typedef
{
int a;
int b;
Int e;//members add
Char c [20];//elements add
Int d;
} A;
If now I burn to write program to the MCU, the program will read from the specified address in flash back to sizeof (A) bytes, and the data to fill in the new structure, A of the case data c, d will be disordered, any good solution?
I don't think of A good approach is to upgrade the program to run for the first time, after the first flash of the saved data read the old structure, and then A A member assigned to the new structure, but it has A big disadvantages, is the program have to keep every version of the structure, the definition of A
For example, a single chip microcomputer with version 2, for some reason he have to upgrade to version 5, the previously saved data is used, must be from the first 2 - & gt; 3 - & gt; 4 - & gt; 5, as quite a trouble
There is saved in the form of characters, for example
"1, a=1"
"2, b=2"
3, c="hello"
"4, d=4"
Save old structure parameters, so that each line Numbers corresponding to the fixed member, adding new members, always add at the end, so as not to affect the original data correctly read
So to save, also some bad places, is to set up the file system, first, of course, the disadvantages are only for me, because the original program code is written in ancient times so don't use the file system, now want to change is very big, so ask what is the more convenient solution?
CodePudding user response:
This is not a file system problem, is to define a data format, using JSON