memset(&s_flashDriver, 0, sizeof(flash_config_t));
memset(&s_cacheDriver, 0, sizeof(ftfx_cache_config_t));
/* Setup flash driver structure for device and initialize variables. */
result = FLASH_Init(&s_flashDriver);
if (kStatus_FTFx_Success != result)
{
retRes=-1;
}
/* Setup flash cache driver structure for device and initialize variables. */
result = FTFx_CACHE_Init(&s_cacheDriver);
if (kStatus_FTFx_Success != result)
{
retRes=-2;
}
/* Get flash properties*/
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflash0BlockBaseAddr, &pflashBlockBase);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflash0TotalSize, &pflashTotalSize);
FLASH_GetProperty(&s_flashDriver, kFLASH_PropertyPflash0SectorSize, &pflashSectorSize);
result = FLASH_GetSecurityState(&s_flashDriver, &securityStatus);
if (kStatus_FTFx_Success != result)
{
retRes=-3;
}
if (kFTFx_SecurityStateNotSecure == securityStatus)
{
/* Pre-preparation work about flash Cache/Prefetch/Speculation. */
FTFx_CACHE_ClearCachePrefetchSpeculation(&s_cacheDriver, true);
/* Erase a sector from destAdrss. */
#if defined(FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP) && FSL_FEATURE_FLASH_HAS_PFLASH_BLOCK_SWAP
/* Note: we should make sure that the sector shouldn't be swap indicator sector*/
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize * 2));
#else
destAdrss = pflashBlockBase + (pflashTotalSize - (SECTOR_INDEX_FROM_END * pflashSectorSize));
#endif
result = FLASH_Erase(&s_flashDriver, destAdrss, pflashSectorSize, kFTFx_ApiEraseKey);
if (kStatus_FTFx_Success != result)
{
retRes=-4;
}
/* Verify sector if it's been erased. */
result = FLASH_VerifyErase(&s_flashDriver, destAdrss, pflashSectorSize, kFTFx_MarginValueUser);
if (kStatus_FTFx_Success != result)
{
retRes=-5;
}
/* Post-preparation work about flash Cache/Prefetch/Speculation. */
FTFx_CACHE_ClearCachePrefetchSpeculation(&s_cacheDriver, false);