FlexNVM and EEEPROM Functionality Clarifications Needed.

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

FlexNVM and EEEPROM Functionality Clarifications Needed.

1,725 Views
m4l490n
Contributor V

I'm reading the Using Kinetis FlexMemory as enhanced EEPROM App note and I have a little confusion. I read that:

When the EEE is accessed, the EEE state machine keeps track of the data and backs it up as data records, stored in some portion of the FlexNVM used as an E-flash ...

The data records are written and erased as needed. This means that if a location within the EEPROM has never been accessed, there will not be a data record for it. This helps to reduce the amount of data that needs to be backed up and can increase the memory endurance.

The appnote mentions that any reads and writes to EEE will use the FlexRAM since E-flash is not accessible and that the EEE state machine will manage reads and writes to flash.

What I don't understand is how often the data will be transferred from FlexRAM to the E-flash. For example, if I define 64 bytes as EEEPROM (without splits), does that mean that the EEE state machine will only transfer the FlexRAM to E-flash UNTIL I write 64 bytes to it?

If that's true, then if I have written just 20 bytes to the EEEPROM (FlashRAM) and I lose power then I will lose those 20 bytes which is not right.

Is this right (I kinda feel it isn't but I'm not sure)

0 Kudos
3 Replies

1,705 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi m4l490n,

    In fact, to the customer, just need to partition the FlexNVM, to define the related EEPROM size, the backup size, please note, the EEPROM backup size must be at least 16 times the EEPROM partition size in the flexRAM.

kerryzhou_0-1618205892762.png

Then, the customer just need to operate the flexRAM address as the eeprom address is OK.

kerryzhou_1-1618205941132.png

I don't know which kinetis chip you are using, give you an example:

#define LONGWORD_COUNTER_ADDR 0x14000040
#define WORD_COUNTER_ADDR 0x14000044
#define BYTE_COUNTER_ADDR 0x14000046


//#define WORD_COUNTER_ADDR_TEST 0x10000000

int partition_flash(int eeprom_size, int dflash_size)
{
      /* Test to make sure the device is not already partitioned. If it
       * is already partitioned, then return with no action performed.
       */
      if ((SIM_FCFG1 & SIM_FCFG1_DEPART(0xF)) != 0x00000F00)
      {
          printf("\nDevice is already partitioned.\n");
          return 0;
      }

      /* Write the FCCOB registers */
      FTFL_FCCOB0 = FTFL_FCCOB0_CCOBn(0x80); // Selects the PGMPART command
      FTFL_FCCOB1 = 0x00;
      FTFL_FCCOB2 = 0x00;
      FTFL_FCCOB3 = 0x00;

      /* FCCOB4 is written with the code for the subsystem sizes (eeprom_size define) */
      FTFL_FCCOB4 = eeprom_size;

      /* FFCOB5 is written with the code for the Dflash size (dflash_size define) */
      FTFL_FCCOB5 = dflash_size;


      /* All required FCCOBx registers are written, so launch the command */
      FTFL_FSTAT = FTFL_FSTAT_CCIF_MASK;

      /* Wait for the command to complete */
      while(!(FTFL_FSTAT & FTFL_FSTAT_CCIF_MASK));

      return 1;
}

int main (void)
{
	char ch;
    uint32 temp=0;
#ifdef KEIL
	start();
#endif
  	printf("\nRunning the hello_world project in K2050MHz family\n");
  	
  	SCB_SHCSR|=SCB_SHCSR_BUSFAULTENA_MASK|SCB_SHCSR_MEMFAULTENA_MASK|SCB_SHCSR_USGFAULTENA_MASK;
  	  	printf("\nRunning FlexMem demo!!\n");
  	        /* Partition the memory to enable FlexMem mode */
  	        if ( partition_flash( 0X33, 0X03) )//0X03
  	        {
  	            /* Device has been partitioned for the first time, so this
  	             * means the counters have not been initialized yet. We'll
  	             * zero them out now.
  	             */
  	            *((uint32 *)(LONGWORD_COUNTER_ADDR)) = 0x0;

  	            /* Wait for the command to complete */
  	            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

  	            *((uint16 *)(WORD_COUNTER_ADDR)) = 0x0;

  	            /* Wait for the command to complete */
  	            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

  	            *((uint8 *)(BYTE_COUNTER_ADDR)) = 0x0;

  	            /* Wait for the command to complete */
  	            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));
  	        }
  	        
  	        
//Write eeprom
	            *((uint32 *)(LONGWORD_COUNTER_ADDR)) = 0x0;

	            /* Wait for the command to complete */
	            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

	            *((uint16 *)(WORD_COUNTER_ADDR)) = 0x0;

	            /* Wait for the command to complete */
	            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

	            *((uint8 *)(BYTE_COUNTER_ADDR)) = 0x0;

	            /* Wait for the command to complete */
	            while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));
	  	        printf("\nlongword counter = 0x%08X", *(uint32 *)(LONGWORD_COUNTER_ADDR));
	  	        printf("\nword counter = 0x%04X", *(uint16 *)(WORD_COUNTER_ADDR));
	  	        printf("\nbyte counter = 0x%02X", *(uint8 *)(BYTE_COUNTER_ADDR));
  	        ////////////////////////
  	      /* Make sure the EEE is ready. If not wait for the command to complete */
  	      while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

  	      temp = *((uint32 *)(LONGWORD_COUNTER_ADDR));
  	      *((uint32 *)(LONGWORD_COUNTER_ADDR)) = (uint32) temp + 1;

  	      /* Make sure the EEE is ready. If not wait for the command to complete */
  	      while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

  	      temp = *((uint16 *)(WORD_COUNTER_ADDR));
  	      *((uint16 *)(WORD_COUNTER_ADDR)) = (uint16) temp + 1;

  	      /* Make sure the EEE is ready. If not wait for the command to complete */
  	      while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));

  	      temp = *((uint8 *)(BYTE_COUNTER_ADDR));
  	      *((uint8 *)(BYTE_COUNTER_ADDR)) = (uint8) temp + 1;

  	      /* Make sure the EEE is ready. If not wait for the command to complete */
  	      while(!(FTFL_FCNFG & FTFL_FCNFG_EEERDY_MASK));
  	      

  	        /* Display the initial counter values */
  	        printf("\nlongword counter = 0x%08X", *(uint32 *)(LONGWORD_COUNTER_ADDR));
  	        printf("\nword counter = 0x%04X", *(uint16 *)(WORD_COUNTER_ADDR));
  	        printf("\nbyte counter = 0x%02X", *(uint8 *)(BYTE_COUNTER_ADDR));

  	  	printf("\nRunning FlexMem demo!!end\n");  
	while(1)
	{
		ch = getchar();
		putchar(ch);
	} 
}

 

When you want to use the 64byte eeprom, you just need to operate the flexRAM, you don't need to care about the related flexNVM flash after you already partition it, the chip hardware will do it automatically.

As you know, EEPROM can be byte operation, so if you just write 20bytes, it will contains 20 bytes, not which you needed whole 64 bytes.

Wish it helps you!

If you still have questions about it, please kindly let me know.

Best Regards,

kerry

0 Kudos

1,684 Views
m4l490n
Contributor V

@kerryzhou 

Thanks for helping.

So, if I understood correctly, as soon as I write one byte to the FlexRAM, is the processor going to invoke the EEPROM file system to program this new byte in the EEPROM backup memory (FlexNVM EEPROM partition)?

0 Kudos

1,678 Views
kerryzhou
NXP TechSupport
NXP TechSupport

 

Hi m4l490n,

  Please check your mentioned application note, chapter 2.1 How FlexMemory EEE works

The FlexRAM address space is where you access all of your EEE data. When the EEE
is accessed, the EEE state machine keeps track of the data and backs it up as data records, stored in some portion of the FlexNVM used as an E-flash. Using a large block of E-flash to back up the data for a smaller amount of EEE data allows the FlexMemory EEE implementation to offer extremely high endurance.

 

So, even you write one byte, the EEPROM still will save it to the related flash and the backup flash, which you don't need to care, if you don't believe it, you can try just write one byte, power off the chip, then power on the chip again, readout your eeprom related address, you will find your one byste still there, as your know, RAM will lost the data after power off, so it is mainly use the flash to store your data.

 

Wish it helps you!

Best Regards,

kerry

0 Kudos