flash erase on MPC5510

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

flash erase on MPC5510

Jump to solution
2,244 Views
petitbeurre
Contributor I

Hi all,

 

I am a bit confused about some point on the MPC5510 Reference Manual, about flash erase. In section 22.5.5 (Flash Erase, chapter Flash Array and Control), step 3 indicates : "Write any address in flash. This is referred to as an erase interlock write".

I do not understand what an "erase interlock write" is, and what its purpose is. Also, I've noted that if I omit this step, the erase seems to work just as fine.

 

Could someone enlighten me please?

Thanks!

Nicolas

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

You have to ensure that there's no access to flash partition which contains flash block that is being programmed or erased. Read-while-write is supported only between partitions. For example, if you erase/program block L0 or L1 or L2 or L3, then you can't access whole partition 1 (0x0000_0000 - 0x0000_BFFF) during that operation.

So, if any other tasks or interrupts access that partition during erase/program operation then it could lead to problems.

Lukas

View solution in original post

0 Kudos
6 Replies
1,846 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

take a look at this thread:

https://community.freescale.com/message/328958#328958

I posted sample code where you can find how to do interlock write. It was written for another MCU but the principle is still the same.

Lukas

0 Kudos
1,846 Views
petitbeurre
Contributor I

Hi Lukas,


Thank you for your reply.
Actually, I have already written a piece of code (very similar to yours) for flash erase. It works fine when I use it on a simple program, but I need to use it under a Real Time Operating System, and when I do the execution jumps to an address where it should not go. It is weird because it also works fine when I use step mode (when I run it with the RTOS).

Do you know if there may be some side effects because of using an RTOS (such as interrupts or something)?

Here is my code for erasing a Low address space block, assuming the block has been enabled before.

Many thanks !

/* erase a block from low adress space

* block : 0..9 */

void eraseBlock (int block) {

  /* start erase sequence */

  FLASH.MCR.B.ERS = 1;

  /* block selection for erase */

  FLASH.LMS.B.LSEL = 0b0000000000 | (1 << block);

  /* erase interlock write */

  *(unsigned int *)(0x4000 * block) = 0xffffffff;

  /* high voltage enable */

  FLASH.MCR.B.EHV = 1; 

  /* wait for done and program/erase good */

  while(!FLASH.MCR.B.DONE) {

  }

  while (!FLASH.MCR.B.PEG) {

  }

  /* high voltage disable */

  FLASH.MCR.B.EHV = 0;

  /* end of erase sequence */

  FLASH.MCR.B.ERS = 0;

  /* diselect block */

  FLASH.LMS.B.LSEL = 0b0000000000;

}

0 Kudos
1,847 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

You have to ensure that there's no access to flash partition which contains flash block that is being programmed or erased. Read-while-write is supported only between partitions. For example, if you erase/program block L0 or L1 or L2 or L3, then you can't access whole partition 1 (0x0000_0000 - 0x0000_BFFF) during that operation.

So, if any other tasks or interrupts access that partition during erase/program operation then it could lead to problems.

Lukas

0 Kudos
1,846 Views
petitbeurre
Contributor I

Okay so if I understand correctly, if the code of my application is stored in block L2 for example, this code attempts to erase block L3, this could lead to a read-while-write problem because L2 and L3 are in the same partition?

0 Kudos
1,846 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Exactly. The code must run from another partition or from RAM.

0 Kudos
1,846 Views
petitbeurre
Contributor I

Well thank you very much Lukas for having helped me on this!

0 Kudos