AnsweredAssumed Answered

MPC5634M  Flash_program   example

Question asked by 歌 苏 on Sep 1, 2016
Latest reply on Sep 18, 2016 by Lukas Zadrapa

Hi,

   I now learn to write a bottom drive of MPC5634M  Flash_program,but i face a lot of problem.so l need a exapmle to reference.The follow is what i have writed .

Who can give me a reference example ?

 

#ifdef ROM_VERSION
#pragma push
#pragma section code_type ".my_ram" ".my_ram" code_mode=far_abs
#endif
void Program_FLASH(void)
{
#define FLASH_HLR_PASSWORD 0xB2B22222
unsigned int status;
/* enable high address space */
CFLASH1.HLR.R = FLASH_HLR_PASSWORD; // unlock register
CFLASH1.HLR.R = 0x00000000; // unlock all high blocks

/* step1. erase block 10 (0xC0000-0xFFFFF) */
CFLASH1.MCR.B.ERS = 1; // select operation (erase)
CFLASH1.HSR.R = 0x00000004; // select 10 block
*((unsigned int*) p_test) = 0xFFFFFFFF; // interlock write
CFLASH1.MCR.B.EHV = 1; // start the erase operation
while(CFLASH1.MCR.B.DONE == 0){}; // wait for DONE
CFLASH1.MCR.B.EHV = 0;
CFLASH1.MCR.B.ERS = 0;

/* step2. program data */
CFLASH1.MCR.B.PGM = 1;
*((unsigned int*) p_test++) = data_to_be_written[0]; // first write
*((unsigned int*) p_test++) = data_to_be_written[1]; // additional write
*((unsigned int*) p_test++) = data_to_be_written[2]; // additional write
*((unsigned int*) p_test) = data_to_be_written[3]; // additional write
CFLASH1.MCR.B.EHV = 1; //start the erase operation
while(CFLASH1.MCR.B.DONE == 0){}; //wait for DONE
status=CFLASH1.MCR.R&0x00000200;
CFLASH1.MCR.B.EHV = 0;
CFLASH1.MCR.B.PGM = 0;
}

#ifdef ROM_VERSION
#pragma pop
endif

Outcomes