A batch of Flash writing

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

A batch of Flash writing

2,377 Views
MaxY
Contributor I

Hi all,
I implemented a Flash driver for E64.
The functionalilty of driver have Flash erasing, Flash writing...etc.

But there is a situation very strange when doing a batch of Flash writing.(See following pseudo code)
It will run very smoothly in debug mode(Use BDM and press debug button on Metrowerks IDE),
every word(0x1111) you programmed is correct, but in free running mode(Turn off EVB power then turn on EVB power) you'll see there are a lot of word incorrect. (How can I see the word is incorrect? Because I didn't disconnect BDM from MCU, if you wanna see the Flash, you just need to press reset button on Hi-Wave. Remember to set the mode of memory window as periodical then double click any memory.)

Pseudo code:
INT32U StartAddress = 0x003C8000;
INT16U Word = 0x1111;
for(; StartAddress<0x003CBFFF; StartAddress+=2)
    Flash_WriteWord(StartAddress, Word);



Attached file, TestFlashProg.rar can be opened by Metrowerks CW3.1.
If you do not have E64 EVB, you just change header file usage, <MC9S12E64.h>.
First, you have to select target, Flash RAM Func in Metrowerks and make it.
Second, open Hyper-Terminal set baudrate as 19200bps.
Third, select target, Bootloader and build then you can start to run this project.

-----------------------------------
Thanks for looking.
TestFlashProg.zip

Correct5.jpg

Error2.jpg

Message Edited by t.dowe on 2009-10-21 12:46 AM
Labels (1)
0 Kudos
Reply
4 Replies

773 Views
kef
Specialist I
It looks like flash programming time is too short (some bits fail to programm).
 
I see one bug that could explain why it happens. In normal mode FCLKDIV is a write once register. And you have this
 
 FCLKDIV_PRDIV8 = 0;  // this write is granted
 FCLKDIV_FDIV = 21;    //  this is ignored in normal mode
So, effective diveder locked in FCLKDIV should be 0. Wrong value indeed.
 
 
 
Also I'm curious what from did you get following figures. Did you take them from the map file?:
 
#define FLASH_RAM_FUNC_START      0xFEE0
#define FLASH_RAM_FUNC_SIZE       21
#define FLASH_COPY_START          0x4FE0
0 Kudos
Reply

773 Views
MaxY
Contributor I
Hi kef,
I have to say you're really an expert.
After I modify configuration of Flash speed, it works. :smileyhappy:

1.
#define FLASH_COPY_START            0x4FE0

@ test project, there's a target named, "Flash RAM Function", and the relative prm file is flash_RamFunc.prm. I defined the address as following.
SECTIONS
     DUMMY_RAM = READ_WRITE 0xF000 TO 0xF002
     ROM = READ_ONLY 0x4FE0 TO 0X4FFF
END

2.
#define FLASH_RAM_FUNC_START    0xFEE0

@ P&E_ICD_linker.prm, I reserved a RAM space for Flash driver.
The reserved space is for Flash RAM function. After you launch one of the Flash command you have to wait for flag, CCIF to be set. This is the mission of Flash FAM function.

3.
#define FLASH_RAM_FUNC_SIZE       21
In the Metrowerks IDE, there's a list shows code size of every c-file.

0 Kudos
Reply

773 Views
kef
Specialist I
Thanks for compliment :smileyhappy: and for reply. Good to know it was indeed fclkdiv. I believed that flash programm/erase just can't success with fclkdiv set to zero.
 
 
I asked about fixed RamFunc addresses because I found it weird to use defines instead of address of (&) operator. Subproject with its own prm explains why you did so. Thanks.
 
Regards
0 Kudos
Reply

773 Views
DiegoNunes
Contributor I
Maxy, can you post where did you correct the bug? I'm working with NE64 with xtal = 25MHz, PLL factor 2/10, with bus clock at 5 MHz. What is your xtal and pll configuration. Thanks.
0 Kudos
Reply