;
;I am working on a small subsystem using the MCF51ac128 chip.
;I have not been able to get the SECTOR ERASE flash command to work.
;CAN ANYONE HELP?
;
;I am running a 20megaHz Bus clock from the PLL
;so I have set the FCDIV register as part of the powerup sequence.
;20,000,000/8/16 = 156,250Hz.
;
MOVE.B #%01001111,D0 ;the FDIVLD bit sets itself automatically
MOVE.B D0,(FCDIV).L ;set FLASH clock to an acceptable frequency.
;
;Location 40D, the NVPROT non-volatile register that is copied by silicone
;to the FPROT register on reset, is set in the exec so that there should be no
;FLASHprotected at all:
;
INIT_NVPROT: DB %11111111 ;40D will be copied to FPROT
;
;I have dumped FCDIV and FPROT and verified that they are correct.
;
;
;The followig subrutine is copied into RAM and executed in an attempt
;to erase the 1K sector at address $1FC00.
;
;Writing a one to the FCBEF bit in FSTAT resets the CPU immediately everytime
;for the sector erase command ($40), and the sector is not erased.
;The exec is burned with each long in the sector at $1FC00 set to $12345678,
;it is not erased to $FFFFFFFF, it is not even changed at all.
;
;NOTE: I tried an erase verify command (5) just to see what wuld happen,
;it did not reset the CPU, and the routine executed to completion.
;
;I have followed the instructions in Chapter 4 and I can't find any other
;documentation on the subject of FLASH for the MCF51ac128/256.
;
SECTOR_ERASE_RAM:
MOVE.W #$2700,SR ;lock out interrupts
MOVEA.L #FSTAT,A6
MOVEA.L #FCMD,A5
MOVE.L #$1FC00,A0 ;addr of sector to erase in A0
;;;; MOVE.L #$5,D1 ;erase Verify command.
MOVE.L #$40,D1 ;40hex Sector Erase command.
MOVE.B #$30,(A6) ;write ones to clear the error bits if any.
MOVE.L #$FFFFFFFF,(A0) ;write a LONG to the address passed in A0
MOVE.B D1,(A5) ;write the FLASH command into FCMD register.
;The following instruction resets the CPU.
MOVE.B #$80,(A6) ;write one to FCBEF bit to "launch" command.
;It never gets here.
MOVE.L #50,D0 ;;;
TIME_WASTING_LOOP: ;
NOP ;Give the FLASH controller some time
SUBQ.L #1,D0 ;to get going before checking FSTAT.
BGT.B TIME_WASTING_LOOP ;;;
FLASH_CMD_WAIT:
MOVE.B D0,(SRS).L ;KICK the COP it is defaulted to .512sec.
MOVE.B (A6),D0 ;check FLASH status register
ANDI.L #$40,D0 ;test the FCCF bit
BEQ.B FLASH_CMD_WAIT ;Wait Loop until the command completes.
MOVE.W #$2000,SR ;reenable interrupts
CMP.L #$5,D1 ;If the command was verify, report result
BEQ.B TST_FBLANK
RTS
TST_FBLANK: ;;;
MOVE.B (A6),D0 ;get the FSTAT register
ANDI.L #$4,D0 ;Strip off the FBLANK bit
BEQ.B NOT_ERASED ;if FBLANK=0, FLASH array is not erased.
ERASED: MOVEA.L #ERASED_MSG,A0 ;
BRA.B REPORT_FBLANK ;
NOT_ERASED: ;
MOVEA.L #NOT_ERASED_MSG,A0 ;
REPORT_FBLANK: ;
JSR (SEND_MESSAGE_NOW).L ;;;
RTS
NOT_ERASED_MSG: DB "NOT "
ERASED_MSG: DB "ERASED",CR,0
;Hopefully if I can get a sector erased I will be able to program it.
thanks,
Tom_too
Message Edited by Tom_too on 2009-01-22 07:36 PM