Time delays necessary when writing to Flash memory?

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

Time delays necessary when writing to Flash memory?

3,754 Views
raghav_sarma
Contributor I
Hi all,
 
I'm using flash routines downloaded from the Freescale website to erase / reprogram flash memory. My applications calls the flash erase command repeatedly in a loop incrementing the address pointer by 0x200 (the flash sector size) each time, so that the next secotr is erased until the entire region to be erased is erased. I get an error however when the erase flash routines are called.
 
On examining (taking care not to interrupt the actual flash procedure with the BDM) this with the debugger, I've noticed that there is always a breakdown on either the second or the third sector of flash that needs to be erased.
 
One thought was that this may be because a certain time is required for a flash erase command to complete and maybe we need to put in a delay between successive calls to erase flash sectors. Could this be a problem?
 
Any other suggestions what could cause such behaviour?
 
Raghav
Labels (1)
0 Kudos
Reply
7 Replies

1,598 Views
Lundin
Senior Contributor IV
What do you mean "a certain time required"? Don't you look at the CCIF flag before/after each command?

Edit: Assuming HCS12, you didn't tell.

Message Edited by Lundin on 2007-01-1608:17 AM

0 Kudos
Reply

1,598 Views
raghav_sarma
Contributor I
Yes I am using the HCS12 (DG128B) . I've just taken a look at the assembly code and Yes, this seems to look at the CCIF flag to see if the command has been completed. Aslo it seems to have a couple of time delays already. A snippet of the assembly code that erases flash is below. I guess then that something else  must be causing my problems.
 
Raghav
 
;*********************************************************************
;* SpSub - register flash command and wait for Flash CCIF
;*  this subroutine is copied onto the stack before executing
;*  because you can't execute out of flash while a flash command is
;*  in progress (see DoOnStack to see how this is used)
;*
;* Note: must be even # of bytes!
;*
;* Uses 24 bytes on stack + 3 bytes for CALL above
;*********************************************************************
           EVEN                 ;Make code start word aliened
SpSub:      
           ldab   SpSubEnd-SpSub+3,sp  ;get PPAGE back from stack
           stab   PPAGE                ;Store the PPAGE address
           tfr    ccr,b                ;get copy of ccr
           orcc  #$10                  ;disable interrupts
           staa   FSTAT                ;[PwO] register command
           nop                         ;[O] wait min 4~ from w cycle to r
           nop                         ;[O]
           nop                         ;[O]
           brclr  FSTAT,mFSTAT_CCIF,*  ;[rfPPP] wait for queued commands to finish
           tfr    b,ccr         ;restore ccr and int condition
           rtc                  ;back into DoOnStack in flash
SpSubEnd:
0 Kudos
Reply

1,598 Views
Lundin
Senior Contributor IV
Not sure what could be causing the problem. Do you run the code from RAM or from another flash bank than the one you are programming? If you don't know what I mean, then check this recent post, also for Dx128:

http://forums.freescale.com/freescale/board/message?board.id=16BITCOMM&;message.id=3018
0 Kudos
Reply

1,598 Views
raghav_sarma
Contributor I
Lundin,
 
It appears that the message that you pointed me to has been deleted. I was not able to look at this post.
 
Raghav
0 Kudos
Reply

1,598 Views
raghav_sarma
Contributor I
Hi Lundin,
 
The  flash ruotines are put on to he stack and run from there. I'm using the AN2720 flash memory programming utility from freescale.
 
The strange part is when I try calling the flash erase routines from main(), just to try and see if they are working fine, there is no problem. When my (CCP) application though calls them with exactly the same arguments, there are always the problems I've described above.
 
Raghav
0 Kudos
Reply

1,598 Views
Lundin
Senior Contributor IV
Not sure how that ';' ended up in the URL. Here it is again:

http://forums.freescale.com/freescale/board/message?board.id=16BITCOMM&message.id=3018

Anyway, if you run the code from RAM, that shouldn't be a problem. Could be anything really, something with the clock prescaler calculation perhaps?


Edit: The GUI of these messageboards is really annoying... Remove the ';' that pops up in the link and it should be fine.

Message Edited by Lundin on 2007-01-1611:58 AM

Message Edited by Alban on 2007-01-16 11:41 AM

0 Kudos
Reply

1,598 Views
Alban
Senior Contributor II
Hi Lundin,
 
I don't see how you got the ";". I just pressed "delete" and submit and it disappeared.
Strange,
 
Alban.
0 Kudos
Reply