When to write to NVM

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

When to write to NVM

727 Views
rmaier
Contributor III

I'll get straight to the question: Is there anything wrong with writing to unwritten flash at any time? That is to say, we have a sector that has been erased, I want to write to a "virgin" portion of this sector at any time even after a reset/power-up. Basically, write to any flash bytes that are still set to 0xFF in a predefined sector?

I am working with a KEA64 MCU. I need to write a small amount of data to flash frequently. I've got plenty of flash space to spare. I could use one or more sectors, and write to them sequentially. Once a sector is filled, it gets erased and put to the end of the write queue. The theory is that writing 8 bytes sequentially get me 64 writes per deteriorating erase/write cycle, thus extending my usable "write" cycles from a minimum of 10k to 640k.

Is there any reason this would not work, or is not favorable?

0 Kudos
2 Replies

561 Views
mjbcswitzerland
Specialist V

Hi

you need to write long words (rather than individual bytes) but the technique is correct as you describe it.

In the uTasker project this is one of the strategies integrated into the frame work (the one called USE_PARAMETER_AREA in the parameter configuration options below)

#define USE_PARAMETER_BLOCK                 // enable a parameter block for storing and retrieving non-volatile information
    #define USE_PAR_SWAP_BLOCK              // we support a backup block which can be restored if desired (it is recommended to use this together with USE_PARAMETER_BLOCK
  //#define PARAMETER_NO_ALIGNMENT          // the driver doesn't need to respect byte write restrictions since the application does - this can improve memory utilisation when bytes writes are not supported by the hardware
//#define USE_PARAMETER_AREA                // simple parameter area rather than parameter block


When USE_PARAMETER_AREA is enabled, the following API calls are available which manage it this way and is compatible for any Kinetis part (the user defines the Flash sectors making up the area):

// Called to retrieve the valid block of parameters from the parameter area
//
extern int fnGetPar(unsigned short usParameterReference, unsigned char *ucValue, unsigned short usLength);

// Called to set a byte or block of bytes to a parameter block
//
extern int fnSetPar(unsigned short usParameterReference, unsigned char *ucValue, unsigned short usLength);

// Called to delete a block in the parameter block or to manipulate parameter block itself
//
extern int fnDelPar(unsigned char ucDeleteType);


Regards

Mark

http://www.utasker.com/kinetis/TRK-KEA64.html
http://www.utasker.com/kinetis/FRDM-KEAZ64Q64.html

0 Kudos

561 Views
rmaier
Contributor III

Great. Thanks for the advice, Mark.

0 Kudos