AnsweredAssumed Answered

MPC5634M programming the flash section

Question asked by Burak Soner on Jun 16, 2016

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

Outcomes