Bahadir Selcuk

XDP512 Runtime flash writing

Discussion created by Bahadir Selcuk on Apr 5, 2008
Latest reply on Apr 7, 2008 by Tom Thompson
Hi,
I am trying to write in flash memory on runtime. There are some faults.
Code:
 
#define ALIGNED_WORD_MASK 0x0001
#define PROG 0x20
 
#pragma push
#pragma DATA_SEG FLASH_DIAG
unsigned int FLASH_DiagSave[16];
#pragma pop
unsigned int ProgFlash(unsigned int* progAdr,unsigned int* bufferPtr,                       unsigned int size){ if(((unsigned int)progAdr & ALIGNED_WORD_MASK) != 0)    /* Check for aligned word */ {  return(FAIL); }   while (!FSTAT_CBEIF);     if (FSTAT_ACCERR || FSTAT_PVIOL)      FSTAT = 0x30;         *progAdr = 15;         FCMD = PROG;         FSTAT = FSTAT_CBEIF_MASK;               while (!FSTAT_CBEIF);      while (!FSTAT_CCIF);     return(PASS);}//------------------------------------------------------------------------------void ConfigFCLKDIV(void)  {    if (!FCLKDIV_FDIVLD)      {        FCLKDIV_PRDIV8 = 1;        FCLKDIV_FDIV = 10;      }    return;  }//------------------------------------------------------------------------------void main(void) {  unsigned int result = 0;  volatile byte flashValue;  byte debug=0;  unsigned char i;  /* put your own code here */  SetupXGATE();  EnableInterrupts;    ConfigFCLKDIV(); result = ProgFlash(FLASH_DiagSave, DiagBuffer, 16);  flashValue = (byte)FLASH_DiagSave[0];  for(;;) {    } /* wait forever */  /* please make sure that you never leave this function */}

 If I set a break point at the line of           "flashValue = (byte)FLASH_DiagSave[0];"    program don't stop and run forever. If I halt it stops unknown area. But if I set a breakpoint at the line of                              "while (!FSTAT_CBEIF);"            in  "ProgFlash" function there is no problem writing 15 to  FLASH_DiagSave[0]. 
I am using 16MHz osc. And FLASH_DIAG is in ROM_4000.
What is problem?


Outcomes