EmbeddedRelated.com
Forums

Re: saving structure to flash memory

Started by Preston Gurd May 10, 2006

Hello John,

Once flash memory has been initialized, it essentially becomes
"write-once"
memory until it is initialized again.

So, once you have initialized a segment (128 bytes if info memory or
512 bytes otherwise) you can use a similar structure assignment to
place your data in flash. For instance, you might write something like

 	void StoreConfigData(ConfigData *configData)
 	{
 		InitializeFlashSegment( SYSCONFIG_BASE_A );
    		*(ConfigData *)(SYSCONFIG_BASE_A + 2) = *configData;
	}

Hope this helps..

Preston

> 
> preston,
> thanks for your help.  is there an easy way to save the data from 
> the structure to flash memory or do i have to do it piece by piece 
> as below?
> 
> WriteToFlash(configData->curHour);
> WriteToFlash(configData->curMin);
> WriteToFlash(configData->startHour);
> WriteToFlash(configData->endHour);
> //..rest of the saves
> 
> 
> 
> --- In msp430@msp4..., Preston Gurd <rpgurd@...> wrote:
> >
> > 
> > 
> > Hello John,
> > 
> > The problem you have observed is in fact a bug.
> > This will be fixed ASAP and I will offer
> > you an updated version, as soon as it is ready.
> > 
> > However, from looking at your code, it seems evident to me that
> > what you are doing is copying a structure piece by piece from flash
> > to RAM. You could do this same job, without having to provide the 
> impressive
> > sequence of #define directives, by writing the LoadConfigData 
> function
> > as follows:
> > 
> > 	void LoadConfigData(ConfigData *configData)
> > 	{
> >     		*configData = *(ConfigData *)(SYSCONFIG_BASE_A + 2);
> > 	}
> > 
> > All the best,
> > 
> > Preston Gurd
> > (the AQ430 C compiler guy)
> > 	

Beginning Microcontrollers with the MSP430