Hello Michael,
I do not use the "doonstack" method, but use a fixed block of RAM (at the bottom of the stack) for during erasing and programming flash, which I consider to be simpler. Additionally, I also tend not to use burst programming. The additional time required for byte-by-byte programming will still be shorter than the page erase period, so IMHO not worth the extra complication for most projects.
However, I did check out a version of the doonstack approach that I have on hand, and may not be the most recent offering. I assume that you are referring to the code for the 'SpSub' sub-routine that gets transferred to the stack? This code for the version that I have, is as follows:
; Sub-routine code transferred to the stack for execution
SpSub: ldhx LOW(SpSubSize+4),sp ; get flash address from stack
sta ,x ; write to flash; latch addr and data
lda SpSubSize+3,sp ; get flash command
sta FCMD ; write the flash command
lda #mFCBEF ; mask to initiate command
sta FSTAT ; [pwpp] register command
nop ; [p] want min 4~ from w cycle to r
ChkDone: lda FSTAT ; [prpp] so FCCF is valid
lsla ; FCCF now in MSB
bpl ChkDone ; loop if FCCF = 0
SpSubEnd: rts ; back into DoOnStack in flash
SpSubSize: equ (*-SpSub)
As you can see, there is only a single write within the flash page being erased, so I do not know the reason for the second write operation. The flash erase sub-routine is as follows:
FlashErase1:
PSHA ; Adjust SP for DoOnStack entry
LDA #(mFPVIOL|mFACCERR) ; Mask
STA FSTAT ; Abort any command & clear errors
LDA #mPageErase ; Mask pattern for page erase command
BSR DoOnStack ; Execute stack-based sub-routine
ais #1 ; Deallocate data location from stack
rts
Regards,
Mac