Main Site Documentation

Saving Data to Flash Memory of G120


#1

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.


#2

@ anthonys - You can use ExtendedWeakReference


#3

Thanks
could you give any example ?
How could use that ?


#4

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.


#5

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.


#6

try



http://msdn.microsoft.com/en-us/library/microsoft.spot.extendedweakreference_fields(v=vs.102).aspx

#7

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


#8

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

https://www.ghielectronics.com/docs/165/netmf-and-gadgeteer-troubleshooting#3020

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.



```cs
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();

                    }

                    else
                    {
                       
                        DeviceName = powerdata.devicename;
                        
                    }

 MyExtendedWeakReferences.s_numBootsExtendedWeakReference.Target = powerdata;
                                             
                    System.Threading.Thread.Sleep(2000);

                    GHI.Premium.System.Util.FlushExtendedWeakReferences();

Any help would be great


#9

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


#10

use PushBackIntoRecoverList()


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


#11

@ 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 ?

Thanks


#12

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


#13

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


#14

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?


#15

You can save data to internal EEPROM on G120, read the manual 8.4
https://www.ghielectronics.com/downloads/man/G120_User_Manual.pdf


#16

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.???