Ron LeForce

Saving Data In Flash on GT32

Discussion created by Ron LeForce on May 4, 2006
Latest reply on Jun 9, 2006 by Ron LeForce
Hello All.
I'm using the 9s08gt32 in an application that requires that I save a small amount of semi-perm. data in internal flash. I've followed the Freescale guidelines pretty carefully with these results:
my routines work correctly if I single-step thru them
if I use them while running at full speed they don't work

This is how I set the main clock:
mov #$28,icgc1
mov #$31,icgc2
lda icgs1 ; dummy read
mov #01,icgs1

which sets FEI mode with a bus clock of approx. 5.4MHz (which I've verified independantly).

I set the flash clock thusly: lda #$1f sta fcdiv which should yield a flash clock of approx. 174KHz.

Then I have a small routine if flash which gets copied down to ram at $0300 by the startup routine. This routine does the actual writing of flash, and is called by the main routine which runs out of flash. Here is what that looks like:
; write the command
sta fcmd
lda #$80
sta fstat
lda fstat
bpl wfloop

Finally, here is the main flashing routine:
; check for errors
lda fstat
and #$30
beq asfbt1
; had error(s), try to clr
lda #$30
sta fstat
; then we have to erase
; our flash buffer @ $d000
; min erase is 512 bytes
sta flashbuf+3 ; any data
lda #$40 ; page erase
jsr progflash
; then write the marker
lda #$a5
sta flashbuf
lda #$20 ; write byte
jsr progflash
lda #$5a
sta flashbuf+1
lda #$20
jsr progflash
; then filterontime
lda filterontime
sta flashbuf+2
lda #$20
jsr progflash
lda filterontime+1
sta flashbuf+3
lda #$20
jsr progflash
; then filter display
lda fltdisp
sta flashbuf+4
lda #$20
jsr progflash
lda fltdisp+1
sta flashbuf+5
lda #$20
jsr progflash
; then temp
lda setpoint
sta flashbuf+$6
lda #$20
jsr progflash
lda setpoint+1
sta flashbuf+$7
lda #$20
jsr progflash

Its probably something simple, but I just don't see it yet. Any help would be appreciated.