Flash Writing and Erasing for the MC9S08QG8

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

Flash Writing and Erasing for the MC9S08QG8

5,967 Views
kdelbarba
Contributor I
I've read all the previous topics related to this and have not found one to help. Right now I'm trying to write single bytes to Flash and erase pages in flash. I've written a function that seems to work when using single step but if I just let it run the flash isn't written to or erased.

void WriteToFlash(char charinput, int address, short erase)
{
char *write;
int done;

write = (char * )address;

if (1 == FSTAT_FACCERR)
{
FSTAT_FACCERR = 0;
} // end if // clearing Error Field

while (0 == FSTAT_FCBEF)
{
feedCOP();
} // end while // FCBEF Command buffer empty flag 1 means it's empty

*write = charinput; // load into buffer address and char going to write

if (0 == erase) // write
{

FCMD = 0x20; // write one byte
} // end if
else
{
FCMD = 0x40; // erase page the byte would be in

} // end erase else


FSTAT_FCBEF = 1;

asm
{
MUL;
}

if (FSTAT_FACCERR == 1 | FSTAT_FPVIOL == 1)
{
SendMsg("Error!!!!!!");
}

FSTAT_FCBEF = 0;

} // end write to flash

Thanks,

Kdelbarba
Labels (1)
0 Kudos
Reply
6 Replies

920 Views
irob
Contributor V

kdelbarba coded:

if (FSTAT_FACCERR)
{
FSTAT_FACCERR = 0; // clearing Error Field
}


According to page 55:
FACCERR is cleared by writing a 1 to FACCERR. Writing a 0 to FACCERR has no meaning or effect.
0 Kudos
Reply

919 Views
Bud
Contributor I

Irob,

  You mentioned page 55 on this forum.. the question is.. what note/document are you accessing?  I plan to implement a flash page erase function as part of my application using a gt16.

 

Bud

0 Kudos
Reply

919 Views
irob
Contributor V
Sorry about that. I was referring to the MC9S08QG8 datasheet: LINK.
0 Kudos
Reply

919 Views
irob
Contributor V
kdelbarba, have you seen this post? It's a great tech note with sample code on copying a function from flash to RAM and then running the function from RAM. Works nicely with your function.
0 Kudos
Reply

920 Views
glork
Contributor I
Hello kdelbarba.
I think you need to run the page-erase and byte-write functions in ram because flash is disabled during the process (so your program can't run...).
Also, I don't see where you initialize the flash clock divider, etc.
Look up application notes regarding 'Do-on-stack' which is a freescale flash-write routine.
ron
0 Kudos
Reply

919 Views
fire
Contributor I

i agree with you glork .We shouldrun the WRITE and ERASE code in RAM.

You have to copy the code to RAM and rin it.

0 Kudos
Reply