Issue with FLASH_EraseAll

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

Issue with FLASH_EraseAll

1,545 Views
mtbrewster
Contributor I

I am calling FLASH_EraseAll on an MKL28Z512 and it returns a success status but the flash is not erased. Is there something else I need to do?

0 Kudos
Reply
6 Replies

1,342 Views
mtbrewster
Contributor I

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

0 Kudos
Reply

1,342 Views
mtbrewster
Contributor I

I forgot to add that I can erase a sector ok.

0 Kudos
Reply

1,342 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mike,

    Thank you for your updated information.

    Could you tell me why you need to do erase all in the MCU code?

    As you know, all the code you are running is in the flash, so, if you want to erase all the flash, you must copy all your code to the RAM at first. Could you tell me your application at first?


Have a great day,
Kerry

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

0 Kudos
Reply

1,342 Views
mtbrewster
Contributor I

Hi Kerry,We want to be able to erase all the flash as a security measure. We don't need to retain anything. I thought the code in the flash driver set up the flash cmd to execute from ram.

Thanks, Mike

Sent from Yahoo Mail on Android

On Mon, Jul 30, 2018 at 6:25 PM, kerryzhou<admin@community.nxp.com> wrote:

#yiv4095925715 * #yiv4095925715 a #yiv4095925715 body {font-family:Helvetica, Arial, sans-serif;}#yiv4095925715 #yiv4095925715 h1, #yiv4095925715 h2, #yiv4095925715 h3, #yiv4095925715 h4, #yiv4095925715 h5, #yiv4095925715 h6, #yiv4095925715 p, #yiv4095925715 hr {}#yiv4095925715 .yiv4095925715button td {}

|

NXP Community

|

Re: Issue with FLASH_EraseAll

reply from Kerry Zhou in Kinetis Microcontrollers - View the full discussion

Hi Mike,

    Thank you for your updated information.

    Could you tell me why you need to do erase all in the MCU code?

    As you know, all the code you are running is in the flash, so, if you want to erase all the flash, you must copy all your code to the RAM at first. Could you tell me your application at first?

 

 

Have a great day,

Kerry

 

0 Kudos
Reply

1,342 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mike,

   Please try to copy all your code to RAM, then run the erase all again, at this time, can you erase all the chip successfully?


Have a great day,
Kerry

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

0 Kudos
Reply

1,342 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi Mike,

    Please tell me what the IDE you are using? And what the code you are using? The SDK code?

   If you want to erase all the flash, do you also copy all your code to the RAM at first? Otherwise it will have problems.

   Do you try to erase the sector which don't have the code, whether that works or not?


Have a great day,
Kerry

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

0 Kudos
Reply