Hi Kerry,
I am using KDS 3.2.0. I'm not sure what version of SDK(the project was setup by another engineer who is currently on vacation).
Here are the functions to init the flash driver and to call the erase all function:
void mcuFlash_init()
{
status_t result; /* Return code from each flash driver function */
memset(&flashDriver, 0, sizeof(flash_config_t));
result = FLASH_Init(&flashDriver);
if( kStatus_FLASH_Success != result )
{
PRINTF("%s: failed to setup flashDriver\r\n", __func__);
return;
}
/* Get flash properties*/
FLASH_GetProperty(&flashDriver, kFLASH_PropertyPflashBlockBaseAddr, &pflashBlockBase);
FLASH_GetProperty(&flashDriver, kFLASH_PropertyPflashTotalSize, &pflashTotalSize);
FLASH_GetProperty(&flashDriver, kFLASH_PropertyPflashSectorSize, &pflashSectorSize);
FLASH_GetProperty(&flashDriver, kFLASH_PropertyDflashTotalSize, &dflashTotalSize);
FLASH_GetProperty(&flashDriver, kFLASH_PropertyDflashBlockBaseAddr, &dflashBlockBase);
FLASH_GetProperty(&flashDriver, kFLASH_PropertyEepromTotalSize, &eepromTotalSize);
FLASH_GetProperty(&flashDriver, kFLASH_PropertyPflashBlockCount, &pflashBlocks);
/* print welcome message */
/* Print flash information - PFlash. */
PRINTF("\r\n Flash Information: ");
PRINTF("\r\n Total Program Flash Size:\t%d KB, Hex: (0x%x)", (pflashTotalSize / 1024), pflashTotalSize);
PRINTF("\r\n Number of Blocks:\t%d", pflashBlocks);
PRINTF("\r\n Program Flash Sector Size:\t%d KB, Hex: (0x%x) ", (pflashSectorSize / 1024), pflashSectorSize);
/* Check if DFlash exist on this device. */
if( dflashTotalSize )
{
PRINTF("\r\n Data Flash Size:\t%d KB, Hex: (0x%x)", (dflashTotalSize / 1024), dflashTotalSize);
PRINTF("\r\n Data Flash Base Address:\t0x%x", dflashBlockBase);
}
else
{
PRINTF("\r\n There is no D-Flash (FlexNVM) on this Device.");
}
/* Check if FlexMemory exist on this device. */
if( eepromTotalSize )
{
PRINTF("\r\n Enhanced EEPROM (EEE) Block Size:\t%d KB, Hex: (0x%x)", (eepromTotalSize / 1024), eepromTotalSize);
}
else
{
PRINTF("\r\n There is no Enhanced EEPROM (EEE) on this Device.");
}
/* Check security status. */
result = FLASH_GetSecurityState(&flashDriver, &securityStatus);
if( kStatus_FLASH_Success != result )
{
PRINTF("\r\n%s: Error in retrieving FLASH security status\r\n",__func__);
}
/* Print security status. */
switch( securityStatus )
{
case kFLASH_SecurityStateNotSecure:
PRINTF("\r\n Flash is UNSECURE!");
break;
case kFLASH_SecurityStateBackdoorEnabled:
PRINTF("\r\n Flash is SECURE, BACKDOOR is ENABLED!");
break;
case kFLASH_SecurityStateBackdoorDisabled:
PRINTF("\r\n Flash is SECURE, BACKDOOR is DISABLED!");
break;
default:
// something is really wrong if you get here as only the 3 above values are valid
PRINTF("\r\n Flash is in Unknown state!\r\n");
break;
}
PRINTF("\r\n");
}
bool mcuFlash_clear(void)
{
status_t status;
PRINTF("\r\nGoing to EraseAll\r\n");
status = FLASH_EraseAll(&flashDriver, kFLASH_ApiEraseKey);
//should not return if so then it is an error
PRINTF("\r\nBack from EraseAll, status %d\r\n", status);
return false;
}
and the FLASH_EraseAll function from the SDK
status_t FLASH_EraseAll(flash_config_t *config, uint32_t key)
{
status_t returnCode;
if (config == NULL)
{
return kStatus_FLASH_InvalidArgument;
}
/* preparing passing parameter to erase all flash blocks */
kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_ERASE_ALL_BLOCK, 0xFFFFFFU);
/* Validate the user key */
returnCode = flash_check_user_key(key);
if (returnCode)
{
return returnCode;
}
flash_cache_clear_process(config, kFLASH_CacheClearProcessPre);
/* calling flash command sequence function to execute the command */
returnCode = flash_command_sequence(config);
flash_cache_clear(config);
#if FLASH_SSD_IS_FLEXNVM_ENABLED
/* Data flash IFR will be erased by erase all command, so we need to
* update FlexNVM memory partition status synchronously */
if (returnCode == kStatus_FLASH_Success)
{
returnCode = flash_update_flexnvm_memory_partition_status(config);
}
#endif
return returnCode;
}
Thanks,
Mike