writing in flash

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

writing in flash

3,517 Views
ramabh
Contributor I
Hi..
 
I am facing a peculiar problem.
I am using mc9s12dt128 controller.I downloaded flash standard routines from freescale site it self.
I added these files to my project and i am using cosmic compiler.
 
when i am debugging step by step the flash codes are running good i am able to change flash memory location but when i am not using step by step..................my code stops running....it is like i placed some break point.
 
and even i am not able to change the locations too....
 
If any one having some ideas please help me
 
 
Labels (1)
0 Kudos
Reply
6 Replies

821 Views
ramabh
Contributor I
hi..
 
i didnot understand what you mentioned.
 
while doing single stepping i am able to write.
And i am not sending any STOP command and even that access error is also not occuring
 
my problem is when i give go through debugger the code is behaving as there are some break points
0 Kudos
Reply

821 Views
kef
Specialist I
Flash memory block is not readable while it's being programmed. While programming CPU can't read program memory (from flash block that is being programmed) and executes not your code but some odd instructions. That's why you may notice something odd like unexpected breakpoints. Single stepping inserts pauses between instructions and probably flash programming completes before you hit "singlestep" button again. You need to move your flash program/erase routines to memory that will be readable while programming (RAM, EEPROM, another flash block, external memory).
Note also that if you are going to program/erase interrupt vectors flash block, then you should also disable all interrupts for program/erase time. Else CPU can fetch not valid vector but garbage and runaway again.
 
 
0 Kudos
Reply

821 Views
Lundin
Senior Contributor IV
Sorry, I misunderstood what you ment. If the problem occurs only when running, yeah then it is as Kef says, it is very likely caused because you are trying to program the same flash bank as the code is executed from. I once had the same problem myself. You are lucky to have a DT128, since it has two flash "banks" (64k chunks) and you won't have to place any code in RAM.



I think it would be nice if Freescale could make this a bit more clear in the manual. All it says is:

"Each Flash block can be programmed or erased at the same time. However, it is not possible to read from a Flash block while it is being erased or programmed."

Yay, a flash "block". And just what is that? Is it a segment of 512 bytes, is it a page of 16k or is it a bank of 64k? It is not clear. In the FCNFG register documentation in the very same manual, they suddenly speak of banks, not of blocks.

First time I read that I assumend it meant the 512 segment being written to, and it is obvious that there are plenty of others out there (approx every S12 user writing their own flash routines) doing the same mistake.

Further, Codewarrior adds to the confusion since there they are talking about "banked memory" rather than "paged memory".

Less vauge, ambiguous names of the various mcu parts in general would be welcome.
0 Kudos
Reply

821 Views
kef
Specialist I
Hm, sorry for misusing "block". All these terms should be used more carefully.
 
Actually I'm not sure if 9S12x128/9S12x256 are able to read one bank while programming another one. I haven't tried it my self and don't know if it's possible. Old 912D60 had two flash modules. Module is something similar to more modern "block". SCI module, SPI module .. SCI block, SPI block . Old 912DG128 had 32kB flash arrays. Flash array is something similar to 64kB flash bank :smileyhappy:. You could erase 912dg128 flash array at once, you can erase 9S12 64kB flash bank. I'm sure that one could program one flash array while reading another flash array. But, since S12 docs say:
 
"... it is not possible to read from a Flash block while it is being erased or programmed."
.. and since all banks belong to the same block, I assume that all the S12 flash should be not readable while any bank is being programmed/erased. Oops.
0 Kudos
Reply

821 Views
peg
Senior Contributor IV
Hi,
 
It seems to me that there is _absolutely_ _no_ standard for the terms to describe different sections of flash memory. Other manufacturers are just as bad as Motorola/Freescale and probably this is made worse by Freescale using different third party flash vendors who probably use different terms for the same thing.
 
The most important thing here is that the device in question has two areas of flash with _seperate_ programming voltage control, so that you can run (read) from one section (prog volts off) while programming another (prog voltage on).
 
Regards
Peg
 
0 Kudos
Reply

821 Views
Lundin
Senior Contributor IV
That is expected. If you single-step through the rows where you write to FCMD and FSTAT you will get access violation.

RTFM, FTS128K Block User Guide, chapter 4.1.4 Illegal Flash Operations:

"11. The part enters STOP mode and a program or erase command is in progress. The command is aborted and any pending command is killed."
0 Kudos
Reply