AnsweredAssumed Answered

Crash FlashCommandSequence without artificial delay

Question asked by Leif Zars on Jun 30, 2016
Latest reply on Jul 5, 2016 by jeremyzhou

C90TFS/FTFxFlash Driver

In function FlashCommandSequence the system hard faults. But when I add a delay everything works. Below notice the while loop with the nop, without it i get a hard fault.

 

Using a K24FN1M0 using config FTFx_KX_(2048_1024)K_0K_(16_4)K_4K_0K.h

 

Any ideals?

 

uint32_t SIZE_OPTIMIZATION FlashCommandSequence (PFLASH_SSD_CONFIG pSSDConfig )
{
  disableISRs();
    uint32_t ret;       /* return code variable */
    uint32_t temp;      /* temporary variable */


    /* clear CCIF to launch command */
    temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FSTAT_OFFSET;
    REG_BIT_SET(temp, FTFx_SSD_FSTAT_CCIF);
    temp = 1000000;
    while(temp){
    __asm( "NOP" );
    temp--;
    }
    /* wait for completion of this command */
    temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FSTAT_OFFSET;
    while(0x0U == (REG_BIT_GET(temp, FTFx_SSD_FSTAT_CCIF)))
    {
        /* wait till CCIF bit is set */
        /* serve callback function if counter reaches limitation */
        if(NULL_CALLBACK != pSSDConfig->CallBack)
        {
            (pSSDConfig->CallBack)();
        }
    }


    temp = pSSDConfig->ftfxRegBase + FTFx_SSD_FSTAT_OFFSET;
    ret = ((uint32_t)(REG_READ(temp)) & FTFx_SSD_FSTAT_ERROR_BITS);
    enableISRs();
    return(ret);
}

Outcomes