Saving Data to Flash Memory of G120

HI there,

I would like to save array in the flash memory of the G120, How could I do that ?
I need to save because if micro controller loses power then I will lost the important data.

@ anthonys - You can use ExtendedWeakReference

could you give any example ?
How could use that ?

just search for EWR or ExtendedWeakReference in the forum and/or codeshare.
You can also look in the NETMF PSDK API docs. The API) is described there.
In the NETMF installation folder you can find EWR sample code.

Thanks Reinhard…

I have used EWR sample code. It is working when I deploy code again, it does remember the object of the class . But, when I power off the G120 then target is coming null for EWR.

1 Like

Also EWR are not written immediately to flash.
There is a static Flush or FlushAll method which ensures the data to be written.

@ leforban
I tried that one as well, doesn’t work

Look at above link and from “ExtendedWeakReference (EWR) Not Working” section I have tried following method:

But it isn't working.  Following is my code I am not sure when to use above method.

MyExtendedWeakReferences.s_numBootsExtendedWeakReference = ExtendedWeakReference.RecoverOrCreate(typeof(MyExtendedWeakReferences.TypeUniqueToOurApp), 0, ExtendedWeakReference.c_SurvivePowerdown);

MyExtendedWeakReferences.s_numBootsExtendedWeakReference.Priority = (Int32)ExtendedWeakReference.PriorityLevel.System;

                    MyExtendedWeakReferences.PowerData powerdata = (MyExtendedWeakReferences.PowerData)MyExtendedWeakReferences.s_numBootsExtendedWeakReference.Target;

                    if (powerdata == null)
                       powerdata = new MyExtendedWeakReferences.PowerData();


                        DeviceName = powerdata.devicename;

 MyExtendedWeakReferences.s_numBootsExtendedWeakReference.Target = powerdata;


Any help would be great

As I know you must for EWR in 4.3 use MS and not GHI library…

use PushBackIntoRecoverList()

if (powerdata == null)
    powerdata = new MyExtendedWeakReferences.PowerData();
    DeviceName = powerdata.devicename;
--> INSERT HERE    PushBackIntoRecoverList();

@ RobvanSchelven

I tried your suggestion of “PushBackIntoRecoverList()” , but still I am not able to save data in the flash.

Can anyone tell me that How can I still continue debugging in visual studio after disconnecting power of G120 and connecting again ?


@ anthonys - Here you talk about save data in RAM. Or did you mean Flash?

@ RobvanSchelven - ya I mean in flash, sorry it was by mistake

Any news about this. I need this feature for my project, too…

Has somebody a working example for G120 or Cerbuino?

Does somebody know if it is supported on G120 or Cerbuino?

Is EWR the only way to save data into internal Flash?

You can save data to internal EEPROM on G120, read the manual 8.4

Thanks. That seems like a perfect solution.

Is it dangerous to use this. I don’t want to overwrite critical sections, where firmware is stored etc.???