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
Hi,
this piece of code works as expected:
CFLASH1.HLR.R = 0xB2B22222; //password
CFLASH1.HLR.R = 0x0; //unlock all blocks in high address space in CFLASH1
//Erase
CFLASH1.MCR.B.ERS = 1;
CFLASH1.HSR.R = 0x00000004;
*(unsigned int *)0x000C0000 = 0xFFFFFFFF;
CFLASH1.MCR.B.EHV = 1;
while ((CFLASH1.MCR.B.DONE == 0));
CFLASH1.MCR.B.EHV = 0;
CFLASH1.MCR.B.ERS = 0;
//Program
CFLASH1.MCR.B.PGM = 1;
*(unsigned int *)0x000C0000 = 0x11112222;
*(unsigned int *)(0x000C0000 + 0x4) = 0x33334444;
CFLASH1.MCR.B.EHV = 1;
while ((CFLASH1.MCR.B.DONE == 0));
CFLASH1.MCR.B.EHV = 0;
CFLASH1.MCR.B.PGM = 0;
Notice that we can write only one double word at a time.
Read-While-Write is supported between banks, so the code should be executed from RAM or from another bank.
Regards,
Lukas