Board logo

标题: [原创]bootloader从DP256到XEP100的移植问题 [打印本页]

作者: cunning    时间: 2008-9-10 23:44     标题: [原创]bootloader从DP256到XEP100的移植问题

各位大虾,小弟之前按AN2546的NoteBook做了MC9S12DP256的bootloader,现在需要移植到MC9S12XEP100,但flash擦写和很多寄存器设置有很大区别,哪位仁兄能有任何指教或做过类似工作能指点一二,不胜感激.先在此谢过
作者: cunning    时间: 2008-9-11 20:21

了解的帮帮忙啊


作者: GaoTristone    时间: 2008-9-13 01:19

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


作者: cunning    时间: 2008-9-13 17:48

非常感谢GaoTristone,很受益


作者: cunning    时间: 2008-9-15 20:28

感觉AN3391比较有用


作者: chiusir    时间: 2009-3-20 10:05

good!






欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0