Carl Norman

S08 Flash question programming, strange results

Discussion created by Carl Norman on Jan 30, 2008
Latest reply on Jan 27, 2013 by Russell Sher

I have had a read of programming flash for the S08 family (previously posted full working C code for 908 on this forum) which is in production and working fine.

The S08 data sheet seems to be all over the place with information scattered through out (unlike 908 which was in order very clear).

This code is run out of ram, the code below works exactly as the code reads ( have tripple checked stepping through it), so I guess the concept of what I am doing must be the problem?

This code is to show the core concept.
//--- Somewhere in main//20Mhz BusICGC1 = 0x78;ICGC2 = 0x30;while(!ICGS1_LOCK);   //Wait for lock before allowing software to startupwhile(FSTAT_FACCERR) FSTAT_FACCERR = 1;             //Make sure error is cleared before setting up the divider    if(!FCDIV_DIVLD) FCDIV = 0b01001100;                //set fFCLK = about 200kHz unless already setupFPROT_FPOPEN = 1;                                   //No flash protectionFPROT_FPS = 1;                                      //No flash protection//Another Function moves this code to ram, and runs from there   
if(FSTAT_FACCERR) FSTAT_FACCERR = 1;  //Step 1 - If there is an access error, clear it
while(!FSTAT_FCBEF);                  //Step 2 - Wait until ready to accept the command
ADDRESS_0xF300 = 0xFF;        // Step 3 - Write to page for erase
FCMD = mPageErase;                    // Step 4 - Setup the erase command
FSTAT_FCBEF = 1;                      // Step 5 - Carry out command
if(FSTAT_FPVIOL || FSTAT_FACCERR) FSTAT_FACCERR = 1;  //Step 6 - If there is an access error, clear it, work out error handling later
while(FSTAT_FCCF);                    // Step 7 - Wait for the command complete flag

Now, what is REALLY strange is, this code actually works IF and only IF i do exactly this
Fresh burn the chip
run to cursor at step1
then run to cursor at the line after step 8

If i move the memory window to watch address F300, it dosnt work, if i leave the memory window alone, it works.

If i just hit run, it hangs at step 7 and causes Watchdog reset

This software has also been causig me to have to unplug the USB on my Cyclone pro and refresh for the first time ever (not sure if its related, but its only since i have been playing with this code).

Once i get this working i will post up this most basic C code to run either 908 or S08 processors