MC5604P - In Application Programming - erase/modify Code Flash

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

MC5604P - In Application Programming - erase/modify Code Flash

Jump to solution
1,121 Views
steffenrose
Contributor III

Hello,

 

I want to implement a Bootloader. But my implementation of the Erase and Flash functionality will not work.

I'm wondering that it is not working (possible) AND no error bit is set (why?).

 

The next function should flash some test data to the Code Flash at 0x0000.8000. This area is erased.

The function is located in RAM (0x4000.00A8).

 

#pragma section RX ".ramfunction" ".ramfunction" data_mode=far_abs code_mode=far_abs

 

__declspec(section ".ramfunction") void write(void);

void write(void)

{

    //CFLASH.MCR.R = 0x10;

    CFLASH.MCR.B.PGM = 1; //double word / 8 Byte

   

     *(U32*)0x8000 = 0x11223344;

     *(U32*)0x8004 = 0x11223344;

 

    //CFLASH.MCR.R = 0x11;

    CFLASH.MCR.B.EHV = 1; /* start program */

    while (CFLASH.MCR.B.DONE == 0)

        {

            ;

        }

    //CFLASH.MCR.R = 0x10;

    CFLASH.MCR.B.EHV = 0; /* stop program */

 

    //CFLASH.MCR.R = 0x00;       

    CFLASH.MCR.B.PGM = 0;

}

 

CFLASH_LMLR->LME - Lock is disabled

CFLASH_SLMLR->SLE - Lock is disabled

 

I'm the meaning this sequence ist described in MPC560XPRM.pdf / 17.3.8.1.1 Double word program.

 

Hope anybody can tell me my mistake or ideas to check additional prerequirements. Also an example Sourcecode for the CodeWarrior 5.9 would be nice.

Thank you very much.

bye

Steffen

Labels (1)
Tags (1)
0 Kudos
1 Solution
702 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

there's nothing wrong in your code snippet. If no error bits are set, it is related to locking mechanism most likely. I have this minimalist code that works as expected (executed from RAM):

int main(void) {

    volatile int i = 0;

     

    /* unlock all blocks */

    CFLASH.LML.R = 0xA1A11111; /* write password */

    CFLASH.LML.R = 0x00100000; /* unlock low and mid blocks primary */

    CFLASH.SLL.R = 0xC3C33333; /* write password */

    CFLASH.SLL.R = 0x00100000; /* unlock low and mid blocks secondary */

    /* erase block B0F1 (0x0000_8000 - 0x0000_BFFF) */

    CFLASH.MCR.B.ERS = 1;

    CFLASH.LMS.R = 0x00000002; /* select B0F1 */

    *(unsigned int *)0x00008000 = 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 B0F1 */

    CFLASH.MCR.B.PGM = 1;

    *(unsigned int *)0x00008000 = 0xAABBCCDD; /* interlock write */

    *(unsigned int *)0x00008004 = 0x11223344; /* program data write */

    CFLASH.MCR.B.EHV = 1;

    while(CFLASH.MCR.B.DONE == 0);

    CFLASH.MCR.B.EHV = 0;

    CFLASH.MCR.B.PGM = 0;

  /* Loop forever */

  for (;;) {

    i++;

  }

}

Could you give this a try?

Regards,

Lukas

View solution in original post

3 Replies
703 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

there's nothing wrong in your code snippet. If no error bits are set, it is related to locking mechanism most likely. I have this minimalist code that works as expected (executed from RAM):

int main(void) {

    volatile int i = 0;

     

    /* unlock all blocks */

    CFLASH.LML.R = 0xA1A11111; /* write password */

    CFLASH.LML.R = 0x00100000; /* unlock low and mid blocks primary */

    CFLASH.SLL.R = 0xC3C33333; /* write password */

    CFLASH.SLL.R = 0x00100000; /* unlock low and mid blocks secondary */

    /* erase block B0F1 (0x0000_8000 - 0x0000_BFFF) */

    CFLASH.MCR.B.ERS = 1;

    CFLASH.LMS.R = 0x00000002; /* select B0F1 */

    *(unsigned int *)0x00008000 = 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 B0F1 */

    CFLASH.MCR.B.PGM = 1;

    *(unsigned int *)0x00008000 = 0xAABBCCDD; /* interlock write */

    *(unsigned int *)0x00008004 = 0x11223344; /* program data write */

    CFLASH.MCR.B.EHV = 1;

    while(CFLASH.MCR.B.DONE == 0);

    CFLASH.MCR.B.EHV = 0;

    CFLASH.MCR.B.PGM = 0;

  /* Loop forever */

  for (;;) {

    i++;

  }

}

Could you give this a try?

Regards,

Lukas

702 Views
steffenrose
Contributor III

Hello Lukas,

thank you very much for your help! It works.

/* unlock all blocks */

    CFLASH.LML.R = 0xA1A11111; /* write password */

    CFLASH.LML.R = 0x00100000; /* unlock low and mid blocks primary */

    CFLASH.SLL.R = 0xC3C33333; /* write password */

    CFLASH.SLL.R = 0x00100000; /* unlock low and mid blocks secondary */

was the required action. But why?

The password are only describt for the nonvolatile registers. (MPC560XPRM.pdf)

The LME bit is read as 0 before this action, too.

Is the Lock of the Shadow region the relevant point?

But it should not be locked, because the LME bit is 0.

Or is it possible, that the P&E Debugger show the wrong value for this register.

CFLASH_LMLR->LME - Lock is disabled

I'm confusing.

How long is the unlock active?

bye

Steffen

0 Kudos
702 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Steffen,

yes, I can see now that the description in reference manual is confusing.

There are two options how to initialize the locking bits:

1. You can modify corresponding word in shadow flash and the value from shadow flash will be automatically copied to LML register during reset. You do not need to take care about password in this case.

2. Second options is identical to the code I sent you earlier. Write password to LML and then you can modify the locking bits in LML as needed until next reset.

Regards,

Lukas