Hi peg,
The code below now assembles without any errors. However when used with the program and erase code listed in my first post I still cannot write anything to flash. It does appear to write the entire flash memory to $00 at each location from $F000 to $FFFF. Do not know why this is occuring. There must be some other registers that need to be programmed or I have missed something else.
We are running out of time so it looks like we will have to deadbug an 8 pin SOIC 1K EEPROM to our board just to save 2 bytes since we cannot get the on chip flash to work.
Thanks to everyone for their help.
Regards,
Paul
;************************************************************************************************
; SUBROUTINE: SpSub ;
;************************************************************************************************
SpSub ldhx <SpSubSize+4,sp
sta 0,x
lda SpSubSize+3,sp
sta FCMD
lda #mFSTAT_FCBEF
sta FSTAT
nop
ChkDone: lda FSTAT
lsla
bpl ChkDone
SpSubEnd: rts ;back into DoOnStack in flash
SpSubSize: equ (*-SpSub)
;************************************************************************************************
; SUBROUTINE: DoOnStack ;
; ON ENTRY: H:X - points at the flash byte to be programmed ;
; A holds the data for the location to be programmed ;
; ON RETURN: H:X unchanged a A = FSTAT shifted left by 2 bits ;
; Z=1 if OK, Z=0 if protect violation or access error ;
; Uses 32 bytes of stack space + 2 bytes for BSR/JSR used to call it ;
; USES: DoOnStack which uses SpSub ;
;************************************************************************************************
DoOnStack: pshx
pshh ;save pointer to flash
psha ;save command to stack
ldhx #SpSubEnd ;point at last byte to move to stack
SpMoveLoop: lda ,x ;read from flash
psha ;move onto stack
aix #-1 ;next byte to move
cphx #SpSub-1 ;past end?
bne SpMoveLoop ;loop until the whole subroutine is on stack
tsx ;point to subroutine on stack
tpa ;move CCR to A for testing
and #$08 ;check the I mask
bne I_set ;skip if I already set
sei ;block interupts while flash busy
lda SpSubSize+6,sp ;preload data for command
jsr ,x ;execute the subroutine on the stack
cli ;OK to cleat the I mask now
bra I_cont ;continue to stack de-allocation
I_set: lda SpSubSize+6,sp ;preload data for command
jsr ,x ;execute the subroutine on the stack
I_cont: ais #SpSubSize+3 ;de-allocate subroutine body _ H:X + command
;H:X flash pointer OK from SpSub
lsla ;A=00 & Z=1 unless PVIOL or ACCERR
rts ;to flash where DoOnStack was called