了解的帮帮忙啊
S12XE的Flash操作更加简洁,都是通过操作CCOB命令寄存器来实现。所有的擦除和编程只要通过寄存器的操作就可以实现了。关键是要写一个CCOB命令的函数。下面是一个经过验证的CCOB函数,在freescale的s12xep100的demo板上试过。
/******************************************************************************
Function Name : LaunchFlashCommand
Notes : This function does not check if the Flash is erased.
This function does not explicitly verify that the data has been
sucessfully programmed.
This function must be located in RAM or a flash block not
being programmed.
******************************************************************************/
tU08 LaunchFlashCommand(char params,tU08 command,tU08 ccob0,tU16 ccob1,tU16 ccob2,tU16 ccob3,tU16 ccob4,tU16 ccob5)
{
if(FTM.fstat.bit.ccif == 1) {
FTM.fstat.byte = (FPVIOL | ACCERR); // Clear any error flags
FTM.fccobix.byte = 0; // Write the command id / ccob0
FTM.fccob.byte.hi = command;
FTM.fccob.byte.lo = ccob0;
if(++FTM.fccobix.byte != params) {
FTM.fccob.word = ccob1; // Write next data word to CCOB buffer.
if(++FTM.fccobix.byte != params) {
FTM.fccob.word = ccob2; // Write next data word to CCOB buffer.
if(++FTM.fccobix.byte != params) {
FTM.fccob.word = ccob3; // Write next data word to CCOB buffer.
if(++FTM.fccobix.byte != params) {
FTM.fccob.word = ccob4; // Write next data word to CCOB buffer.
if(++FTM.fccobix.byte != params)
FTM.fccob.word = ccob5; // Write next data word to CCOB buffer.
}
}
}
}
FTM.fccobix.byte = params-1; // This is necessary! 03082007 r66193
FTM.fstat.byte = CCIF; /* Clear command buffer empty flag by writing a 1 to it */
while (!FTM.fstat.bit.ccif) { /* wait for the command to complete */
}
return(FTM.fstat.byte); /* Return status. programmed OK */
}
else {
return(FLASH_BUSY); /* state machine busy */
}
}
另附FTM的数据结构的定义:
typedef struct /*FTM datastructure */
{
volatile tFCLKDIV fclkdiv; /*flash clock divider register */
volatile tFSEC fsec; /*flash security register */
volatile tREG08 fccobix; /*flash Common Command Object (CCOB) index register */
volatile tREG08 feccrix; /*flash ECCR index register */
volatile tFCNFG fcnfg; /*flash configuration register */
volatile tFERCNFG fercnfg; /*flash error configuration register */
volatile tFSTAT fstat; /*flash status register */
volatile tFERSTAT ferstat; /*flash error status register */
volatile tFPROT fprot; /*program flash protection register */
volatile tEPROT eprot; /*data flash (eeeprom) protection register */
volatile tFCCOB fccob; /*common command object register */
volatile tU16 etag; /*EEE tag counter */
volatile tU16 feccr; /*CCR error result*/
volatile tU08 fopt; /*flash option register */
}tFTM
非常感谢GaoTristone,很受益
感觉AN3391比较有用
good!
欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) | Powered by Discuz! 7.0.0 |