DataFlash is not holding data after PowertDown

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

DataFlash is not holding data after PowertDown

Jump to solution
1,161 Views
bjrajendra
Senior Contributor I

Hi,


I'm using MCP5602P, I'm trying to store data into the DataFlash Memory (0x0080_0000) and wrote a code accordingly. The value got stored as I can see it on using debugger window, Memory Block, but once the power switched off and again If I see the debugger window without running the Program, the value is not seen. My idea is, though the program was flashed newly, the debugger wont erase the DataFlash Memory. Is there any project's internal Flash settings I need to make or linker cmd file I need to edit, so that I can store the value permanantly.

I'd attached the Code for DataFlash. Kindly suggest any modifications I need to make.

Original Attachment has been moved to: FlashCode.txt.zip

Labels (1)
0 Kudos
1 Solution
687 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

this piece of code works as expected:

    unsigned int data1, data2;
    
  /* unlock */
  DFLASH.LML.R = 0xA1A11111;    //write password
  DFLASH.LML.R = 0x00000000;    //unlock all 4 16k blocks
  DFLASH.SLL.R = 0xC3C33333;    //write password
  DFLASH.SLL.R = 0x00000000;    //unlock all 4 16k blocks
 
  /* erase */  
  DFLASH.MCR.B.ERS = 1;    //erase operation
  DFLASH.LMS.R = 0xF;        //select all 4 block for erase
  *(unsigned int *)0x00800000 = 1;    //interlock write
  DFLASH.MCR.B.EHV = 1;
    while(DFLASH.MCR.B.DONE == 0);
    DFLASH.MCR.B.EHV = 0;
  DFLASH.MCR.B.ERS = 0;
 
  /* program one word */
  DFLASH.MCR.B.PGM = 1;    //program operation  
  *(unsigned int *)0x00800000 = 0xAABBCCDD;    //interlock write
  DFLASH.MCR.B.EHV = 1;
    while(DFLASH.MCR.B.DONE == 0);
    DFLASH.MCR.B.EHV = 0;
  DFLASH.MCR.B.PGM = 0;  
 
  /* program next word */
  DFLASH.MCR.B.PGM = 1;    //program operation  
  *(unsigned int *)0x00800004 = 0x11223344;    //interlock write
  DFLASH.MCR.B.EHV = 1;
    while(DFLASH.MCR.B.DONE == 0);
    DFLASH.MCR.B.EHV = 0;
  DFLASH.MCR.B.PGM = 0;  
 
  /* read */
    data1 = *(unsigned int *)0x00800000;
    data2 = *(unsigned int *)0x00800004;

If you use CodeWarrior 2.x and PEmicro debugger, notice that it does not program/erase DFlash by default. If you program new program to the device by debugger, the content of DFlash is kept.

Regards,

Lukas

View solution in original post

0 Kudos
7 Replies
688 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

this piece of code works as expected:

    unsigned int data1, data2;
    
  /* unlock */
  DFLASH.LML.R = 0xA1A11111;    //write password
  DFLASH.LML.R = 0x00000000;    //unlock all 4 16k blocks
  DFLASH.SLL.R = 0xC3C33333;    //write password
  DFLASH.SLL.R = 0x00000000;    //unlock all 4 16k blocks
 
  /* erase */  
  DFLASH.MCR.B.ERS = 1;    //erase operation
  DFLASH.LMS.R = 0xF;        //select all 4 block for erase
  *(unsigned int *)0x00800000 = 1;    //interlock write
  DFLASH.MCR.B.EHV = 1;
    while(DFLASH.MCR.B.DONE == 0);
    DFLASH.MCR.B.EHV = 0;
  DFLASH.MCR.B.ERS = 0;
 
  /* program one word */
  DFLASH.MCR.B.PGM = 1;    //program operation  
  *(unsigned int *)0x00800000 = 0xAABBCCDD;    //interlock write
  DFLASH.MCR.B.EHV = 1;
    while(DFLASH.MCR.B.DONE == 0);
    DFLASH.MCR.B.EHV = 0;
  DFLASH.MCR.B.PGM = 0;  
 
  /* program next word */
  DFLASH.MCR.B.PGM = 1;    //program operation  
  *(unsigned int *)0x00800004 = 0x11223344;    //interlock write
  DFLASH.MCR.B.EHV = 1;
    while(DFLASH.MCR.B.DONE == 0);
    DFLASH.MCR.B.EHV = 0;
  DFLASH.MCR.B.PGM = 0;  
 
  /* read */
    data1 = *(unsigned int *)0x00800000;
    data2 = *(unsigned int *)0x00800004;

If you use CodeWarrior 2.x and PEmicro debugger, notice that it does not program/erase DFlash by default. If you program new program to the device by debugger, the content of DFlash is kept.

Regards,

Lukas

0 Kudos
687 Views
bjrajendra
Senior Contributor I

Nice to see you answering to my question. Still I'm not able to see the value in that DFlash address once the power goes off. I'm using FreeScale CodeWarrior IDE 5.9 & PE Micro USB Multilink Interface. Is there anythink I need to change in my linker file or configuration settings.

0 Kudos
687 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

I can't see any reason for this. If you use CodeWarrior 2.x or 10.x then it does not touch data flash by default. So, you should see that the data are still present in data flash even if you load new program to flash using debugger from CodeWarrior or if you just turn off and then turn on the power.

Regards,

Lukas

0 Kudos
687 Views
bjrajendra
Senior Contributor I

Hi,

Once again thank you for your reply and your interest. Actually If I load a new program without turning OFF the MCU, the data is still there in DFlash memory. But once I turn off the MCU and load the program, the values didn't exist in DFlash memory location. My question is, it is a Flash memory and stores the value eventhough there is a power off. 

Do I need to add any additional initializations other than clock? or any Debug configurations I need to edit ?

Thanks & Regards,

BJ RAJENDRANATH

0 Kudos
687 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

No other settings are necessary. If you enter debug mode during reset (so no code is executed) and if you just check the content of memory in your debugger, you should see the content of flash. That means there's nothing to configure. There's e200z0 core on this device, so there's no even MMU which needs to be initialized like on other cores.

Regards,

Lukas

0 Kudos
687 Views
bjrajendra
Senior Contributor I

Any Internal Flash settings to be configured ?

0 Kudos
687 Views
bjrajendra
Senior Contributor I

No one turned out to answer. Can anyone suggest things to be modified in my code. Awaiting for the reply.

0 Kudos