本帖最后由 rdboy 于 2010-4-26 09:10 编辑
Hi,Sir
Thanks for your help.
在正常模式下,我必须用下面的代码,但是不能成功写flash(重新连上BDM,查看对应地址的数据不对).如果我用机器码:PrgOfRam:dc.b $1C,$01,$06,$80,$1F,$01,$06,$80,$FB,$3D,程序会crash。困惑啊。
bset FSTAT,#mFSTAT_CCIF
Wait_CCIF:
brclr FSTAT,#mFSTAT_CCIF,Wait_CCIF;if this bit is 0x0,wait here. Wait a while for CCIF to be set
在BDM下,用机器码PrgOfRam:dc.b $1C,$01,$06,$80,$1F,$01,$06,$80,$FB,$3D,能够成功写Flash。
请指点,多谢。急。
LaunchFlashCommand: equ *
leax LaunchComBuff,pcr
;check FCLKDIV&0x80
brset FCLKDIV,#mFCLKDIV_FDIVLD,Wait_CCIF0 ;if set ,jump// if((temp & 0x80) == 0x80)
;else,run here
ldaa #FCLK_DIV_4M
staa FCLKDIV ;FCLKDIV = FCLK_DIV;
oraa #$80
cmpa FCLKDIV;check FCLKDIV is FCLK_DIV | 0x80 // if(FCLKDIV != (FCLK_DIV | 0x80))//Check to make sure value is written.
jmp ret_Launch;if not equ,return
Wait_CCIF0:
brclr FSTAT,#mFSTAT_CCIF,Wait_CCIF0;if this bit is 0x0,wait here. Wait a while for CCIF to be set
brclr FSTAT,#mFSTAT_CCIF,ret_Launch;
;BDM,must use these 2 lines. or CAN not write into flash.
;ldab #48
;stab FSTAT;Use store instruction to clear ACCERR, FPVIOL.
;NS,must use these 2 lines.or crash.
bset FSTAT,#mFSTAT_ACCERR
bset FSTAT,#mFSTAT_FPVIOL
;**********SET UP THE FTM COMMAND AND PARAMETERS***********
bclr FCCOBIX,#mFCCOBIX_CCOBIX0
bclr FCCOBIX,#mFCCOBIX_CCOBIX1
bclr FCCOBIX,#mFCCOBIX_CCOBIX2
;clra
ldab 1,x
stab FCCOBHI
;inca
ldab 2,x
stab FCCOBLO
ldab 0,x
beq Con_Oper;if param == 0,return
ldaa #$03
;jsr Delay32nop,pcr
Write_CCOB:
nop
nop
inc FCCOBIX
ldy a,x
sty FCCOB;Write next word parameter to CCOB1 buffer.
inca
inca
decb ;because register store param number
beq Con_Oper;if b is 0,return
bra Write_CCOB
Con_Oper:
;BMD,use the following code,write ok.
jmp PrgOfRam,pcr
;NS,use the following code,CAN communication is okay,but not write ok.
;bset FSTAT,#mFSTAT_CCIF
;Wait_CCIF:
; brclr FSTAT,#mFSTAT_CCIF,Wait_CCIF;if this bit is 0x0,wait here. Wait a while for CCIF to be set
ret_Launch:
;puly
;pulx
;puld
rts
;LaunchFlashCommand
;************************************************************************************************************* |