The code is here:
;Here parameters:
;1,params(byte); 2, ccob0high(byte); 3 ccob0low(byte);4 ccob1(word);5 ccob2(word);6 ccob3(word);7 ccob4(word);
;8 ccob5(word);9 ccob6(word);10 ccob7(word);
;LaunchComBuff: fixed memory to Program flash,the above parameter store in it.
LaunchFlashCommand:
;pshd
;pshx
;pshy
leax LaunchComBuff,pcr
;jsr Delay32nop,pcr
;check FCLKDIV&0x80
ldaa FCLKDIV
brset FCLKDIV,#mFCLKDIV_FDIVLD,Wait_CCIF0 ;if set,jump
;else,run here
ldaa #FCLK_DIV_4M
staa FCLKDIV
;if(FCLKDIV != (FCLK_DIV | 0x80))//Check to make sure value is written.
;ReportError(0);
oraa #$80
cmpa FCLKDIV;check FCLKDIV is FCLK_DIV | 0x80
bne ret_Launch;if not equ,return
; jsr Delay32nop,pcr
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;
ldaa #$030
staa FSTAT;Use store instruction to clear ACCERR, FPVIOL.
; jsr Delay32nop,pcr
;**********SET UP THE FTM COMMAND AND PARAMETERS***********
clr FCCOBIX
;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
;The code in flash
;Con_Oper:
; ldaa #$80
; staa FSTAT
;Wait_CCIF:
; brclr FSTAT,#mFSTAT_CCIF,Wait_CCIF ;while (!FSTAT_CCIF);
Con_Oper:
jsr PrgOfRam,pcr
wait_Here:
brset FSTAT,#mFSTAT_ACCERR,wait_Here
brset FSTAT,#mFSTAT_FPVIOL,wait_Here
brset FSTAT,#mFSTAT_MGSTAT1,wait_Here
brset FERSTAT,#mFERSTAT_ERSERIF,wait_Here
brset FERSTAT,#mFERSTAT_PGMERIF,wait_Here
brset FERSTAT,#mFERSTAT_EPVIOLIF,wait_Here
brset FERSTAT,#mFERSTAT_ERSVIF1,wait_Here
brset FERSTAT,#mFERSTAT_DFDIF,wait_Here
brset FERSTAT,#mFERSTAT_SFDIF,wait_Here
;jsr Delay32nop,pcr
ret_Launch:
;puly
;pulx
;puld
rts
;LaunchFlashCommand
;*************************************************************************************************************
It can run normally under BDM mode,but it will crash when we run it in normal mode.
Please help me.Thanks.
Solved! Go to Solution.
Hi,Sir
Thanks for your help.
I have 2 question:
1.
I modified the code as followed.
Just like code:
;IN BDM nmode,must use these 2 lines. It will write the flash sucessfully(I can find the data in debug momory window)
ldab #48
stab FSTAT;Use store instruction to clear ACCERR, FPVIOL.
if I use the following code:
bset FSTAT,#mFSTAT_ACCERR
bset FSTAT,#mFSTAT_FPVIOL
Data can not been writen into flash.
But in NS mode,I must use these 2 lines,or crash.
bset FSTAT,#mFSTAT_ACCERR
bset FSTAT,#mFSTAT_FPVIOL
2.
IN BDM,I muse use memory data rgOfRam:dc.b $1C,$01,$06,$80,$1F,$01,$06,$80,$FB,$3D, to replace the following code:
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
But in NS,if i use PrgOfRam,the code will crash.
I must use these 3 lines in NS.
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
But this way,NS can not write the data into flash successfully.
Please check the following code.
Thanks for your help.
Please give me support when you are free. I am urgent about it.
;*************************************************************************************************************
;stack to store parameter.
;Here parameters:
;1,params(byte); 2, ccob0high(byte); 3 ccob0low(byte);4 ccob1(word);5 ccob2(word);6 ccob3(word);7 ccob4(word);
;8 ccob5(word);9 ccob6(word);10 ccob7(word);
;LaunchComBuff: fixed memory to Program flash,the above parameter store in it.
LaunchFlashCommand: equ *
;pshd
;pshx
;pshy
leax LaunchComBuff,pcr
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
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
;*************************************************************************************************************
1) It is not clear what does "crash" mean. Does MCU reset?
It is OK to clear error flags like this
LDAB #mFSTAT_ACCERR | mFSTAT_PVIOL
STAB FSTAT
Or like this
MOVB #mFSTAT_ACCERR | mFSTAT_PVIOL, FSTAT
But it is NOT OK to clear ACCERR this way
BSET FSTAT, #mFSTAT_ACCERR
In case CCIF flag is set, BSET will write "1" not only to ACCERR, but also to CCIF! You want to clear ACCERR, but code will write "1" also to CCIF, trying to launch flash command.
This code will clear only ACCERR
BCLR FSTAT, #~mFSTAT_ACCERR
2) Do you initialize bytes in RAM at PrgOfRam? dc.b directive is good to put some bytes to flash. But dc.b doesn't initialize RAM after power is applied to MCU. Debugger may load RAM once, but after power is removed PrgOfRam will be destroyed. You have to initialize it after MCU resets.
Thanks for your help.
Crash means program run into accidental address,program breakdown.
My MCU is mc9s12xep100.
I define it like here:
org $2100
PrgOfRam:dc.b $1C,$01,$06,$80,$1F,$01,$06,$80,$FB,$3D.
I thinks it is stored in address from 0x2100.
You mean debug will load it once and then BDM is okay,but NS can not init it? The data will be destroyed in NS.
How to init it after reset in NS mode.How to replace of dc.b to define some constant in memory?
Please give me way,thanks.
org $2100
PrgOfRam:dc.b $1C,$01,$06,$80,$1F,$01,$06,$80,$FB,$3D.
I thinks it is stored in address from 0x2100.
Yes, PrgOfRam is allocated at 0x2100. But ProgOfRam is allocated in RAM and thus you should initialize contents of PrgOfRam routine each time CPU resets. Allocate the copy of PrgOfRam in flash and copy it to PrgOfRam on reset.
In asm,can I finish it by the following code:
org $FF0C
ProtectFlash: dc.b $CF,$FF,$FF,$FE.
I try it.But I found 0x00 at address 0xFF00-0xffff.
How can i do for this aim in asm.
Please help me.Thanks a lot.
AsongLi.
ok.I get to know.Thanks for your help
THANKS.