FLASH PROBLEMS HELP

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

FLASH PROBLEMS HELP

10,563 次查看
yodabam
Contributor I
Im working with an HCS08GB60 micro, and I am trying to write some date to Flash Memory in C. I can write to RAM no problem, but I am having an issue with the process of Writing To flash. I realize there is a specific step for getting it to work right but its just not working for me. Does anyone have any sample code or better instructions for setting up the FLASH to write data to it. I dont know what I am doing wrong. Help, Thanks
标签 (1)
0 项奖励
回复
13 回复数

1,591 次查看
yodabam
Contributor I
Thanks for the help,  but I dont undersand why what I have won't work. I am receiving the Warning Message inside the Debugger of "Invalid Flash Frequency Selected" and this leads me to believe that this is the reason I am unable to right to flash. I am following the manuals' flow diagram step by step and still I have nothing
 
My Code looks like this:
I am running a 4MHz Bus Clock
FSTAT_FACCERR = 1;
FSTAT_FPVIOL = 1; //RESETS THE ERROR FLASGS
FCDIV  = 0x13; //This is the line that generates a warning message
ptr = (int*) 0x5000; //Flash Memory Address
*ptr = 0xFF;
FCMD = 0x40; //Byte Erase for that Page space
FSTAT_FCBEF = 1; //Send Command
 
*ptr = 0xFF;
FCMD = 0x20; //Write Value FF to location 0x5000
FSTAT_FCBEF = 1; //Send Command
 
Any one  understand why I would be getting an error message for an Invalid Flash Clock Frequency. Im really in a bind and I am not seeing any lights at the end of the tunnel
0 项奖励
回复

1,591 次查看
rhinoceroshead
Contributor I
Page 47 of the GB60 datasheet says the flash clock must be set to between 150 kHz and 200 kHz.  Your divider value of FCDIV = 0x13 and a 4MHz clock yields a flash clock of 210.5 kHz - and that's probably why CodeWarrior is warning you.  Try 0x14 or 0x15 and see if the warning goes away.
0 项奖励
回复

1,591 次查看
rhinoceroshead
Contributor I

Actually, there are several things wrong here.  Immediately after you are sending the page erase command, you are sending the program command - but the Flash module is not yet ready.  You need to poll the FCCF bit in the FSTAT register to see when the module is ready for another command.

Also, you say you are writing an 0xFF to address 0x5000 in Flash.  When Flash is blank, it reads 0xFF, so in order to test it, you should be writing anything except 0xFF in order to see if it's working.

Another thing, you only did a page erase, not a mass erase, so you need to run the blank check command as part of the security measure before you can run the program command.  I think this is an extra step to make sure runaway code doesn't write over the Flash.

I highly recommend you read the Flash section of the datasheet a few times to become more acquainted with it.  I've never worked with this particular device and I only scanned the datasheet for things that jumped out at me and I could still be missing something.

0 项奖励
回复

1,591 次查看
rhinoceroshead
Contributor I
Another thing...  You have:
 
ptr = (int*) 0x5000; //Flash Memory Address
*ptr = 0xFF;
 
You are declaring your pointer as a pointer to an integer, which is 2 bytes.  If you try to do this, you are actually writing the number 0x00FF to 0x5000, which is really writing 0x00 to 0x5000 and 0xFF to 0x5001, but even that may not work depending on how the compiler decides to generate the machine code, and I think the Flash module needs to be written one byte at a time anyway.  A better approach might be:
 
ptr = (char*)0x5000;
*ptr = 0xFF;
0 项奖励
回复

1,591 次查看
yodabam
Contributor I

Thanks for the Help,

Although I have tried all possible values for FCDIV and I still get the same warning message and I know for a fact that my BUS clock is 4Mhz. So im still thinking that is my problem. I tried going through with your suggestions and I am still not getting anything to write to flash. I still think it is my Frequency Clock command which is not allowing the value to be written. Unles something else Is wrong

0 项奖励
回复

1,591 次查看
yodabam
Contributor I
I found the problem....I was attempting to execute a page erase/program instruction out of FLASH into FLASH. You can not write or erase any FLASH location while executing out of FLASH. I needed to move the instruction into RAM first. Now I know and knowing is half the battle. Thanks for the help
0 项奖励
回复

1,591 次查看
yodabam
Contributor I

Ok, I have the board hooked up to my computer and I am running through it attempting to Flash. I am noticing that no matter what I do the FCDIV register is setup with a value of CB (giving me a Flash Clock way too Low) Upon reboot I am not able to write to this register to set the flash clock!!

Also my code is giving me a FACCERR whenever i set a value to ptr

int *ptr;

ptr = (char*) 0x5000;

FCDIV = 0x19;

*ptr = 0x88; //Trying to Write a Value to 0x500 Gives me ACCERR in FSTAT

FCMD = 0x40; //Erase Page

FSTAT_FCBEF = 1; //Send Command

 

*ptr = 0x88; //Trying to Write a Value to 0x500 Gives me ACCERR in FSTAT

FCMD = 0x20; //Byte Program

 

What Is going wrong...Why cant I write to FCDIV or where would the reset value be coming from. Need input thanks guys..and girls

FSTAT_FCBEF = 1; //Send Command

0 项奖励
回复

1,591 次查看
rhinoceroshead
Contributor I
For starters, you declared your pointer as an integer pointer instead of a character pointer.  So the line you have that says this:
 
int* ptr;
 
should be this:
 
char* ptr;
 
The reason it is giving an error is because the compiled code is writing two bytes into Flash, which causes an ACCERR flag to raise since the Flash module can only latch one byte at a time.
 
I'm confused about the FCDIV problem.  Try clearing the error flags first, then setting the FCDIV register.  Then before sending each command, make sure the flags are cleared again.
0 项奖励
回复

1,591 次查看
marchesi
Contributor II
Hello,

did you get your problem killed?

If not,

aren't you using a .cfg file? That's called a 'initialization file',
which you could check out in debugger options.

Look for something like 'set_hfmcld'. This sets the clock divider.

We also need some extra care about what 'clock' we're talking about (oscillator,
core, pll, system, etc...). For instance, in our system here the Processor Expert
calculates this value as 61 (0x3d), which is quite different from the .cfg 0x0A.

Marchesi
0 项奖励
回复

1,591 次查看
yodabam
Contributor I
Well the ACCERR is getting caused no matter what I try to send. The Flags are cleared before Write a value to FCDIV. But its almost as if the FlashClk divider is set to a specific value regardless to what the program is telling it to do.
 
Does any one have any sample code that isnt already up here on the forum in C for writing to Flash. Thanks
0 项奖励
回复

1,591 次查看
peg
Senior Contributor IV
0 项奖励
回复

1,591 次查看
kdelbarba
Contributor I
I followed the link but it only confuses me. I'm trying to write to flash in C using the process from the Family Reference Manual and am having great difficulty. Does anyone have byte writing working in C?

Kdelbarba
0 项奖励
回复

1,591 次查看
peg
Senior Contributor IV

Hi Yodabam,

Take a look at AN2496.

It is for trimming the ICG but at the end of this process they write the trim value to FLASH which is the bit that may assist you.

BR Peg

0 项奖励
回复