I haven't programmed this chip. I'd suggest the first thing to do would be to find working example code and copy that. But looking at Page 88 in the manual:
Before starting a command write sequence, the FACCERR and FPVIOL flags in the FSTAT register must be clear and the FCBEF flag must be set
You're not doing that. You're setting the FCBEF bit, but you're not clearing the other ones. If they're set the command won't run, and note you have to write a "1" to those bits to clear them.
Are you running that programming command from RAM? Or is the IDE you're using burning it to Flash and you're running it from there? That can't work. Have you erased the Flash before you try to program it?
I'd suggest you search this forum for others that have had problems with this, like this one from 2008, yes 13 years ago. See if they had similar problems, and look at any code they mention.
https://community.nxp.com/t5/8-bit-Microcontrollers/Not-able-to-use-Flash-for-buring-data-as-ROM/m-p...
I found that by searching this forum for "FCBEF" - that's the easiest way to find things related to a particular prepheral - search for a register or register bit name. The code given there does a few more things than yours does:
/* The opcode above represents this set of instructions */
if (FSTAT&0x10){ //Check to see if FACCERR is set
FSTAT = FSTAT | 0x10; //write a 1 to FACCERR to clear
}
(*((volatile unsigned char *)(Address))) = data; //write to somewhere in flash
FCMD = 0x20; //set command type.
FSTAT = FSTAT | 0x80; //Put FCBEF at 1.
_asm NOP; //Wait 4 cycles
_asm NOP;
_asm NOP;
_asm NOP;
if (FSTAT&0x30){ //check to see if FACCERR or FVIOL are set
return 0xFF; //if so, error.
}
while ((FSTAT&0x40)==0){ //else wait for command to complete
;
}
Note the "wait 4 cycles". That was necessary 13 years ago with the MC9S08AW16. The Coldfire chip might need the same, less or more. Not having those waits might explain why single-stepping the programming works for you. The single-stepping is adding the delays. Why are they there? The FCCF bit may not be able to clear immediately when you write FCBEF. It may take a few Flash clock cycles before it can do that. This is very common in these peripherals. Since the Coldfire is probably running at a higher clock rate than the MC908 it might need a longer delay too. Or maybe that's only there because it takes a while for the error bits to set and the delay is needed for that. In any event, programming code should check for errors and should tell you about any errors it found so you know.
Yes, I know. I can't find anything in the manual that says that any delays are necessary, and none of the flow charts show them either. Guess what? The instructions and flow charts in the 2007 MCS908 manual don't show any delays either. The Flash chapter in the MCF manual looks almost identical the the MC908 one as they're using the same Flash module. That's why you have to look at sample code, to find the stuff the manual doesn't mention.
Tom