MKL03Z: Flash erase fails when supply voltage is under 2.3v

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

MKL03Z: Flash erase fails when supply voltage is under 2.3v

1,168件の閲覧回数
gauravbanyal
Contributor IV

Hello,

I am using MKL03Z on my custom board. I am using the 8MHz clock. I have noticed that at low supply voltages (under 2.3v) the flash erase fails. The limits of flash erase should be in-line with the limits of MCU operation of ~1.7 volts but it doesn't seem to match up. Copied below is my code which I have taken from the SDK example "SDK_2.2_MKL03Z32xxx4\boards\frdmkl03z\driver_examples\flash". I get the following prints on the UART terminal:

===

ERROR 3
REASON FOR FAILURE: 105

====

Please help me fix this failure.

Thanks,

Gaurav Banyal.

Code:

=====

/*******************************************************************************
* Defines
******************************************************************************/
#define MEMORY_FREE (1)
#define MEMORY_NOT_FREE (0)

#define NUM_FLASH_SECTORS_FOR_DATA (5)

bool erase_flash(){

/* Check security status. */
result = FLASH_GetSecurityState(&s_flashDriver, &securityStatus);
if (kStatus_FLASH_Success != result)
{
//error_trap();
PRINTF("\r\n ERROR_TRAP 2\r\n");
}
/* Print security status. */
switch (securityStatus)
{
case kFLASH_SecurityStateNotSecure:
PRINTF("\r\n\r\n Flash is UNSECURE!");
break;
case kFLASH_SecurityStateBackdoorEnabled:
PRINTF("\r\n\r\n Flash is SECURE, BACKDOOR is ENABLED!");
break;
case kFLASH_SecurityStateBackdoorDisabled:
PRINTF("\r\n\r\n Flash is SECURE, BACKDOOR is DISABLED!");
break;
default:
break;
}
PRINTF("\r\n");

/* Test pflash basic opeation only if flash is unsecure. */
if (kFLASH_SecurityStateNotSecure == securityStatus)
{

/* Debug message for user. */
/* Erase several sectors on upper pflash block where there is no code */
/* Erase memory from destAdrss upto the number of buffer bytes. */
destAdrss = pflashBlockBase + (pflashTotalSize - (NUM_FLASH_SECTORS_FOR_DATA*pflashSectorSize));
zeroAdrss = destAdrss;
PRINTF("\r\n destAdrss = 0x%x, \r\n pflashBlockBase = 0x%x, \r\n pflashTotalSize = 0x%x, \r\n pflashSectorSize = 0x%x\r\n", destAdrss, pflashBlockBase, pflashTotalSize, pflashSectorSize);
result = FLASH_Erase(&s_flashDriver, destAdrss, (NUM_FLASH_SECTORS_FOR_DATA*pflashSectorSize), kFLASH_ApiEraseKey);
if (kStatus_FLASH_Success != result)
{
PRINTF("\r\n ERROR 3");
PRINTF("\r\n REASON FOR FAILURE: %d\r\n", result);
memory_free = MEMORY_NOT_FREE;
}
else{
memory_free = MEMORY_FREE;
}

for( volatile uint32_t i = 0; i < 100000; ++i)
{
__asm("NOP"); /* delay */
}

/* Verify sector if it's been erased. */
result = FLASH_VerifyErase(&s_flashDriver, destAdrss, (NUM_FLASH_SECTORS_FOR_DATA*pflashSectorSize), kFLASH_MarginValueUser);
if (kStatus_FLASH_Success != result)
{
PRINTF("\r\n FLASH NOT ERASED!! \r\n");
memory_free = MEMORY_NOT_FREE;
return (FAILED);
}
else
{
memory_free = MEMORY_FREE;
/* Print message for user. */
PRINTF("\r\n Successfully Erased %d sectors from 0x%x -> 0x%x\r\n", NUM_FLASH_SECTORS_FOR_DATA, destAdrss, (destAdrss + (NUM_FLASH_SECTORS_FOR_DATA*pflashSectorSize)));
return (SUCCESS);
}
}
else
{
PRINTF("\r\n Erase/Program opeation will not be executed, as Flash is SECURE!");
return (FAILED);
}
}

=====

タグ(2)
0 件の賞賛
返信
1 返信

956件の閲覧回数
gauravbanyal
Contributor IV

I have noticed that mostly either the flash erase fails or the flash verify fails. Its seldom that both fail together.

Some questions:

1. Does the FLASH_Erase() return an error when the flash area I am trying to erase is already in erased status? Is it ok to consider that the flash is erased if FLASH_VerifyErase() returns success after FLASH_Erase() has returned a failure.

2. I have changed the sequence calls in this function. The new sequence is as follows: 

Check if flash is already erased by calling the FLASH_VerifyErase().

If true, return success and exit.

If false, erase and verify.

In this step, if erase fails, try verification. If verification fails, return error. If Verification succeeds even though FLASH_Erase() had not returned success, return success.

Is this approach also OK or is it important that FLASH_Erase() and FLASH_VerifyErase() should both return success?

Best regards,
Gaurav.

0 件の賞賛
返信