MEMORY{ flash (RX) : ORIGIN = 0x00000000, LENGTH = 0x00040000 vectorram(RWX) : ORIGIN = 0x20000000, LENGTH = 0x00000400 sram (RWX) : ORIGIN = 0x20000400, LENGTH = 0x00007C00 ipsbar (RWX) : ORIGIN = 0x40000000, LENGTH = 0x0}C file:#define FLASH_PROGRAM_ADDR(x) \ (*(volatile unsigned long *)(void *)(&__IPSBAR[(0x04000000 + (x))]))#define ACCERR 0x10#define PVIOL 0x20#define CCIF 0x40#define CBEIF 0x80//Assume Crystal Oscillator = 25Mhzvoid InitCpuFreq(void){ MCF_CLOCK_SYNCR=0x4007;//Multiply By 12 (Divide By 5 Later),PLL Enable }void SetFlashBurnFreq(void){ MCF_CFM_CFMMCR=0;//No Lock,Interrupt Disable MCF_CFM_CFMCLKD=0x55;//Set Freq To About ~178Khz MCF_CFM_CFMPROT=0;//No Sector Is Protect MCF_CFM_CFMSACC=0;//Flash Sectors Are Placed In Supervisor Address MCF_CFM_CFMDACC=0;}int runInRam(char cmd, long addr, long val) { MCF_CFM_CFMUSTAT = PVIOL | ACCERR; FLASH_PROGRAM_ADDR(addr)=val; MCF_CFM_CFMCMD = cmd; MCF_CFM_CFMUSTAT = CBEIF; while (!(MCF_CFM_CFMUSTAT & (CCIF | PVIOL | ACCERR))); return MCF_CFM_CFMUSTAT & (PVIOL | ACCERR);}void runEnd(void){} // leave this immediately after runInRam //The function to program an array of longs, for instance: int flashProg(long *Addr, long *Value, int n) { char buf[120]; int (*ramCopy)(char,long,long) = (int(*)(char,long,long))buf; memcpy(buf, (void*)runInRam, (char*)runEnd - (char*)runInRam); while (n--) { if (ramCopy(0x20/*CMDPROG*/, Addr[n-1], Value[n-1])) return -1; } return 0;}void main (void){long Addr[2]= { 0x6000, 0x6004 }; long Value[2]= { 0xAA55AA55, 0x55AA55AA };InitCpuFreq(); SetFlashBurnFreq(); flashProg(Addr, Value, 2);}
Message Edited by Alban on 2006-08-07 06:38 AM
I am burnning the flash with C commands (internal) and not by external device.
I already succeeded to program the flash.
The address should be 44000000 + wanted address and the buffer of the ram function should be bigger.
#define FLASH_PROGRAM_ADDR(x) \ (*(volatile unsigned long *)(void *)(&__IPSBAR[(0x04000000 + (x))]))#define ACCERR MCF_CFM_CFMUSTAT_ACCERR#define PVIOL MCF_CFM_CFMUSTAT_PVIOL#define CCIF MCF_CFM_CFMUSTAT_CCIF#define CBEIF MCF_CFM_CFMUSTAT_CBEIFvoid InitCpuFreq(void){ MCF_CLOCK_SYNCR=0x4007;//Multiply By 12 (Divide By 5 Later),PLL Enable }void SetFlashBurnFreq(void){ MCF_CFM_CFMMCR=0;//No Lock,Interrupt Disable MCF_CFM_CFMCLKD=0x55;//Set Freq To About ~178Khz MCF_CFM_CFMPROT=0;//No Sector Is Protect MCF_CFM_CFMSACC=0;//Flash Sectors Are Placed In Supervisor Address MCF_CFM_CFMDACC=0;}int runInRam(char cmd, long addr, long val) { MCF_CFM_CFMUSTAT = PVIOL | ACCERR; FLASH_PROGRAM_ADDR(addr)=val; MCF_CFM_CFMCMD = cmd; MCF_CFM_CFMUSTAT = CBEIF; while (!(MCF_CFM_CFMUSTAT & (CCIF | PVIOL | ACCERR))); return (MCF_CFM_CFMUSTAT & (PVIOL | ACCERR));}void runEnd(void){} // leave this immediately after runInRam //The function to program an array of longs, for instance: int flashProg(long *Addr, long *Value, int n) { char buf[200]; int (*ramCopy)(char,long,long) = (int(*)(char,long,long))buf; memcpy(buf, (void*)runInRam, (char*)runEnd - (char*)runInRam); if(n!=0) { /* PROGRAM WORD */ while (n--) { if (ramCopy(MCF_CFM_CFMCMD_PGM, Addr[n], Value[n])) return (-1); } } else /* PAGE ERASE */ { if (ramCopy(MCF_CFM_CFMCMD_PGERS, Addr[0], Value[0])) return (-1); } return (0); }void main() { int local, num_word; long Addr[8]= { 0x00006000, 0x00006004, 0x00006008, 0x0000600B, 0x00006010, 0x00006014, 0x00006018, 0x0000601B }; long Value[8]= { 0xAA55AA55, 0x01234567, 0x55AA55A0, 0x89ABCDEF, 0x00112211, 0x0ABCCD00, 0x44444444, 0x76543210 }; InitCpuFreq(); SetFlashBurnFreq(); num_word = 0; while(1) { local = flashProg(Addr, Value, num_word); if(num_word == 8) { num_word = 0; } else { num_word++; } local = flashProg(Addr, Value, num_word); } }