Problem: Programming Flash - Code Example

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

Problem: Programming Flash - Code Example

4,058 Views
jgrowdon
Contributor I
Hi All - I have been trying to implement a very very simple piece of code to program one byte in flash.  After I have this functioning, I can take it from there.  To make things easy, I located the piece of code in RAM so that I did not have to transfer it from flash to RAM.   I simply call this routine with a "jsr"  from my normal code.  Unfortunately - the Flash never gets updated,...
 
 Here is the assembler code I used:
 
SpSub:        sei 

             ; Write One byte of data to $182C in Flash
             
             lda      #(mFPVIOL+mFACCERR)
             sta      FSTAT
 
             lda      #$0A                                     ; Random data to be programmed
             sta      FLASHStart                          ; FLASHStart equates to $182C - the firsty byte in flash
 
             lda      #mByteProg
             sta      FCMD
             
             lda      #mFCBEF
             sta      FSTAT
             
             nop
             
ChkDone2:     lda      FSTAT
             lsla  
             bpl      ChkDone2
                          
             cli
             
SpSubEnd:     rts
 
=====
Note 1: I am running at approx 18Mhz and have set up the FCDIV up to %01001011
 
Does anyone see any problems with this code?
 
Thanks in Advance -
 
John
 
 

 
Labels (1)
0 Kudos
5 Replies

540 Views
bigmac
Specialist III

Hello John,

Are you erasing the flash page before trying to re-program the byte value?

Regards,
Mac

 

0 Kudos

540 Views
jgrowdon
Contributor I

Hi Mac,

Actually, I execute this code after I use my P&E Micro Multilink 12 to program the flash.  As far as I understand, it completely erases the flash.  All of the cells are filled with "ff". 

I actually wrote a small piece of code (that I executed before the code shown above) to erase a 512 byte portion of the flash prior to programming it.  It did not make any difference.

Best Regards,

John

0 Kudos

540 Views
glork
Contributor I
Hello jgrowdon.
One thing you probably should do is have more than one NOP instruction for delay. I use 4 because space and time aren't an issue. Its a small price to pay to be sure.
Also, even though it may seem stupid, re-check the values you are using for the WRITE command and for making FCBF 1. Because you just show equates we can't see what they really mean.
Also I never trust my understanding of all the internal clock dividers, etc. If you get the flash-clock wrong you can break the chip. Its useful to make a routine that uses a timer off busclk to toggle an i/o pin so that you can hard-verify your busclk frequency. Then re-verify your fclk prescaler/divider to make sure its in the right range.
Finally, I couldn't tell how you get your code into ram; does your programmer put it there or do you have a routine that does it?
ron
0 Kudos

540 Views
jgrowdon
Contributor I

Hi Glork,

Thanks for the suggestions.  I will give them a try.  The way I placed my code in RAM was to simply put it below the RAM variables (i.e org   RAMStart).  The routine would only function while my board was powered up.  If I turned it off, the routine would disappear.  I am just trying to get the basic functionality going.

You made a comment about destroying the flash with the wrong timing.  Could you comment on that further?  I may have already destroyed the flash.

John

0 Kudos

540 Views
jgrowdon
Contributor I

Hi Glork,

Petr from Freescale sent me a small piece of code that worked perfectly.  The error I had in my code was the following - I used $4b in the FCDIV variable instead of $4c.   I used $4b because the HCS08 Family Reference Manual  Revision 1 (pg. 84) recommended using the following for a 32.768kHz crystal:

initFCDIV    equ   %01001011   (i.e. 4b)

The code I received from Freescale had $4c loaded into the FCDIV.   I sent a message to Freescale asking them to look into this.

Thanks for you comments,

John G.

0 Kudos