By the way I copied the settings on this link Erasing Flash sectors in KL25 on the Freedom Board.
I allocated space for flash component as well.
I'll paste my functions below.
bool readInternalFlash(u32 address, u8 * data, u16 len)
{
FLASH1_Read(flash_Ptr, address, data, len); // Start reading from the flash memory
do {
FLASH1_Main(flash_Ptr);
OpStatus = FLASH1_GetOperationStatus(flash_Ptr);
} while (!((OpStatus == LDD_FLASH_IDLE) | (OpStatus == LDD_FLASH_FAILED)));
if (OpStatus == LDD_FLASH_FAILED)
return false;
return true;
}
bool writeInternalFlash(u32 address, u8 * data, u16 len)
{
FLASH1_Write(flash_Ptr, data, address, len);
while (!DataWrittenFlg) {
FLASH1_Main(flash_Ptr);
}
DataWrittenFlg = FALSE;
if (FLASH1_GetOperationStatus(flash_Ptr) == LDD_FLASH_FAILED)
return false;
readInternalFlash(address, data, len);
return true;
}
bool eraseInternalFlash(u32 address, u16 len)
{
if (FLASH1_Erase(flash_Ptr, address, len) == ERR_OK)
return true;
else
return false;
}