AnsweredAssumed Answered

writing to flash

Question asked by Daniel Lenz on Nov 26, 2008
Latest reply on Dec 11, 2008 by H?kan Dahlberg
Hello all,

i have a litle problem with my code to write in flash.

Code  for RG60:
void main(void) {  MCU_init();       erase_flash();  program_flash();
  ...
}

#pragma CODE_SEG MY_ADDRESSES
unsigned char addr[8];

#pragma CODE_SEG MY_ADDRESS_CODE
erase_flash(void)
{
   addr[0] = 0xCC;       // write in address array to start flash operation
   if (FSTAT_FACCERR==1)         // flash access error?
    {
      FSTAT = FSTAT & 0x30;      // clear FACCERR flag
    }
   FCMD = mPageErase;            // flash command -> page erase
   FSTAT_FCBEF = 1;              // clear flash command buffer empty flag
                                 // and launch command
   _asm NOP;                     // wait 4 cycles
   _asm NOP;
   _asm NOP;
   _asm NOP;
   while(FSTAT_FCCF==0){}        // wait for flash command complete
}

program_flash(void)
{
   addr[0] = 0xCC;       // write in address array to start flash operation
   if (FSTAT_FACCERR==1)         // flash access error?
    {
      FSTAT = FSTAT & 0x30;      // clear FACCERR flag
    }
   FCMD = mByteProg;             // flash command -> byte program
   FSTAT_FCBEF = 1;              // clear flash command buffer empty flag
                                 // and launch command
   _asm NOP;                     // wait 4 cycles
   _asm NOP;
   _asm NOP;
   _asm NOP;   
   
   while(FSTAT_FCCF==0){}        // wait for flash command complete
}

my prm-file:

NAMES END

SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    ROM                      =  READ_ONLY    0x182C TO 0xFFAF;   // flash
    Z_RAM                    =  READ_WRITE   0x0046 TO 0x00FF;
    RAM                      =  READ_WRITE   0x0100 TO 0x0845;   // ram
  
    MY_RAM                   =  READ_ONLY    0x0846 TO 0x0A46;   // flash
    MY_RAM2                  =  READ_WRITE   0x0A47 TO 0x17FF;   // flash
    ROM2                     =  READ_ONLY    0xFFC0 TO 0xFFDF;   // flash
  
END

PLACEMENT
    DEFAULT_RAM                         INTO  RAM;
    DEFAULT_ROM, ROM_VAR, STRINGS       INTO  ROM;
    _DATA_ZEROPAGE, MY_ZEROPAGE         INTO  Z_RAM;
    ...
    MY_ADDRESS_CODE                     INTO  ROM;
    ...  
    MY_RF_ADDRESSES                     INTO  MY_RAM;   // my flash
  
END
STACKSIZE 0x50 


I hope, somebody can help me and can find my mistake.

Outcomes