Uh oh, I thought it would be easy to store persistent app data

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Uh oh, working with some other SDK's that support writing/reading data to flash, I thought this would be well supported in WICED.

How do I write a string (or any BLOB) to a persistent location and also read that string (or BLOB) back? And then write a changed string (or BLOB) back to the location?

I understand underlying FLASH issues with re-writing - but I really don't want to have to deal with that.

Surely there is some support in WICED or at least some contributed code that deals with this need.

I don't need a lot of space.maybe just 1KB or so.

0 Likes
1 Solution
Anonymous
Not applicable

Hello,

you can use the DCT for that purpose. A section is reserved at the end of it, so you can link your personnal data there.

You can do something like this:

typedef struct {

int my_int;

} dct_data_t;

const dct_data_t _app_dct = {

.my_int = 42,

};

This will add a section in the DCT containing an integer, and initialized to 42.

To access it, you can do as follow:

dct_data_t *data;

wiced_dct_read_lock ((void **) &data, WICED_TRUE, DCT_APP_SECTION, 0, sizeof (dct_data_t));

data->my_int = 0;

wiced_dct_write (data, DCT_APP_SECTION, 0, sizeof (dct_data_t));

wiced_dct_read_unlock (data, WICED_TRUE);

Like this you have modified your own data and set my_int to 0.

View solution in original post

5 Replies
Anonymous
Not applicable

Note, Using WICED C API's

0 Likes
Anonymous
Not applicable

Hello,

you can use the DCT for that purpose. A section is reserved at the end of it, so you can link your personnal data there.

You can do something like this:

typedef struct {

int my_int;

} dct_data_t;

const dct_data_t _app_dct = {

.my_int = 42,

};

This will add a section in the DCT containing an integer, and initialized to 42.

To access it, you can do as follow:

dct_data_t *data;

wiced_dct_read_lock ((void **) &data, WICED_TRUE, DCT_APP_SECTION, 0, sizeof (dct_data_t));

data->my_int = 0;

wiced_dct_write (data, DCT_APP_SECTION, 0, sizeof (dct_data_t));

wiced_dct_read_unlock (data, WICED_TRUE);

Like this you have modified your own data and set my_int to 0.

Anonymous
Not applicable

Thanks Oliver!
So it is quite easy after all!

I did have an issue with the initialization to 42 not occurring when the new DCT was downloaded, but I found that I needed to follow the pattern in snip/config_mode including the config_mode_dct.[ch] files as well as the config_mode.mk. When I did that, initialization and everything worked quite nicely.

Thanks again!

PS: If there's any additional documentation besides what's in the doc directory, I'd love to have a link / the document.

0 Likes
Anonymous
Not applicable

One more thing... in addition to DCT docs, is there anything related to writing thousands of times that I need to be concerned about? Is it managing and reclaiming FLASH nicely?

0 Likes
Anonymous
Not applicable

Well that would depend on the flash you are using, but I think nowadays flash should support enough erase/write cycles for you don't need to be concerned about it. Data are being swapped from a sector to another (on STMF205 at least, DCT uses two sectors, but only one active at a time).