1. 你的代码好像没有严格遵照flash command 执行步骤,请参考以下下方的代码:
uint16_t Flash_Program2LongWords(uint32_t wNVMTargetAddress, uint32_t dwData0, uint32_t dwData1)
{
uint16_t err = FLASH_ERR_SUCCESS;
// Check address to see if it is aligned to 4 bytes
// Global address [1:0] must be 00.
if(wNVMTargetAddress & 0x03)
{
err = FLASH_ERR_INVALID_PARAM;
return (err);
}
// Clear error flags
FTMRH_FSTAT = 0x30;
// Write index to specify the command code to be loaded
FTMRH_FCCOBIX = 0x0;
// Write command code and memory address bits[23:16]
FTMRH_FCCOBHI = FLASH_CMD_PROGRAM;// program FLASH command
FTMRH_FCCOBLO = wNVMTargetAddress>>16;// memory address bits[23:16]
// Write index to specify the lower byte memory address bits[15:0] to be loaded
FTMRH_FCCOBIX = 0x1;
// Write the lower byte memory address bits[15:0]
FTMRH_FCCOBLO = wNVMTargetAddress;
FTMRH_FCCOBHI = wNVMTargetAddress>>8;
// Write index to specify the word0 (MSB word) to be programmed
FTMRH_FCCOBIX = 0x2;
// Write the word 0
#if defined(BIG_ENDIAN)
//FTMRH_FCCOB = (dwData0>>16) & 0xFFFF;
FTMRH_FCCOBHI = (dwData0>>16)>>8;
FTMRH_FCCOBLO = (dwData0>>16);
// Write index to specify the word1 (LSB word) to be programmed
FTMRH_FCCOBIX = 0x3;
// Write word 1
//FTMRH_FCCOB = (dwData0) & 0xFFFF;
FTMRH_FCCOBHI = (dwData0) >>8;
FTMRH_FCCOBLO = (dwData0);
// Write index to specify the word0 (MSB word) to be programmed
FTMRH_FCCOBIX = 0x4;
// Write the word2
//FTMRH_FCCOB = (dwData1>>16) & 0xFFFF;
FTMRH_FCCOBHI = (dwData1>>16)>>8;
FTMRH_FCCOBLO = (dwData1>>16);
// Write index to specify the word1 (LSB word) to be programmed
FTMRH_FCCOBIX = 0x5;
// Write word 3
//FTMRH_FCCOB = (dwData1) & 0xFFFF;
FTMRH_FCCOBHI = (dwData1) >>8;
FTMRH_FCCOBLO = (dwData1);
#else
//FTMRH_FCCOB = (dwData0) & 0xFFFF;
FTMRH_FCCOBHI = (dwData0) >>8;
FTMRH_FCCOBLO = (dwData0);
// Write index to specify the word1 (LSB word) to be programmed
FTMRH_FCCOBIX = 0x3;
// Write word 1
FTMRH_FCCOBHI = (dwData0>>16)>>8;
FTMRH_FCCOBLO = (dwData0>>16);
// Write index to specify the word0 (MSB word) to be programmed
FTMRH_FCCOBIX = 0x4;
// Write the word2
//FTMRH_FCCOB = (dwData1) & 0xFFFF;
FTMRH_FCCOBHI = (dwData1) >>8;
FTMRH_FCCOBLO = (dwData1);
// Write index to specify the word1 (LSB word) to be programmed
FTMRH_FCCOBIX = 0x5;
// Write word 3
//FTMRH_FCCOB = (dwData1>>16) & 0xFFFF;
FTMRH_FCCOBHI = (dwData1>>16)>>8;
FTMRH_FCCOBLO = (dwData1>>16);
#endif
// Launch the command
FTMRH_LaunchCMD(TRUE);
// Check error status
if(FTMRH_FSTAT & FTMRH_FSTAT_ACCERR_MASK)
{
err |= FLASH_ERR_ACCESS;
}
if(FTMRH_FSTAT & FTMRH_FSTAT_FPVIOL_MASK)
{
err |= FLASH_ERR_PROTECTION;
}
if(FTMRH_FSTAT & FTMRH_FSTAT_MGSTAT0_MASK)
{
err |= FLASH_ERR_MGSTAT0;
}
if(FTMRH_FSTAT & FTMRH_FSTAT_MGSTAT1_MASK)
{
err |= FLASH_ERR_MGSTAT1;
}
return (err);
}
2.还有在program byte之前,确保该区域处于erase 状态,这在参考手册有注明
|