writting to flash

Started by the_oog6789 October 3, 2005
Hi all,

I'm working on a HCS12 trying to store data in the onboard flash.
I've written a function in C to erase a sector of flash which i can
step through but crashes when executed normally. The debugger gives
a message 'illegal_bp' when it stops running at the end of the
function. Just wondering if anybody has any suggestions on what the
problem might be.

#pragma CODE_SEG NON_BANKED
void SectorErase(long Faddress)
{
unsigned char saved_pp = PPAGE;

PPAGE = 0x39;

FSTAT = (FSTAT & 0x20) | (FSTAT & 0x10);
while(!(FSTAT & 0x80));

*(unsigned short *)Faddress = 0x1a2b;
FCMD = 0x40;
FSTAT |= 0x80;

PPAGE = saved_pp;
}
#pragma CODE_SEG DEFAULT

Faddress is 0x398000. My write function is similar and both can be
stepped through which could be a timing issue. Or would it be a
problem returning to the DEFAULT code_seg? Any ideas?


> I'm working on a HCS12 trying to store data in the onboard flash.
> I've written a function in C to erase a sector of flash which i can
> step through but crashes when executed normally. The debugger gives
> a message 'illegal_bp' when it stops running at the end of the
> function. Just wondering if anybody has any suggestions on what the
> problem might be.

Maybe because you cannot read from FLASH while erasing/programming, and
executing your program straight from FLASH is just reading during erasing.
You need to move your erase/programming procedure into RAM, and execute
out of there.

--
Michal Konieczny
mk@mk@....