MPC5634M programming the flash section

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

MPC5634M programming the flash section

Jump to solution
2,192 Views
buraksoner
Contributor II

Hello there,

 

I'm working on programming the flash of an MPC5634M. Specifically the CFLASH0 section. info on my project:

 

ProjectName

     a.c

     a.h

     b.c

     b.h

     ...

 

Contents of a.c:

 

uint32_t value_val = 40;

 

Contents of a.h:

 

extern uint32_t value_val;

 

Contents of b.c

 

void Nvm_ProgFlash (uint32_t* address, uint32_t value)

{

  uint32_t tmp = 0;

  uint32_t status = 0;

 

  CFLASH0.LMLR.R = 0xA1A11111; // password..

  CFLASH0.LMLR.B.LLOCK = 0x7F; // unlock block 5. Others are locked

  CFLASH0.SLMLR.R = 0XC3C33333; // password..

  CFLASH0.SLMLR.B.SLLOCK = 0x7F; // unlock block 5. Others are locked

 

// Erase Routine

  CFLASH0.MCR.B.ERS = 1;

  CFLASH0.LMSR.R = 0x00000080;

  *(unsigned int *)0x00038928 = 0xFFFFFFFF;

  CFLASH0.MCR.B.EHV = 1;

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

  status = CFLASH0.MCR.B.PEG & 0x00000200;

  CFLASH0.MCR.B.EHV = 0;

  CFLASH0.MCR.B.PGM = 0;

 

// Program Routine

  CFLASH0.MCR.B.PGM = 1;

  *(unsigned int *)0x00038928 = value;

  *(unsigned int *)(0x00038928 + 0x4) = value;

  CFLASH0.MCR.B.EHV = 1;

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

  status = CFLASH0.MCR.B.PEG & 0x00000200;

  CFLASH0.MCR.B.EHV = 0;

  CFLASH0.MCR.B.PGM = 0;

 

}

 

Contents of b.h:

 

void Nvm_ProgFlash(uint32_t);

 

And I'm calling the function in b.c as Nvm_ProgFlash(60); in main. When I build the project I check the ProjecName.MAP and the ProjectName.MOT files, the object value_val is located at the address 0x00038928.

 

With regards to the reference manual, this seems to be all that I need to program the relevant flash address. The program gets stuck in   while ((CFLASH0.MCR.B.DONE == 0));  during the erase routine. Am I missing something basic here or is there something additional that needs to be done?

 

Thanks in advance for the help,

Burak

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

Where the code is running from? Read-While-Write is supported only between banks. We should not access flash bank during erase/program operation. So, the code should be executed from RAM or from another bank. I guess this is the reason.

The code itself works fine on my side.

Lukas

View solution in original post

10 Replies
1,733 Views
sufree
Contributor II

Hello ,

I face the question as follow:when debugging ,when run :

/* step2. program data */
CFLASH0.MCR.B.PGM = 1; // select operation
*((unsigned int*) 0x00038928) = 0x66AA66AA; // first write
*((unsigned int*) 0x00038928+0x4) = 0x11BB11BB; // additional write

 the program break and into :QQ图片20160904211500.png

I need some about it,Thanks.

0 Kudos
1,733 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

where the code is running from? Read-While-Write is supported only between banks, so you are not allowed to access bank which is currently being erased or programmed. Address 0x0003_8928 belongs to bank 0, so the code must run from bank 1 (high address space) or from RAM.

Regards,

Lukas

0 Kudos
1,733 Views
sufree
Contributor II

Hi thanks,

I'm just a beginner.I don't know where the code is running from.My program about array1 and array2 can run normally.so i guess the code run from bank0. I try to change the address about internal_flash:     org = 0x000C0000,   len = 0x0017E000. but in vain. can you give me some detailed explanation .

0 Kudos
1,733 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

I can see two problems in the project you attached.

1. Linker file - you can't use "myram:                 org = 0x40018000,   len = 0x00001000"

That's out of RAM. There's only 94KB: 0x4000_0000 - 0x4001_77FF.

You can use:

internal_ram:          org = 0x40000000,   len = 0x00013000
    myram:                 org = 0x40013000,   len = 0x00001000
    
    heap  :                org = 0x40014000,   len = 0x00002000
    stack :                org = 0x40016000,   len = 0x00001800

2. Function Program_FLASH_A0:

*((unsigned int*) 0x00038928) = 0x66AA66AA;        // first write
*((unsigned int*) 0x00038932) = 0x11BB11BB;        // additional write

- this is wrong. 0x00038928 + 4 = 0x0003892C. It is not 0x00038932.

Correct way is:

*((unsigned int*) 0x00038928) = 0x66AA66AA;        // first write
*((unsigned int*) 0x0003892C) = 0x11BB11BB;        // additional write

If I change these two things, it works...

Regards,

Lukas

0 Kudos
1,733 Views
sufree
Contributor II

Hi Lukas,

     I do as you say,it works.

     Thank you very much.

    Regards,

       su

    

0 Kudos
1,733 Views
buraksoner
Contributor II

Hello Lukas,

I thought I was running it from bank 1 but it wasn't. Moved it to a new RAM section I defined. It solved the problem.

Thanks a lot for the help!

Regards,

Burak

0 Kudos
1,733 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Hi,

there's a typo:

pastedImage_0.png

You have to clear ERS bit. Then it will work.

Regards,

Lukas

1,733 Views
buraksoner
Contributor II

Hello Lukas,

Thanks for pointing the typo out. But that seems to be irrelevant to my problem. The code gets stuck in the "while" before that line. I've realized something more about this: I think I get stuck in that while (erase is not done) because after setting the EHV bit I get a read while write error (I've seen this at the MCR register). Please see screenshot below:

rwe.png

I don't have any other interrupts etc. running in the background though. This function is called in main after the watchdog disable and PLL init so there should be no interrupts/flashreads that I've

Is there maybe a configuration problem in this?

Regards,

Burak

0 Kudos
1,734 Views
lukaszadrapa
NXP TechSupport
NXP TechSupport

Where the code is running from? Read-While-Write is supported only between banks. We should not access flash bank during erase/program operation. So, the code should be executed from RAM or from another bank. I guess this is the reason.

The code itself works fine on my side.

Lukas

1,733 Views
buraksoner
Contributor II

Sorry, copy paste mistake. Function Nvm_ProgFlash is like this:

void Nvm_ProgFlash (uint32_t value)

{

....

}

0 Kudos