Gong xd

How to program MCF5223X  Flash on chips

Discussion created by Gong xd on Jun 27, 2007
Latest reply on Jul 23, 2007 by Gong xd
When I erase 9s12NE64 flash(on chip),   I must "Do On Stack". I can not erase flash from flash itself.
I must move this code to RAM and run it from RAM.
but now when  update to MCF52235,  how can i do?  or  can program flash from flash itself ?
ask for help.
//     mcs9s12ne64  erase  flash sector must call DoOnStack().
;* DoOnStack - copy SpSub onto stack and call it (see also SpSub)
;*  De-allocates the stack space used by SpSub after returning from it.
;*  Allows final steps in a flash prog/erase command to execute out
;*  of RAM (on stack) while flash is out of the memory map
;*  This routine can be used for flash word-program or erase commands
;* Calling Convention:
;*           jsr    DoOnStack
;* Uses 32 bytes on stack + 3 bytes if Call instruction used
            pshb                 ;save B - PPAGE
            ldx   #SpSubEnd-2    ;point at last word to move to stack RTC
SpmoveLoop: ldd    2,x-          ;read from flash
            pshd                 ;move onto stack
            cpx   #SpSub-2       ;past end?
            bne    SpmoveLoop    ;loop till whole sub on stack
            tfr    sp,x          ;point to sub on stack
            ldaa  #mFSTAT_CBEIF  ;preload mask to register command
            call   0,x,00        ;execute the sub on the stack
            leas   SpSubEnd-SpSub,sp  ;de-allocate space used by sub
            pulb                 ;restore B
            rtc                  ;to flash where DoOnStack was called
                                 ; assume banked calling function