Reply by Tecnowatt - Massimo Sala April 1, 20052005-04-01
I see this simple question is interesting for many people.

Many thanks for all you guys with your suggestions. Unfortunately I cannot
- add a battery to back-up the SRAM
- add FRAM
because the project is already installed at many customers sites, and my
boss said "we cannot modify the hardware". Moreover, I have a weird behaviour using the flash, sometimes after a power
off / power on of the Rabbit RCM2110 the data stored with writeUserBlock()
are gone.

I am working on this, adding more tracing to my code. I have also one doubt.
The RCM2110 core module is hosted on a board, developed by a contractor for
us.
I am not a electronic engineer, and the contractor isn't a Rabbit wizard.

Is it possible that some of the RCM2110 signals on J1 and J2 connectors,
linked to the motherboard, at power off / power on cause the flash to erase
(because the motherboard change their status) ?

The code in flash isn't erased, only the writeUserBlock() data.

Signals like:
SMODE1
SMODE0
/RESET
/RES_IN
STATUS
I know are used by the programming cable... ciao, Massimo


Reply by David Troike March 31, 20052005-03-31

Using an Example at Z-World I wrote this routine for saving user
variables to flash. These variables would only range once before
the customer placed the unit into service. They have to tailor
certian items and then let it run.

I have looked at many other people's code too and having a tough
time grasping the concepts for writing to flash.

Here is what I wrote but it does not work all the time. //*****************************************************************

//run-time variables copied to flash
typedef struct _run_time
{
unsigned long valid_flag;
char charPLC_Present_Flag;
char charCurrent_Level;
char charCurrent_Range;
unsigned int Alarm_hour;
unsigned int Alarm_minute;
} RTDATA;

// in main code read user block to ram and see if it is valid

//copy flash data to RAM.
readUserBlock(&RTData,0,sizeof(RTData));

// if data is not marked as valid, put in defaults
if (RTData.valid_flag!=0x55aaface)
{
RTData.charPLC_Present_Flag = 0;
RTData.charCurrent_Level = 0;
RTData.charCurrent_Range = 1;
RTData.Alarm_hour = 0;
RTData.Alarm_minute = 0;
RTData.valid_flag=0x55aaface;
writeUserBlock(0,(void *)&RTData,sizeof(RTData));
}

if (RTData.charPLC_Present_Flag != charPLC_Present_Flag)
{
RTData.charPLC_Present_Flag = charPLC_Present_Flag;
writeUserBlock(0,(void *)&RTData,sizeof(RTData));
}

/***************************************************

Go to User Setup Routine

***************************************************/

//Done with Setup Routine, save any changed data to flash.

if (RTData.charCurrent_Level != charCurrent_Level)
{
RTData.charCurrent_Level = charCurrent_Level;
writeUserBlock(0,(void *)&RTData,sizeof(RTData));
}

if (RTData.charCurrent_Range !=charCurrent_Range)
{
RTData.charCurrent_Range !=charCurrent_Range;
writeUserBlock(0,(void *)&RTData,sizeof(RTData));
}

if (RTData.Alarm_hour !=Alarm_hour)
{
RTData.Alarm_hour =Alarm_hour;
writeUserBlock(0,(void *)&RTData,sizeof(RTData));
}

if (RTData.Alarm_minute !=Alarm_minute)
{ RTData.Alarm_minute =Alarm_minute;
writeUserBlock(0,(void *)&RTData,sizeof(RTData));
}


Reply by bmurthazw March 30, 20052005-03-30

--- In rabbit-semi@rabb..., "H Abed" <mesho@s...> wrote:
> So if static variables are stored in RAM, and their values does not
change
> as long the power there, what does this function do and why do we
need to
> call it at beginning of the code to recover variables
_sysIsSoftReset()

It gives an extra level of protection for non-atomic writes that
might be happening at reset or power down. Also, in some boards such
as the RCM32xx, RCM33xx and BL2600, variables normally go in non-
battery backed fast RAM. The 'bbram' keyword would be adequate for
char variables there, but 'protected' would provide extra safety for
multibyte variables. - Brian

>
> Regards,
> Hisham Abed >
> _____
>
> From: Maurits van de Kamp [mailto:mvk@h...]
> Sent: Wednesday, March 30, 2005 7:06 AM
> To: rabbit-semi@rabb...
> Subject: Re: [rabbit-semi] Re: Writing Variables to Flash? >
> > Does using static variables solve your problem?
> >
> > If you have a static variable declared and then the
> > board resets, it keeps its last value.
>
> When it resets, yes, but not when it powers down. Static variables
are
> in ram, and it needs power to stay there.
>
> > I am not sure,
> > but I guess only changing the variable's value does
> > not wear out the flash.
>
> That's true, because it's not in the flash. :o)
>
> Maurits.
> --
>
> HiTECHnologies Industrial Automation B.V.
> Industrieweg 30, 3401 MA, IJsselstein, The Netherlands
> P.O. box 242, 3400 AE, IJsselstein, The Netherlands
> Tel: +31 30 6875335
> Fax: +31 30 6875333
> E-mail: info@h...
> Web: www.hitechnologies.nl
>
> ===================================================================
> The information contained in this communication is confidential and
may
> be legally privileged. It is intended solely for the use of the
> individual or entity to whom it is addressed and others authorized
to
> receive it. If you are not the intended recipient you are hereby
> notified that any disclosure, copying, distribution or taking any
action
> in reliance on the contents of this information is strictly
prohibited
> and may be unlawful.
> HiTECHnologies B.V. is neither liable for the contents, nor for the
> proper, complete and timely transmission of the information
contained in
> this communication.
> =================================================================== >
>
<http://us.ard.yahoo.com/SIG9nqfk2e/M)8184.6018725.7038619.300117
6/D=gr
>
oups/S06554205:HM/EXP12270761/A%93423/R=0/SIGel9gslf/*http:
/www.n
> etflix.com/Default?mqso`190075> click here >
> <http://us.adserver.yahoo.com/l?
M)8184.6018725.7038619.3001176/D=groups/S=
> :HM/A%93423/randd7710532 >
> _____
>
> > Terms of Service.



Reply by H Abed March 30, 20052005-03-30

So if static variables are stored in RAM, and their values does not change as long the power there, what does this function do and why do we need to call it at beginning of the code to recover variables   _sysIsSoftReset()

 

Regards,
Hisham Abed

From: Maurits van de Kamp [mailto:m...@hitechnologies.nl]
Sent: Wednesday, March 30, 2005 7:06 AM
To: r...@yahoogroups.com
Subject: Re: [rabbit-semi] Re: Writing Variables to Flash?

 

> Does using static variables solve your problem?
>
> If you have a static variable declared and then the
> board resets, it keeps its last value.

When it resets, yes, but not when it powers down. Static variables are
in ram, and it needs power to stay there.

> I am not sure,
> but I guess only changing the variable's value does
> not wear out the flash.

That's true, because it's not in the flash. :o)

Maurits.
--

HiTECHnologies Industrial Automation B.V.
Industrieweg 30, 3401 MA, IJsselstein, The Netherlands
P.O. box 242, 3400 AE, IJsselstein, The Netherlands
Tel: +31 30 6875335
Fax: +31 30 6875333
E-mail: i...@hitechnologies.nl
Web: www.hitechnologies.nl

==================================================================
The information contained in this communication is confidential and may
be legally privileged. It is intended solely for the use of the
individual or entity to whom it is addressed and others authorized to
receive it. If you are not the intended recipient you are hereby
notified that any disclosure, copying, distribution or taking any action
in reliance on the contents of this information is strictly prohibited
and may be unlawful.
HiTECHnologies B.V. is neither liable for the contents, nor for the
proper, complete and timely transmission of the information contained in
this communication.
===================================================================
           





Reply by Maurits van de Kamp March 30, 20052005-03-30

> Sorry, I assumed you have the backup-battery connected and charged.

Yes, that would be a solution. :o)

(I'm not the original poster though)

Maurits. --

HiTECHnologies Industrial Automation B.V.
Industrieweg 30, 3401 MA, IJsselstein, The Netherlands
P.O. box 242, 3400 AE, IJsselstein, The Netherlands
Tel: +31 30 6875335
Fax: +31 30 6875333
E-mail: info@info...
Web: www.hitechnologies.nl

===================================================================
The information contained in this communication is confidential and may
be legally privileged. It is intended solely for the use of the
individual or entity to whom it is addressed and others authorized to
receive it. If you are not the intended recipient you are hereby
notified that any disclosure, copying, distribution or taking any action
in reliance on the contents of this information is strictly prohibited
and may be unlawful.
HiTECHnologies B.V. is neither liable for the contents, nor for the
proper, complete and timely transmission of the information contained in
this communication.
===================================================================


Reply by Daniel March 30, 20052005-03-30

Sorry, I assumed you have the backup-battery connected and charged.

--- In rabbit-semi@rabb..., Maurits van de Kamp <mvk@h...> wrote:

> When it resets, yes, but not when it powers down. Static variables are
> in ram, and it needs power to stay there.




Reply by Maurits van de Kamp March 30, 20052005-03-30
> Does using static variables solve your problem?
>
> If you have a static variable declared and then the
> board resets, it keeps its last value.

When it resets, yes, but not when it powers down. Static variables are
in ram, and it needs power to stay there.

> I am not sure,
> but I guess only changing the variable's value does
> not wear out the flash.

That's true, because it's not in the flash. :o)

Maurits.
--

HiTECHnologies Industrial Automation B.V.
Industrieweg 30, 3401 MA, IJsselstein, The Netherlands
P.O. box 242, 3400 AE, IJsselstein, The Netherlands
Tel: +31 30 6875335
Fax: +31 30 6875333
E-mail: info@info...
Web: www.hitechnologies.nl

===================================================================
The information contained in this communication is confidential and may
be legally privileged. It is intended solely for the use of the
individual or entity to whom it is addressed and others authorized to
receive it. If you are not the intended recipient you are hereby
notified that any disclosure, copying, distribution or taking any action
in reliance on the contents of this information is strictly prohibited
and may be unlawful.
HiTECHnologies B.V. is neither liable for the contents, nor for the
proper, complete and timely transmission of the information contained in
this communication.
===================================================================


Reply by Daniel T. Chaves March 30, 20052005-03-30
Does using static variables solve your problem?

If you have a static variable declared and then the
board resets, it keeps its last value. I am not sure,
but I guess only changing the variable's value does
not wear out the flash.

> From: "Tecnowatt - Massimo Sala"
>
> I read your interesting post.
>
> I need to keep "syncronized" a variable with a
> persistent copy in
> non-volatile memory.
>
> If the application halts / there is a power failure,
> when the Rabbit board
> will restart it must read the last value of the
> variable.
>
> The variable is updated about once per minute.

_____________________________________________
Daniel Teixeira Chaves
Engenheiro de Controle e Automacao
"The squid is not dead"
__________________________________



Reply by bmurthazw March 29, 20052005-03-29

--- In rabbit-semi@rabb..., "Tecnowatt - Massimo Sala"
<massimo.sala@t...> wrote:
> I read your interesting post.
>
> I need to keep "syncronized" a variable with a persistent copy in
> non-volatile memory.
>
> If the application halts / there is a power failure, when the
Rabbit board
> will restart it must read the last value of the variable.
>
> The variable is updated about once per minute. > Is writeUserBlock() the right solution ?

No, that is too frequent and will wear out the flash. Depending on
the part used, flash sectors could wear out in as few as 10,000
writes. Use battery backed RAM and 'protected' variables instead.
See reset_demo.c in the /samples folder.

>
>
> ciao, Massimo > ----- Original Message -----
> From: "bmurthazw" <bmurthazw@y...>
> To: <rabbit-semi@rabb...>
> Sent: Saturday, March 19, 2005 9:11 PM
> Subject: [rabbit-semi] Re: Writing Variables to Flash? > > Here's what I do. I just wrote this sample, didn't test it:
> >
> > #define FACTORYVALUE 0 // or whatever value you want
> >
> > // While developing, change this string to force
superinitialization
> > #define INITFLAG "This string gets written to User Block offset
0"
> >
> > //compiler puts this in flash
> > const int flashvariableTORYVALUE;
> >
> > int runtimeVariable;
> > char buffer[sizeof(INITFLAG)];
> >
> > // On program startup:
> >
> > // Check if we need SuperInitialization (1rst run)
> > if(!(readUserBlock(buffer, 0, sizeof(INITFLAG)))) {
> > if(memcmp(buffer, INITFLAG, sizeof(INITFLAG))) {
> >
> > memcpy(buffer, INITFLAG, sizeof(INITFLAG));
> > writeUserBlock(0, buffer, sizeof(INITFLAG));
> > // put variable value after init string
> > writeUserBlock(sizeof(INITFLAG),&flashvariable,sizeof
> > (flashvariable));
> >
> > }
> > }
> > else{
> >
> > // Not first run, just read variable
> > readUserBlock(runtimeVariable,sizeof(INITFLAG),sizeof
> > (runtimeVariable));
> >
> > }
> >
> > if the value gets changed, then rewrite the userblock:
> >
> > writeUserBlock(sizeof(INITFLAG),&runtimeVariable,sizeof
> > (runtimeVariable));



Reply by Tecnowatt - Massimo Sala March 29, 20052005-03-29
I read your interesting post.

I need to keep "syncronized" a variable with a persistent copy in
non-volatile memory.

If the application halts / there is a power failure, when the Rabbit board
will restart it must read the last value of the variable.

The variable is updated about once per minute. Is writeUserBlock() the right solution ? ciao, Massimo ----- Original Message -----
From: "bmurthazw" <bmurthazw@bmur...>
To: <rabbit-semi@rabb...>
Sent: Saturday, March 19, 2005 9:11 PM
Subject: [rabbit-semi] Re: Writing Variables to Flash? > Here's what I do. I just wrote this sample, didn't test it:
>
> #define FACTORYVALUE 0 // or whatever value you want
>
> // While developing, change this string to force superinitialization
> #define INITFLAG "This string gets written to User Block offset 0"
>
> //compiler puts this in flash
> const int flashvariableTORYVALUE;
>
> int runtimeVariable;
> char buffer[sizeof(INITFLAG)];
>
> // On program startup:
>
> // Check if we need SuperInitialization (1rst run)
> if(!(readUserBlock(buffer, 0, sizeof(INITFLAG)))) {
> if(memcmp(buffer, INITFLAG, sizeof(INITFLAG))) {
>
> memcpy(buffer, INITFLAG, sizeof(INITFLAG));
> writeUserBlock(0, buffer, sizeof(INITFLAG));
> // put variable value after init string
> writeUserBlock(sizeof(INITFLAG),&flashvariable,sizeof
> (flashvariable));
>
> }
> }
> else{
>
> // Not first run, just read variable
> readUserBlock(runtimeVariable,sizeof(INITFLAG),sizeof
> (runtimeVariable));
>
> }
>
> if the value gets changed, then rewrite the userblock:
>
> writeUserBlock(sizeof(INITFLAG),&runtimeVariable,sizeof
> (runtimeVariable));