Crash FlashCommandSequence without artificial delay

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Crash FlashCommandSequence without artificial delay

1,154 Views
leifzars
Contributor IV

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

}

Labels (1)
0 Kudos
Reply
1 Reply

677 Views
jeremyzhou
NXP Employee
NXP Employee

Hi Leif Zars,

I'd highly recommend you to run the Flash driver demo which is from the KSDK 2.0 on your chip, and you can download the KSDK2.0 by referring to the thread.

How to: install KSDK 2.0

And the KSDK2.0 also use the C90TFS/FTFxFlash Driver to execute the several kinds of the flash operation, however the flash_command_sequence() function can work well even without inserting the delay function. So it can help you to figure out the root cause of issue by compare the demo with your demo.

/*!

* @brief Flash Command Sequence

*

* This function is used to perform the command write sequence to the flash.

*

* @param driver Pointer to storage for the driver runtime state.

* @return An error code or kStatus_FLASH_Success

*/

static status_t flash_command_sequence(flash_config_t *config)

{

    uint8_t registerValue;

#if FLASH_DRIVER_IS_FLASH_RESIDENT

    /* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */

    FTFx->FSTAT = FTFx_FSTAT_RDCOLERR_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_FPVIOL_MASK;

    status_t returnCode = flash_check_execute_in_ram_function_info(config);

    if (kStatus_FLASH_Success != returnCode)

    {

        return returnCode;

    }

    /* We pass the ftfx_fstat address as a parameter to flash_run_comamnd() instead of using

     * pre-processed MICRO sentences or operating global variable in flash_run_comamnd()

     * to make sure that flash_run_command() will be compiled into position-independent code (PIC). */

    callFlashRunCommand((FTFx_REG_ACCESS_TYPE)(&FTFx->FSTAT));

#else

    /* clear RDCOLERR & ACCERR & FPVIOL flag in flash status register */

    FTFx->FSTAT = FTFx_FSTAT_RDCOLERR_MASK | FTFx_FSTAT_ACCERR_MASK | FTFx_FSTAT_FPVIOL_MASK;

    /* clear CCIF bit */

    FTFx->FSTAT = FTFx_FSTAT_CCIF_MASK;

    /* Check CCIF bit of the flash status register, wait till it is set.

     * IP team indicates that this loop will always complete. */

    while (!(FTFx->FSTAT & FTFx_FSTAT_CCIF_MASK))

    {

    }

#endif /* FLASH_DRIVER_IS_FLASH_RESIDENT */

    /* Check error bits */

    /* Get flash status register value */

    registerValue = FTFx->FSTAT;

    /* checking access error */

    if (registerValue & FTFx_FSTAT_ACCERR_MASK)

    {

        return kStatus_FLASH_AccessError;

    }

    /* checking protection error */

    else if (registerValue & FTFx_FSTAT_FPVIOL_MASK)

    {

        return kStatus_FLASH_ProtectionViolation;

    }

    /* checking MGSTAT0 non-correctable error */

    else if (registerValue & FTFx_FSTAT_MGSTAT0_MASK)

    {

        return kStatus_FLASH_CommandFailure;

    }

    else

    {

        return kStatus_FLASH_Success;

    }

}


Have a great day,
Ping

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply