AnsweredAssumed Answered

code works with breakpoint, fails without breakpoint

Question asked by sudheer rajulapudi on Apr 20, 2013
Latest reply on Apr 24, 2013 by sudheer rajulapudi


Hi,

 

I am working on flash driver for MC9S12XS128 microcontorller using Codewarrior...

 

My requirement is , erase the expected memory area and program the same memory area base on Unified Diagnostic service request using CAN ....

 

but my issue with erase function. when keep the break points its erasing properly and returning to called function...

 

without break points it's erasing, but not returing to the called function...

 

i tried increasing the stack in prm file as well as keeping the delay before returning to called function...

 

but not working ..... anyone help me what could be the problem... below is the code

 

IO_ErrorType V_API_NEAR FlashDriver_REraseSync( IO_SizeType eraseLength,
   IO_PositionType eraseAddress )
{
   /* Check if length is even */
   if ( (eraseLength & (IO_SizeType)(fp.eraseSize-1)) != 0 )
   {
      fp.errorCode = kFlashEraseInvalidSize;
      return(fp.errorCode);
   }
   /* Check if address is even */
   if ( (eraseAddress  & (IO_SizeType)(fp.eraseSize-1)) != 0 )
   {
      fp.errorCode = kFlashEraseInvalidAddr;
      return(fp.errorCode);
   }

   fp.address = eraseAddress;  /* Flash erase address */
   fp.length = eraseLength;    /* Number of bytes to be erased */

  

  /* Call the erase function in RAM */  
   FLASH_DRIVER_ERASE(flashCode, &fp); /*lint !e611 */
  
   return(fp.errorCode);
}

 

flashCode with hold the addres of ExpFlashErase function

 

void ExpFlashErase( tFlashParam *fp )
{
   unsigned int i=10;
   tFlashLength   flashLength;

   flashLength = fp->length;
   fp->errorCode = kFlashOk;
   fp->errorAddress = fp->address;

 

  while ( (flashLength > 0) && (fp->errorCode == kFlashOk) )
   {
      /* Perform a sector erase */
      FErase(fp);
      fp->errorAddress += (unsigned long)fp->eraseSize;
      flashLength  -= (unsigned long)fp->eraseSize;
   }   
 
}

 

void FErase( tFlashParam *fp )
{
   unsigned char dummyData[FLASH_SEGMENT_SIZE];

   /* Initialize FCMD */
   fp->flashCmd.ccobHi[0] = ERASE_PFLASH_SECTOR;
   fp->flashCmd.cmdSize = 2;

   /* Initialize writeData pointer */
   fp->writeData = dummyData;

   /* Prepare flash and check if command register is empty */
   if ( FPrepCmd(fp) == 0 )
   {
      fp->errorCode = kFlashEraseCmdBufFull;
   }
   else
   {
      /* Start the command sequence N O W */

      /* Write a dummy value to set the page address                  *
       * Do not write a 0x00 because the CPU requires a real "write"  *
       * and not a "clear" instruction.  Some compilers will generate *
       * a CLR instruction which causes a flash ACCESS error          */

      /* Writing CCIF launches the command */
      *FSTAT = CCIF;

      if ( (*FSTAT & FPVIOL) != 0 )
      {
         /* Protection violation - clear flag and set error status */
         *FSTAT = FPVIOL;
         fp->errorCode = kFlashEraseProtect;
      }
      else
      {
         if ( (*FSTAT & ACCERR) != 0 )
         {
            /* Access error - clear flag and set error status */
            *FSTAT = ACCERR;
            fp->errorCode = kFlashEraseAcc;
         }
         else
         {
            /* The only successful way out */
            fp->errorCode = kFlashOk;
         }
      }
   }
}

 

 

 

 

 

Outcomes