This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F2802: FLASH API don't erase and program at the correct address

Part Number: TMS320F2802
Other Parts Discussed in Thread: UNIFLASH, C2000WARE

Hello everybody,
I'm resuming an old project based on TMS320F2802 to add flash programming function when I receive a SCI command from a host. To do this I use FLASH API v3.02 and CCS v9.3.0.00012. When I try to erase SECTORA (0x003F6000-> 0x3F7FFF) and write a buffer to address 0x003F6000, the buffer is written to the address 0x003F5F60. The sector is also erased from that address. Can someone help me?
Here is the code (ToggleTest return 9.9916KHz and Verify function return STATUS_SUCCESS):

#pragma CODE_SECTION(CallFlashAPI,"ramfuncs");
#pragma CODE_SECTION(Error,"ramfuncs");
#pragma CODE_SECTION(Done,"ramfuncs");
#define  WORDS_IN_FLASH_BUFFER 0x100;

{//Function after SCI command
.
.
.

if (SysCtrlRegs.PLLSTS.bit.MCLKSTS != 1)
{//set PLL
   if (SysCtrlRegs.PLLCR.bit.DIV != PLLCR_VALUE)
   {
      EALLOW;
      SysCtrlRegs.PLLSTS.bit.MCLKOFF = 1;
      SysCtrlRegs.PLLCR.bit.DIV = PLLCR_VALUE;                  
      EDIS;

      EALLOW;
      SysCtrlRegs.WDCR= 0x0068;    //WatchDog disable
      EDIS;

      while(SysCtrlRegs.PLLSTS.bit.PLLLOCKS != 1) { }

      EALLOW;
      SysCtrlRegs.PLLSTS.bit.MCLKOFF = 0;
      EDIS;
   }
}
else
{
  ESTOP0;              
}

// Copy the Flash API functions to SARAM
MemCopy(&Flash28_API_LoadStart, &Flash28_API_LoadEnd, &Flash28_API_RunStart);

// We must also copy required user interface functions to RAM
MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);

//Initalize Flash_CPUScaleFactor
Flash_CPUScaleFactor = SCALE_FACTOR;

//Flash callback function not used
Flash_CallbackPtr = NULL;
           
// Jump to SARAM and call the Flash API functions
CallFlashAPI();
}


void CallFlashAPI(void)
{
   Uint16  i;
   Uint16  Status;
   Uint16  *Flash_ptr;     // Pointer to a location in flash
   Uint32  Length;         // Number of 16-bit values to be programmed
   Uint16  VersionHex;     // Version of the API in decimal encoded hex
   Uint16 SCIBuffer[WORDS_IN_FLASH_BUFFER];
 
   //ToggleTest(11);       // Toggle GPIO11

   //Check the version of the API
   VersionHex = Flash_APIVersionHex();
   if(VersionHex != 0x0302)
   {
     ESTOP0;
   }

   DINT; //interrupt disable
   
   Status = Flash_Erase((SECTORA),&FlashStatus);
   if(Status != STATUS_SUCCESS)
   {
       Error(Status);
   }

   for(i=0; i<0x100; ++i)
   {
       SCIBuffer[i] = 0+i;
   }

   Flash_ptr = (Uint16 *)0x003F6000;
   Length = 0x100;                            
   Status = Flash_Program(Flash_ptr,SCIBuffer,Length,&FlashStatus);
 
   if(Status != STATUS_SUCCESS)
   {
      Error(Status);
   }

   Status = Flash_Verify(Flash_ptr,SCIBuffer,Length,&FlashStatus);
   if(Status != STATUS_SUCCESS)
   {
      Error(Status);
   }

   Done();
}


void Error(Uint16 Status)
{
//  Error code will be in the AL register.
    asm(" ESTOP0");
    asm(" SB 0, UNC");
}

void Done(void)

{
    asm(" ESTOP0");
    asm(" SB 0, UNC");
}