Thanks for your help. The answer is right.
However, now I am trying to modify the values of another memory area, and I am getting the same problem, the LME bit is always 0. In addition, when the code gets to "CFLASH.MCR.B.ERS = 1;" line, it jumps to an address that there is nothing and it gets stuck there. This is the new code:
CFLASH.LML.R = 0xA1A11111; /* write password */
CFLASH.LML.R = 0x0011003F; /* unlock MLK1 only */
status= CFLASH.LML.B.LME;
status= CFLASH.LML.B.MLK;
/* erase block MLK1 (0x0006_0000 - 0x0007_FFFF) */
CFLASH.MCR.B.ERS = 1;
CFLASH.LMS.R = 0x00020000; /* select MLK1 */
*(unsigned int *)0x0007FFF0 = 0xFFFFFFFF; /* interlock write - write to any address in selected memory */
CFLASH.MCR.B.EHV = 1;
while(CFLASH.MCR.B.DONE == 0);
CFLASH.MCR.B.EHV = 0;
CFLASH.MCR.B.ERS = 0;
/* program double word to MLK1*/
CFLASH.MCR.B.PGM = 1;
*(unsigned int *)0x0007FFF8 = 0xFFFF2222; /* interlock write */
*(unsigned int *)0x0007FFFC = 0xFFFF0000; /* program data write */
CFLASH.MCR.B.EHV = 1;
while(CFLASH.MCR.B.DONE == 0);
CFLASH.MCR.B.EHV = 0;
CFLASH.MCR.B.PGM = 0;
Do you have any clue why I am getting so many problems?
Thanks in advance,