我使用的是KL16Z64的芯片型号,我的代码如下:
unsigned char Flash_SectorErase(uint32_t FlashPtr)
{
/* Allocate space on stack to run flash command out of SRAM */
/* wait till CCIF is set*/
while (!(FTFA_FSTAT & FTFA_FSTAT_CCIF_MASK)){};
/* Write command to FCCOB registers */
FTFA_FCCOB0 = FlashCmd_SectorErase;
FTFA_FCCOB1 = ( uint8_t)(FlashPtr >> 16);
FTFA_FCCOB2 = (uint8_t)((FlashPtr >> 8) & 0xFF);
FTFA_FCCOB3 = (uint8_t)(FlashPtr & 0xFF);
/* function return */
return Command_Lanuch();
} /* EndBody */
unsigned char Command_Lanuch( void )
{
unsigned char Return = Flash_OK;
// turn off interrupt
DisableInterrupts;
/* Launch command */
FTFA_FSTAT |= FTFA_FSTAT_CCIF_MASK;
/* wait for command completion */
while (!(FTFA_FSTAT & FTFA_FSTAT_CCIF_MASK)) {};
/* checking access error */
if (FTFA_FSTAT & FTFA_FSTAT_ACCERR_MASK)
{
/* clear error flag */
FTFA_FSTAT |= FTFA_FSTAT_ACCERR_MASK;
/* update return value*/
Return |= Flash_FACCERR;
}
/* checking protection error */
else if (FTFA_FSTAT & FTFA_FSTAT_FPVIOL_MASK)
{
/* clear error flag */
FTFA_FSTAT |= FTFA_FSTAT_FPVIOL_MASK;
/* update return value*/
Return |= Flash_FPVIOL;
}
else if (FTFA_FSTAT & FTFA_FSTAT_RDCOLERR_MASK)
{
/* clear error flag */
FTFA_FSTAT |= FTFA_FSTAT_RDCOLERR_MASK;
/* update return value*/
Return |= Flash_RDCOLERR;
}
/* checking MGSTAT0 non-correctable error */
else if (FTFA_FSTAT & FTFA_FSTAT_MGSTAT0_MASK)
{
Return |= Flash_MGSTAT0;
} /* EndIf */
// enable interrupt
EnableInterrupts;
return Return;
}
运行的时候总是会出现 No source available for "0xFFFFFFFE (0xFFFFFFFE)() " 的错误,查了几天了仍然不知道是什么原因造成,请各位高手帮帮忙!! 感激不尽· |