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