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.

TMS320F28377D: QS on F021_API: ERASE failed?

Part Number: TMS320F28377D


Hi all:

    In my project, I find that when I erase the flash and then use api "Fapi_doBlankCheck()", the return result is always error;

    The code below:

Fapi_StatusType FlashSectorErase(U32 SectorAddress,U16 SectorLen)
{
	U16 nRetrys = 0;		

	Fapi_StatusType oReturnCheck = Fapi_Error_Fail;
	Fapi_FlashStatusWordType oFlashStatusWord;
	uint16 repeat;
	
	SeizeFlashPump();
	watchdogDisable();
	
  //
  // Grab flash semaphore for Zone1 to enable access to flash registers.
  //

  EALLOW;
  DcsmCommonRegs.FLSEM.all = 0xA501;

  Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;
  Flash0CtrlRegs.FRD_INTF_CTRL.bit.DATA_CACHE_EN = 0;
  Flash0CtrlRegs.FRD_INTF_CTRL.bit.PREFETCH_EN = 0;
  EDIS;

  DINT;
  oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,(uint32 *)SectorAddress);
  EINT;
  uart_len = sprintf(uart_buff, "Fapi_issueAsyncCommandWithAddress: 0x%08lx\n", SectorAddress);
  uartSendText(uart_buff, uart_len);


  if(oReturnCheck == Fapi_Status_Success)
  {
#if 1
    do
    {
      // Wait until FSM is done with erase sector operation
      while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady)
      {
      
      }     

      if(SectorAddress != SECTOR_E_ADDR)
      {
        // the oReturnCheck is alwyas Fapi_Error_Fail
        oReturnCheck = Fapi_doBlankCheck((uint32 *)SectorAddress,SectorLen,&oFlashStatusWord);
        uart_len = sprintf(uart_buff, "Fapi_doBlankCheck: 0x%08lx\n", SectorAddress);
        uartSendText(uart_buff, uart_len);
      }

      if (Fapi_Error_Fail == oReturnCheck)
      {
        uart_len = sprintf(uart_buff, "Fapi_doBlankCheck NOk \n");
        uartSendText(uart_buff, uart_len);    
        Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,(uint32 *)SectorAddress);
        uart_len = sprintf(uart_buff, "Fapi_issueAsyncCommandWithAddress: 0x%08lx\n", SectorAddress);
        uartSendText(uart_buff, uart_len);        
        nRetrys ++;
      }

    }while((nRetrys < 5)&&(Fapi_Error_Fail == oReturnCheck));
#endif
  }

	Fapi_flushPipeline();
	watchdogSet(WDT_4ms);
	ReleaseFlashPump();

	return oReturnCheck;
}

    Could anyone help me out? Do I miss something?

Best Wish

Li

  • Hi Li,

    Please include EALLOW before the erase function.

    Thanks and regards,

    Vamsi

  • Hi Vamsi:

        I tried your way then there is no error return from "Fapi_doBlankCheck()" function. However, through the following erasing process, I found the on-chip flash was not erased.  Please see the code below:

    Fapi_StatusType FlashSectorErase(U32 SectorAddress,U16 SectorLen)
    {
    	U16 nRetrys = 0;		
    
    	Fapi_StatusType oReturnCheck = Fapi_Error_Fail;
    	Fapi_FlashStatusWordType oFlashStatusWord;
    	uint16 repeat;
    	
    	SeizeFlashPump();
    	watchdogDisable();
    	
      //
      // Grab flash semaphore for Zone1 to enable access to flash registers.
      //
      DINT;
      EALLOW;
      DcsmCommonRegs.FLSEM.all = 0xA501;
    
      Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;
      Flash0CtrlRegs.FRD_INTF_CTRL.bit.DATA_CACHE_EN = 0;
      Flash0CtrlRegs.FRD_INTF_CTRL.bit.PREFETCH_EN = 0;
      EDIS;
    
      oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,(uint32 *)SectorAddress);
      uart_len = sprintf(uart_buff, "Fapi_issueAsyncCommandWithAddress: 0x%08lx\n", SectorAddress);
      uartSendText(uart_buff, uart_len);
      //EDIS; If add EDIS here, my program will reboot, but why?
    
      if(oReturnCheck == Fapi_Status_Success)
      {
    #if 1
        do
        {
          // Wait until FSM is done with erase sector operation
          while (Fapi_checkFsmForReady() != Fapi_Status_FsmReady)
          {
          
          }     
    
          if(SectorAddress != SECTOR_E_ADDR)
          {
            oReturnCheck = Fapi_doBlankCheck((uint32 *)SectorAddress,SectorLen,&oFlashStatusWord);
            uart_len = sprintf(uart_buff, "Fapi_doBlankCheck: 0x%08lx\n", SectorAddress);
            uartSendText(uart_buff, uart_len);
          }
    
          if (Fapi_Error_Fail == oReturnCheck)
          {
            uart_len = sprintf(uart_buff, "Fapi_doBlankCheck NOk \n");
            uartSendText(uart_buff, uart_len);    
            oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,(uint32 *)SectorAddress);
            uart_len = sprintf(uart_buff, "Fapi_issueAsyncCommandWithAddress: 0x%08lx\n", SectorAddress);
            uartSendText(uart_buff, uart_len);        
            nRetrys ++;
          }
    
        }while((nRetrys < 5)&&(Fapi_Error_Fail == oReturnCheck));
    #endif
      }
    
    	Fapi_flushPipeline();
    	EINT;
    	watchdogSet(WDT_4ms);
    	ReleaseFlashPump();
    
    	return oReturnCheck;
    }

     Is there anything wrong with my code? By the way, why the function "Fapi_issueAsyncCommandWithAddress" will cause chip reboot???

    Best Wish

    Li

  • Hi Li,

    Could you confirm whether the flash API and the FlashSectorErase() are executed from RAM or Flash?  They should be executed from RAM.

    I will review the code in a day or two.

    Thanks and regards,
    Vamsi

  • Hi Li,

    I still did not see the EALLOW before the erase function.

    Also, please take a look at this Flash API usage FAQ, it may help for your debug:  https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/951668/faq-faq-on-flash-api-usage-for-c2000-devices 

    Thanks and regards,
    Vamsi

  • Hi Vamsi:

      DINT;
      EALLOW;
      DcsmCommonRegs.FLSEM.all = 0xA501;

      Flash0EccRegs.ECC_ENABLE.bit.ENABLE = 0x0;
      Flash0CtrlRegs.FRD_INTF_CTRL.bit.DATA_CACHE_EN = 0;
      Flash0CtrlRegs.FRD_INTF_CTRL.bit.PREFETCH_EN = 0;
      EDIS;

      // EALLOW; if I add EALLOW here, the CPU will reboot.
      oReturnCheck = Fapi_issueAsyncCommandWithAddress(Fapi_EraseSector,(uint32 *)SectorAddress);
      uart_len = sprintf(uart_buff, "Fapi_issueAsyncCommandWithAddress: 0x%08lx\n", SectorAddress);
      uartSendText(uart_buff, uart_len);
      //EDIS; If add EDIS here, my program will reboot, but why?

    if I add EALLOW like above, the CPU will reboot.

    Thanks and regards,

    Li

  • Hi Li,

    Can you answer my previous question copied below?

    Thanks and regards,

    Vamsi

  • Hi Vamsi:

    Here below is to copy api to ram.

    #ifdef __TI_COMPILER_VERSION__
        #if __TI_COMPILER_VERSION__ >= 15009000
    #pragma CODE_SECTION(FlashSectorErase, ".TI.ramfunc")
        #else
    #pragma CODE_SECTION(FlashSectorErase, "ramfuncs")
        #endif
    #endif

    Thanks

    Li

  • Hi Li,

    How about linker command file and memcpy()?  Are they configured correctly?

    Thanks and regards,

    Vamsi

  • Hi Vamsi:

        I have resolved the problem. Something wrong with "watchdog". I changed the register of WDT then everything ok.

    Best Wish

    Li

  • Hi Li,

    Thank you for the update.  I am closing this post.

    Thanks and regards,

    Vamsi