code works with breakpoint, fails without breakpoint

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

code works with breakpoint, fails without breakpoint

ソリューションへジャンプ
2,062件の閲覧回数
sudheerrajulapu
Contributor I


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;
         }
      }
   }
}

 

 

 

 

 

ラベル(1)
0 件の賞賛
返信
1 解決策
1,618件の閲覧回数
kef
Specialist I


Flash memory is not readable while it is being erased or programmed (also while some flash commands are in progress).  You need to move at least part of your P-flash erase/program code to RAM or to D-flash, which is separate flash array and is readable while P-flash is being erased/programmed. Since interrtup vectors by default are located in P-flash, you also need to disable interrupts for P-flash erase/program time.

元の投稿で解決策を見る

0 件の賞賛
返信
8 返答(返信)
1,618件の閲覧回数
sudheerrajulapu
Contributor I

Hi Radek....

I correctly placed my erase function in RAM......

watchdog is in ROM.... moreover time being ...i disable the WD....

i disabled the interrupts....

0 件の賞賛
返信
1,618件の閲覧回数
sudheerrajulapu
Contributor I

Hi Radek and Edward,

Thank you somuch for suggestion given to me...

my code working fine now.....

0 件の賞賛
返信
1,619件の閲覧回数
kef
Specialist I


Flash memory is not readable while it is being erased or programmed (also while some flash commands are in progress).  You need to move at least part of your P-flash erase/program code to RAM or to D-flash, which is separate flash array and is readable while P-flash is being erased/programmed. Since interrtup vectors by default are located in P-flash, you also need to disable interrupts for P-flash erase/program time.

0 件の賞賛
返信
1,618件の閲覧回数
sudheerrajulapu
Contributor I


Hi Edward...

Thanks for your reply....

I am running my flash algorithem in RAM only....

even added  delay before erase...... but still its working with break points.... other wise .. it's jumps to someother location...

please let me know .. how could i solve this issue...

thanks in advance....

0 件の賞賛
返信
1,618件の閲覧回数
RadekS
NXP Employee
NXP Employee

I do not see in your code any wait loop for erase finishing.

You must wait until FSTAT_CCIF = 1, and after that you can start new erase command (new sector).

For example: while(FSTAT_CCIF == 0); //wait for done

If you handle this waiting by flash interrupt routine and some flags, this interrupt routine and interrupt vector table must be placed also directly in RAM.

However I didn’t found any sign about this approach in your code.


0 件の賞賛
返信
1,618件の閲覧回数
sudheerrajulapu
Contributor I

Hi Radek...

Thanks for your replay....

I am using below code ...... for delay...as you suggested ......

static void FWaitCmdCompleted( tFlashParam *fp )
{
   /* Loop while cmd in progress                *
    * CCIF is valid 5 cycles after start of cmd */
   
   do
   {
      /* Trigger watchdog */
      (void)(*fp->wdTriggerFct)();
                
      /* >>>>B R E A K<<<< the loop if an error has occurred */
      if ( (*FSTAT & (FPVIOL | ACCERR)) != 0 ) break;

   } while ( (*FSTAT & CCIF) == 0 );
}      

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;

      FWaitCmdCompleted(fp); 

      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;
         }
      }
   }
}

when i call this fucntion ...  flash erase function not returning ..... if i reset .. flash corrupting.....

please help ...what could be the issue...

0 件の賞賛
返信
1,618件の閲覧回数
RadekS
NXP Employee
NXP Employee

I suppose that you placed FErase function into RAM. Correct?

Where is placed function wdTriggerFct();?

Code placement:

#pragma CODE_SEG MY_RAM

//your code

#pragma CODE_SEG DEFAULT

Did you try disable interrupts?

0 件の賞賛
返信
1,618件の閲覧回数
RadekS
NXP Employee
NXP Employee

As Edward correctly mentioned, you cannot simultaneously erase and read the same flash block.

S12XS128 has just one 128 Kbyte Flash block.

Workaround:

Program should be executed from RAM during flash erasing/programming,...

In attachment you can find simple example code for P-Flash programming.