2009-12-14 07:43 PM
Writing in FMI using RAM function
2011-05-17 01:00 AM
I guess 2 things:
1. first write operation after reset initializes the FPEC for ~2 ms. If you don't wait after the memory write unprotect, FPEC will probably ignore the erase command and following. 2. the 0x00 0x80 content may come from two reasons: a) cached content, not valid in FLASH memory, b) a status from FPEC, because of point 1) - ignored command ''Read Array'' at the time it was issued.2011-05-17 01:00 AM
Hi,
I want to erase (and write) sector 7 in bank0. My code is running from the same bank so the functions to erase and write are located in RAM. This is the function I call to erase sector 7Code:
void ErasePLC_Program(void) { printf(''nErase PLC Program ''); SCU_FMICLKDivisorConfig(SCU_FMICLK_Div2);/* FMI @48Mhz */ SCU_AHBPeriphClockConfig(__FMI, ENABLE); SCU_AHBPeriphReset(__FMI, DISABLE); PLC_EraseSector(); //CALL FUNCTION IN RAM !! SCU_FMICLKDivisorConfig(SCU_FMICLK_Div2);/* FMI @48Mhz */ printf(''Donen''); } This is the code in RAMCode:
void PLC_EraseSector(void) { vu32 FMI_Sector = FMI_B0S7; vu32 FMI_Bank = FMI_BANK_0; //FMI Writeprotect disable *(vu16*)FMI_Sector = 0x60; *(vu16*)FMI_Sector = 0xD0; *(vu16*)FMI_Sector = 0xFF; //Erase sector command *(vu16 *)FMI_Sector = 0x20; *(vu16 *)FMI_Sector = 0xD0; /* Write a read status register command */ /* and until operation compeletion */ *(vu16 *)(FMI_Bank) = 0x70; while(!((*(vu16 *)FMI_Bank) & 0x80)); //FMI Writeprotect disable *(vu16*)FMI_Sector = 0x60; *(vu16*)FMI_Sector = 0x01; *(vu16*)FMI_Sector = 0xFF; /* Wait until operation compeletion */ while(!((*(vu16 *)FMI_Bank) & 0x80)); } It does not work. When I debug the program with ULINK, the processor returns to the correct adress after calling the RAMfunction, but there is no code to execute (all replaced by 0x00 and 0x80). What is wrong here ? Luc2011-05-17 01:00 AM
Thanks Edison, I will try this.
Luc