Problem with writing to flash MC9S08DZ60.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Problem with writing to flash MC9S08DZ60.

2,218 Views
CBB
Contributor I
This question was posed because the code runs correctly in an emulator, and also runs correctly when stepped through via the BDM. Unfortunately, when we run the code without stepping through line by line, the code errors out, with the FACCERR flag being set. I have looked through the documentation and the list of possible causes of the FACCERR flag being set, and none of seem to be occurring (at least in an obvious way). Any help you could offer would be greatly appreciated, and let me know if there are any more files you will need.

Relevent pieces of code:

Code:
; ### Init_FLASH init code; FSTAT: FCBEF=0,FCCF=0,FPVIOL=1,FACCERR=1,FBLANK=0   LDA     #%00110000   STA     FSTAT                  ; Clear error flags; FCDIV: DIVLD=0,PRDIV8=0,DIV5=1,DIV4=0,DIV3=1,DIV2=0,DIV1=0,DIV0=1   LDA     #$45   STA     FCDIV                  ; Set clock dividerJSR waitForFlashSTA CounterStorage ; set what data address to eraseLDX #mSectorErase  ; erase the sectorJSR flashCommand ; run commandflashCommand:            STX FCMD            ; Set the command specified in X            LDX #mFSTAT_FCBEF   ; loads the flash status            STX FSTAT           ; Load it back to the status to start the command            RTSwaitForFlash:            LDA FSTAT        ; Load Flash Status            AND #mFSTAT_FCCF ; Check for Flash Command Complete Flag            BEQ waitForFlash ; If bit was 0, Z would now be set            LDA FSTAT           ; Load in the flash status            AND #(mFSTAT_FACCERR+mFSTAT_FPVIOL) ; Check for an error            BEQ waitForFlash_continue            STA FSTAT           ; If one exists, clear it        waitForFlash_continue:                       RTS              ; Flash is done and any error was cleared    

 
Added p/n to subject.


Message Edited by NLFSJ on 2008-08-14 09:25 AM
Labels (1)
0 Kudos
6 Replies

441 Views
CBB
Contributor I
If I single step through the code, no error is generated, but nothing happens.
If I step over all the functions, an error is generated, so nothing happens.
If I run the code all at once (by right clicking and selecting run to cursor), it runs successfully.
Does anyone understand why this happens? (I do have interrupts disabled now.)
0 Kudos

441 Views
JimDon
Senior Contributor III
It's because the debugger reads the status registers and tries to read flash while single stepping.
It is a known issue - you just can't do it.

0 Kudos

441 Views
JimDon
Senior Contributor III
You didn't give a part number, but all require that the flashing code be run from ram.

There have been many threads on this, here is one that give several methods.

Here is another one.

There are many more..
0 Kudos

441 Views
CBB
Contributor I
We are using the MC9S08DZ60. We were under the inpression that we could program and erase EEPROM while executing flash based on page 3 in the On-Chip Memory section of the specs.
Is this incorrect?
 

http://www.freescale.com/files/microcontrollers/doc/data_sheet/MC9S08DZ60.pdf?fsrch=1&WT_TYPE=Data%2...

 

On-Chip Memory

• Flash read/program/erase over full operating voltage and

temperature

— MC9S08DZ60 = 60K

— MC9S08DZ48 = 48K

— MC9S08DZ32 = 32K

— MC9S08DZ16 = 16K

• Up to 2K EEPROM in-circuit programmable memory;

8-byte single-page or 4-byte dual-page erase sector;

Program and Erase while executing Flash; Erase abort

• Up to 4K random-access memory (RAM)

0 Kudos

441 Views
peg
Senior Contributor IV
Hello CBB,

The subject of your post is "Problem with writing to flash", so it is quite easy to see how Jim assumed this is what you are doing.
If you are writing to EEPROM then you can do it while executing from flash, like it says on page 3.
The important thing here is that you cannot write to the same array that you are executing from. Or in other words you can't have the programming voltage applied to the array that you are executing from.
Again, ther are many many examples in the forums of how to do this.

0 Kudos

441 Views
JimDon
Senior Contributor III
Well, here is a thread that discusses EEPROM.

As for single stepping thru the code, it seems you need to have interrupt disabled, so perhaps that is the issue at hand.


0 Kudos