Hi, I am currently porting my bootloader to the MC9S08D60.
I've been using this bootloader on 9S08AW60, 9S08AC60, 9S08AC96.
So I wasn't expecting what happend....
I have changed the page size from 512 to 768 bytes (datasheet), I also have noticed that the erased page is not a multiple of 768 (experiment), and that burst programming works only for 32 consecutive bytes, starting at a multiple of 32.
Here is a list of related topics I found :
Here is what happends :
After blanking my page, I start programming is, say 32 bytes per 32.
During the first 256 bytes, all bytes are written.
From 256 to 511, I can flash the first byte, and get an access error when attempting to write the next byte.
From 512 to 767, all bytes are written again
Thats the same is I proceed 256 per 256 bytes, or 8 per 8 bytes.
You will find attached two S19, before and after flashing. The files should be the same (I suggest the use kdiff3 or winmerge to ease comparison).
The area to be programmed is 0x3100..0x33FF, here is a snapshot of the borders :
S123 31E0 EB37EAFCEABFEA81EA41E9FFE9BCE977E931E8E8E89DE84FE7FEE7ABE754E6FA5F
S123 3200 E6FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE3
S123 32E0 04FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE5
S123 3300 049B049A0499049904980498049704970496049504950494049404930493049204
Here is the assembly routine that I use. I think I found it some where around this forum :
ProgSub: lda #(mFSTAT_FPVIOL|mFSTAT_FACCERR) ;clear FSTAT[PVIOL,ACCERR] ldhx #FCNFG ;load address of FCNFG sta 2,x ;double-write FSTAT ensures FSTAT[PVIOL,ACCERR] are cleared sta 2,x clr ,x ;write $00 to FCNFG to clear FCNFG[KEYACC] clra ;clear return code psha ;save to stack, used as return code and operation resultcheckSize: lda #1 ;set the stop function flag ldhx LEN ;check if size is zero beq waitFCCF ;if zero, wait FCCF set and terminate function aix #-1 ;sub size by 1 sthx LEN pula ;remove previous operation result and ignore AwaitFCBEF: lda FSTAT ;check if FSTAT[FCBEF] is high bpl waitFCBEF ;new command can only be start if FSTAT[FCBEF] is high ldhx ADRR lda 0,x aix #1 sthx ADRR ldhx ADRS ;get flash address sta 0,x ;write to flash; latch addr and data aix #1 sthx ADRS lda #mBurstProg ;load A with burst program command sta FCMD ;store burst program command to FCMD lda #mFSTAT_FCBEF ;launch command sta FSTAT ;4 bus cycle nop nop nop nop lda ,x ;check error flags in FSTAT and #(mFSTAT_FPVIOL|mFSTAT_FACCERR) ;reserve FSTAT[PVIOL,ACCERR] psha ;return code and operation result in A; save to stack beq checkPAGEEND ;do the next program sequence if success sta ,x ;clear FSTAT[PVIOL,ACCERR] bra waitFCCF ;non zero in A will stop function after FSTAT[FCCF] setcheckPAGEEND: ;need to wait FSTAT[FCCF] set at page boundary tsx lda 9,x ;high byte of dest asra ;lowest bit saved in carry bit bcs checkSize ;not a page start if carry bit is set lda 10,x ;low byte of dest bne checkSize ;not a page start if low byte is non zero, ;Zero in A. function continue after FSTAT[FCCF] setwaitFCCF: psha ;save stop flag ldx FSTAT ;check if FSTAT[FCCF] is high aslx ;commands are finished if FSTAT[FCCF] is high pula ;retrieve stop flag bpl waitFCCF ;wait until FSTAT[FCCF] is high tsta ;check if stop function beq checkSize pula ;retrieve return code from stack ldhx STACK txs rtsProgSubEnd:ProgSubSize: equ (*-ProgSub)
I tried to add some more nop after starting programming, without succes.
Can Anyone help me to fix the problem ?