Hi Kerry,
Quick question here. I tried to write a data into the last sector of the KL03 on chip flash. All the read and erase operation is ok. But when I tried to write the data into the sector, the code executed this line: kFCCOBx[1] = *src++; and get a hard fault error.
I have initialised and don’t know what else I need to do.
Please help.
Jieqiu
status_t FLASH_Program(flash_config_t *config, uint32_t start, uint32_t *src, uint32_t lengthInBytes)
{
status_t returnCode;
flash_operation_config_t flashOperationInfo;
if (src == NULL)
{
return kStatus_FLASH_InvalidArgument;
}
flash_get_matched_operation_info(config, start, &flashOperationInfo);
/* Check the supplied address range. */
returnCode = flash_check_range(config, start, lengthInBytes, flashOperationInfo.blockWriteUnitSize);
if (returnCode)
{
return returnCode;
}
start = flashOperationInfo.convertedAddress;
flash_cache_clear_process(config, kFLASH_CacheClearProcessPre);
while (lengthInBytes > 0)
{
/* preparing passing parameter to program the flash block */
kFCCOBx[1] = *src++;
if (4 == flashOperationInfo.blockWriteUnitSize)
{
kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_LONGWORD, start);
}
else if (8 == flashOperationInfo.blockWriteUnitSize)
{
kFCCOBx[2] = *src++;
kFCCOBx[0] = BYTES_JOIN_TO_WORD_1_3(FTFx_PROGRAM_PHRASE, start);
}
else
{
}
/* calling flash command sequence function to execute the command */
returnCode = flash_command_sequence(config);
/* calling flash callback function if it is available */
if (config->PFlashCallback)
{
config->PFlashCallback();
}
/* checking for the success of command execution */
if (kStatus_FLASH_Success != returnCode)
{
break;
}
else
{
/* update start address for next iteration */
start += flashOperationInfo.blockWriteUnitSize;
/* update lengthInBytes for next iteration */
lengthInBytes -= flashOperationInfo.blockWriteUnitSize;
}
}
flash_cache_clear(config);
return (returnCode);
}