Flash reading

#1

Hy guys…

I have a structure like this:

typedef struct cron{
					u16  usr_table[6];
					u8 var_set[6];
					bool task_started;
					u8 ora_setare;
					u8 int_setare;
}app_cronjob_set;

and a buffer :

app_cronjob_set Cron[16];

At command AT+CRONADD=p1,p2,p3… i populate this structure with some data…
At command AT+CRONLIST=1…i list the data from this structure
All works fine. Until i want to save this in flash memory and read it every time at : AT+CRONLIST=0

i use these code to write the data in the flash mem:

for (i=0; i<16; i++)
		{
			write = adl_flhWrite("CRON",i,sizeof(app_cronjob_set),(u8*) &Cron[i]);
		}

And the reading part :

app_cronjob_set lstCron[16];

for (i=0; i<16;i++)
{
	if ( adl_flhExist("CRON",i) > 0)
		{
		read = adl_flhRead("CRON",i,sizeof(app_cronjob_set), (u8*) &lstCron[i]);
		}
}

I verified the returning values or adl_flhRead and adl_flhWrite …this values are ok…
but i`m obtaining some strange values:
Ex:
DUMP (1,lstCron[0].var_set,6) = 55 55 55 55 55 55
and it should be = 01 00 01 00 00 01 - something like this

Can someone see what i’m doing wrong ?

Thanks…

#2

At first look here is what I see. The “Cron” variable is a structure, the last value in adl_flhWrite needs to be a u8 variable, not a structure of multiple sets of values.

My advice is that you break up your structure and write the pieces in the structure one by one with the adl_flhWrite command.

#3

I did the same thing…at another part of my application…there i`m writing also a structure…and it works just fine…
I think i saw from where i get this problem…but i’m not sure how to solve this…

Besides reading flash with at+cronlist command…i read it with a cyclic timer at every 30 seconds.
and i saw with some traces that after 2 readings … every flash id has a size of 1 byte instead of 22 bytes …
Somehow the flash is overwritten with a byte value…but i don’t know exactly why is this happening…
Now i’m trying to limit the function called at 30 sec…to read just once… Because that’s all i need…in case of power failure…i don’t want to lose those values… and at power back to load those values back in RAM memory and start normal execution again…

Thanks for you advice…

#4

No, that is not correct.

The final parameter of adl_flhWrite is a u8* pointer - it is the address of the start of the data to write.

Strictly, it would be more appropriate if this were a void* pointer - see: https://forum.sierrawireless.com/t/garbage-when-reading-flash/3612/8

#5

Yes, that’s true…and isn’t the only function that in my opinion needs to take void* pointer parameters for data…but this is it…

I resolved my issues…the problem was that…somewhere in my app i periodically need to save in flash some paramaters from that structures that is modified by the application and in flash needs to be the last value …
I tried to write only to a member of the structure :

adl_flhWrite("CRON",i,sizeof(u8),(u8*) &flhCron[i].task_started);//update in flash

But this statement will write one byte at the starting adress of the structure and not on that specific member of the structure as i was expected…and this is why i cannot read succesfull my data…after such a writing…the structure in flash has only a byte written…

Thanks for your replies…

#6

[/quote]
Thats not true. In fact it would be bad.

What the API is saying is what you are writing is a byte stream (ie, a series of u8s)

If it took a void* then it really wouldn’t know what was at the end of the pointer, but in this case its going to take the pointers and treat it as a stream of bytes. Its a common C idiom to serialize structures like this, however (not so relevant in this case) can be bad depending on the compiler and its byte packing.

#7

I disagree (obviously!)

No.

What the API should be saying to you, the user, is that it will write any arbitrary data type that you should care to give it - just like malloc() returns a void* pointer because it allocates memory for any arbitrary data type.

Which is exactly the case!

The API neither knows nor cares anything about the data being passed to it - all it needs to know is where it starts, and how big it is.

I think you’re confusing the internal implementation with the interface to the user?

#8

Me too faced some issue in reading flash when I was writing a structure in flash whose length was 650 bytes.

But when we get the length of flash ID using api “adl_flhExists” it gives wrong value ,

2017/10/24;16:25:01:426;010;ADL;22;[ADL] flash subs 6 : -4
2017/10/24;16:25:01:426;011;ADL;22;Flh Obj 0000 Len : 650
2017/10/24;16:25:01:426;012;ADL;3;connProfile id: 0 exists length: 138

Be careful when you use adl_flhExists returned length when you want to read it into structure.

#9

Spreeder is the web’s leading destination for speed readind.