Sample code to erase flash of MPC5674F

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

Sample code to erase flash of MPC5674F

4,102 Views
snehakalkhair
Contributor III


Hi,

Can anyone please help me with a sample code for how to erase the flash?

Also would like to understand the use of Flash A and Flash B.

Also what is shadow flash.

 

Regards,

Sneha.

Labels (1)
Tags (2)
24 Replies

2,651 Views
stanish
NXP Employee
NXP Employee

Hello Sneha,

This message does not seem to be related to the fact the evaluation version has expired. Plus if your C project has below 512 KB of object code you should be able to use it anyway.

There is probably a different issue - can you check your connection with the target? does both LEDs (blue/yellow) on your pemicro multilink are on?

Can you check to debug an empty project on a different MPC56xx board (if you have any).

If your MCU is in the socket I'd recommend you to push and release socket several times to ensure there is a good connection between the MCU and the socket pins.

Hope it helps.

Stan

0 Kudos

2,651 Views
snehakalkhair
Contributor III

Hi Stan,

Both the LEDs are ON.

All the connectivity is proper.

The code can be debug and executed on MPC5676R.

The Device is censored error occurs when I try to execute the code on MPC5674F.

Please help me with the process or code to get the password to uncensor the device.

I have the document AN3787 but i am unable to understand where do we get the control word from.

Will you please help me with the code to uncensor the device.

0 Kudos

2,651 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

if the device is unintentionally secured (i.e. the shadow flash has been erased but censorship control word has not been restored or wrong values have been programmed) then the device is locked forever. There's no way to unsecure the device.

The only option is that you would have to implement some kind of backdoor access BEFORE ( !!! ) the device is secured.

Do you have spare MPC5674F? Have you tried to replace the chip?

Lukas

0 Kudos

2,651 Views
snehakalkhair
Contributor III

Hi Lukas,

No we do not have a spare MPC5674F.

I have tried flashing the same program you provided for flash erase.

0 Kudos

2,651 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

the best way is to use SSD flash drivers:

http://www.nxp.com/lgfiles/Qorivva/MPC5674F_C90FL_SSD_DRV.exe

User manual and examples are included in the package.

Notice that the flash memory is interleaved in high address space. That means first 16 bytes belong to flash block A, next 16 bytes to flash block B, next 16 bytes to flash block A and so on… This increases the performance. But you must be aware of this when programming the flash and it is necessary to distinguish which flash block should be programmed. The SSD drivers do this internally, you don't need to take care of it.

Attached is simple example I found in my repository (pure C code without SSD drivers).

Shadow flash contains some configuration data and space for general use. Take a look at Table 11-2:

http://www.nxp.com/files/32bit/doc/ref_manual/MPC5674FRM.pdf

The most important information is that there's censorship control word. Big warning here: if you erase the shadow flash and if you don't restore censorship control word and password appropriately (or if you program wrong data), the chip will be locked forever!!!

Read this application note:

http://www.nxp.com/files/32bit/doc/app_note/AN3787.pdf

Regards,

Lukas

2,651 Views
hyenongijeong
Contributor III

Hi Lukas,

I have a question.

Your sample code and SSD code works good in Mid and High address area.

But it doesn't work in Low address area. 

Does it need different code? or Need other setting?

Thank you,

Regard Henk.

0 Kudos

2,651 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

how did you modify the code? Could you share it?

Regards,

Lukas

0 Kudos

2,651 Views
hyenongijeong
Contributor III

Hi,

Thank you for fast reply :smileyhappy:

There are my modified code.

/* unlock L0 in flash array A */
FLASH_A.LMLR.R = FLASH_LMLR_PASSWORD;
FLASH_A.LMLR.R = 0x00130000;

/* erase L0 */
FLASH_A.MCR.B.ERS = 1;
FLASH_A.MCR.B.ESUS = 0;
FLASH_A.LMSR.R = 0x000003FF; /* select L0 only */
*(unsigned int *)0x00000000 = 0xFFFFFFFF; /* interlock write */
FLASH_A.MCR.B.EHV = 1; /* start erase */
while(FLASH_A.MCR.B.DONE == 0){}; /* wait for done */
FLASH_A.MCR.B.EHV = 0;
FLASH_A.MCR.B.ERS = 0;
if(FLASH_A.MCR.B.PEG == 0)
return 1; /* return error if PEG was not set */

/* program L0 (one word only) */
FLASH_A.MCR.B.PGM = 1;
FLASH_A.MCR.B.PSUS = 0;
*(unsigned int *)0x00000000 = 0xAABBCCDD; /* interlock write */
FLASH_A.MCR.B.EHV = 1; /* start programming */
while(FLASH_A.MCR.B.DONE == 0){}; /* wait for done */
FLASH_A.MCR.B.EHV = 0;
FLASH_A.MCR.B.PGM = 0;
if(FLASH_A.MCR.B.PEG == 0)
return 2; /* return error if PEG was not set */

Regards,

Henk

0 Kudos

2,651 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

First thing I can see - there's LMLR register which is used for unlocking and there's also secondary register SLMLR. If you want to unlock a block in low/mid space, you have to unlock the block in both unlock registers.

I can see that you unlock the block only in LMLR. Try to do the same also in SLMLR.

Regards,

Lukas

2,651 Views
hyenongijeong
Contributor III

Hi,

Thank you. It works good. But still some area is not erase.

Under highlight area are not erase.

5674F_FLASH_2.png

There are my source code.

It does not response line 12.

/* unlock L0 in flash array A */
FLASH_A.LMLR.R = FLASH_LMLR_PASSWORD;
FLASH_A.LMLR.R = 0x00130000;
FLASH_A.SLMLR.R = FLASH_SLMLR_PASSWORD;
FLASH_A.SLMLR.R = 0x00130000;

/* erase L0 */
FLASH_A.MCR.B.ERS = 1;
//FLASH_A.MCR.B.ESUS = 0;
FLASH_A.LMSR.R = 0x00000300; /* select L0 only */
*(unsigned int *)0x00000000 = 0x0; /* interlock write */
FLASH_A.MCR.B.EHV = 1; /* start erase */
while(FLASH_A.MCR.B.DONE == 0){}; /* wait for done */   <==== Hangup ( interrupt 13 TLB Error )
FLASH_A.MCR.B.EHV = 0;
FLASH_A.MCR.B.ERS = 0;
if(FLASH_A.MCR.B.PEG == 0)
return 1; /* return error if PEG was not set */

/* program L0 (one word only) */
FLASH_A.MCR.B.PGM = 1;
//FLASH_A.MCR.B.PSUS = 0;
*(unsigned int *)0x00020000 = 0xAABBCCDD; /* interlock write */
FLASH_A.MCR.B.EHV = 1; /* start programming */
while(FLASH_A.MCR.B.DONE == 0){}; /* wait for done */
FLASH_A.MCR.B.EHV = 0;
FLASH_A.MCR.B.PGM = 0;
if(FLASH_A.MCR.B.PEG == 0)
return 2; /* return error if PEG was not set */

Regards,

Henk

0 Kudos

2,651 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

this piece of code works fine on my side. How did you configured MMU? If you got TLB error, you have to check MMU settings.

Regards,

Lukas

0 Kudos

2,651 Views
hyenongijeong
Contributor III

Hi,

This is our mmu table settings.

/*
Device MMU table:
---------------------------------------------------------
Name: TLB entry Start Length
---------------------------------------------------------
FLASH 0 0x0000_0000 4MB
SRAM 1 0x4000_0000 256KB
SHADOW 2 0x00FF_C000 16KB
EBI 3 0x2000_0000 512KB
PBRIDGEA 4 0xC3F0_0000 1MB
PBRIDGEB + BAM 5 0xFFE0_0000 2MB
---------------------------------------------------------
*/

We set only Shadow A block in MMU table. Do I need to set Shadow B block in MMU table?

Thanks you,

regards,

Henk

0 Kudos

2,651 Views
hyenongijeong
Contributor III

I am still waiting answer of this issue...

Our system occurs tlb error (ivor13) or illigal error (ivor6).

0 Kudos

2,651 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

I'm sorry for delay, I'm out of office now.

No, it is not necessary to set MMU page for shadow block B. I'm not sure what's wrong when reading your description. Could you share your project to be able to duplicate the problem? It will require some debugging...

Regards,

Lukas

0 Kudos

2,651 Views
hyenongijeong
Contributor III

Hi,

Of course, I am very grateful if you could debug me.

This is our project code for Code Warrior Development Studio.

The project is the default program created by Code Warrior right now and added the test code.

FLASH_TEST_5674F.zip - Google Drive 

And our test environment is EVKit (MPC567XEVBMB-MPC567XADAT516).

Thank you,

Regards

Henk

0 Kudos

2,651 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

I'm not able to download the file. Could you attach it here? It is necessary to click on "Use advanced editor" on the right side when you writing new post and you can add attachment there.

Lukas

0 Kudos

2,651 Views
hyenongijeong
Contributor III

Hi,

I attached it.

Thank you.

your support.

Regards

Henk.

0 Kudos

2,651 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi Henk,

the RAM target is working, I can see that flash is erased and 0xAABBCCDD is successfully programmed at  0x30000.

If I select flash target, the code is running from addresses around 0x30000. So, you can NOT erase these blocks.

Regards,

Lukas

0 Kudos

2,651 Views
hyenongijeong
Contributor III

Hi Lukas,

Thank you for giving me a lot of help.

In CodeWarrior setting, the corresponding part was found and corrected.

The code area was moved from 0x30000 to 0x2000 to verify that the area was deleted.

Then of course, 0x2000 area  is not erased.

So, Can I move the code area from FLASH to RAM?

Is it possible?

My final goal is to download and replace FLASH Image during System working.

Thank you,

regards Henk.

0 Kudos