AnsweredAssumed Answered

Erasing and writing P-Flash on MC9S12XEP100 fails when running the program normally, but not when stepping with debugger

Question asked by utwig on Dec 18, 2013
Latest reply on Dec 19, 2013 by utwig

Hi,

 

I am trying to erase and write P-Flash with my MC9S12XEP100 application. I am able to successfully step through the subroutines performing the erasure and write. But if I try to run the application normally, an illegal breakpoint stops the program execution.

 

My P-Flash handling subroutines are derived from the subroutines I use to handle D-Flash in the same application. D-Flash handling works fine. And I have set the FCLKDIV correctly. Below is my code for erasing and writing P-Flash:

 

void erasePflash(unsigned long sector_address){

    unsigned int gpage;

    DisableInterrupts;   

   

    //Wait for the previous flash command to complete

    while(!FSTAT_CCIF);

    //Clear ACCERR or FPVIOL if set

    if ((FSTAT & 0x30) != 0) {

         FSTAT = 0x30;       

    }

    //Erase D-flash command, set global page

    gpage = (unsigned int) (sector_address >> 16U);

    gpage |= 0x0A00;

    FCCOBIX = 0x00;

    FCCOB = gpage;            

    //Address within sector

    FCCOBIX = 0x01;

    FCCOB = (unsigned int) (sector_address);    

 

    //Initiate flash command

    FSTAT = FSTAT_CCIF_MASK; //THE APPLICATION CRASHES IF I TRY TO RUN THE PROGRAM NORMALLY PAST THIS LINE    

 

    //Wait for the flash command to complete

    while(!FSTAT_CCIF);

   

    EnableInterrupts;

}

 

void writePflashWords(unsigned long address, unsigned int *__far ptr, unsigned char length){

    unsigned int gpage;

    unsigned int i;

   

    DisableInterrupts;

 

    //Wait for the previous flash command to complete

    while(!FSTAT_CCIF);   

    //Clear ACCERR or FPVIOL if set

    if ((FSTAT & 0x30) != 0) {

         FSTAT = 0x30;           

    }

    //Data length out of range

      if((length < 1) || (length > 4)) {

        return;

    }

    //Program D-flash command, set global page

    gpage = (unsigned int) (address >> 16U);

    gpage |= 0x0600;

      FCCOBIX = 0x00;

      FCCOB = gpage;               

      FCCOBIX = 0x01;

      FCCOB = (unsigned int) (address);

    //Fill appropriate number of words to FCCOB

      for(i=1; i<=length; i++) {    

          FCCOBIX = i+1;

        FCCOB = *ptr;

        ptr++; 

      }

      //Initiate flash command

    FSTAT = FSTAT_CCIF_MASK; //THE APPLICATION CRASHES IF I TRY TO RUN THE PROGRAM NORMALLY PAST THIS LINE

     

    //Wait for the flash command to complete

    while(!FSTAT_CCIF);          

 

    EnableInterrupts;

}

Outcomes