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