Skip to main content
Visitor II
December 15, 2009
Question

Writing in FMI using RAM function

  • December 15, 2009
  • 3 replies
  • 878 views
Posted on December 15, 2009 at 04:43

Writing in FMI using RAM function

    This topic has been closed for replies.

    3 replies

    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 10:00

    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.

    robosoftAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 10:00

    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 7

    Code:

    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 RAM

    Code:

    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 ?

    Luc

    robosoftAuthor
    Visitor II
    May 17, 2011
    Posted on May 17, 2011 at 10:00

    Thanks Edison, I will try this.

    Luc