michael coury

Flash Programming Not Working on Second Pass

Discussion created by michael coury on Nov 21, 2006
Latest reply on Nov 27, 2006 by michael coury
All -

Here are my erase and write routines -

#pragma CODE_SEG ToCopyToRAM
void EraseFlash(void) {

if ((FSTAT & 0x10) != 0) {
FSTAT |= 0x30;
}
asm {
//LDA #$CC
//STA $1600
LDA #$40
STA FCMD
LDA #$80
STA FSTAT
NOP
NOP
NOP
NOP
WFLOOP:
LDA FSTAT
LSLA
BPL WFLOOP
}
} // end EraseFlash
void WriteFlash(void) {
byte temp = 0x00;
if ((FSTAT & 0x10) != 0) {
FSTAT |= 0x30;
}
asm {
//LDA #$CC
//STA $1600
LDA #$20
STA FCMD
LDA #$80
STA FSTAT
NOP
NOP
NOP
NOP
WFLOOP:
LDA FSTAT
LSLA
BPL WFLOOP
}

// while( (FSTAT & 0x40)!= 1) {
// asm("NOP");
// }
} // end WriteFlash
#pragma CODE_SEG DEFAULT


Here is the routines that call it


int LCDFlashCheck(){
sLCDDataStored_ptr = (lcdram *) LCD_FLASH_START;

if(sLCDDataStored_ptr->iFlashKey == (word) FLASH_SEED) {
sLCDDataActive_ptr->cID = sLCDDataStored_ptr->cID;
sLCDDataActive_ptr->cChannel = sLCDDataStored_ptr->cChannel;
sLCDDataActive_ptr->cEncyptionKey = sLCDDataStored_ptr->cEncyptionKey;
sLCDDataActive_ptr->cPreset1 = sLCDDataStored_ptr->cPreset1;
sLCDDataActive_ptr->cPreset2 = sLCDDataStored_ptr->cPreset2;
sLCDDataActive_ptr->cMode = sLCDDataStored_ptr->cMode;
sLCDDataActive_ptr->cContrast = sLCDDataStored_ptr->cContrast;
sLCDDataActive_ptr->cBacklight = sLCDDataStored_ptr->cBacklight;
return ERROR_NONE;
}else{
sLCDDataActive_ptr->iFlashKey = (word) FLASH_SEED;
sLCDDataActive_ptr->cID = 0;
sLCDDataActive_ptr->cChannel = 5;
sLCDDataActive_ptr->cEncyptionKey = 21;
sLCDDataActive_ptr->cPreset1 = (char) PRESET1;
sLCDDataActive_ptr->cPreset2 = (char) PRESET2;
sLCDDataActive_ptr->cMode = 0;
sLCDDataActive_ptr->cContrast = 0x7F;
sLCDDataActive_ptr->cBacklight = 1;
LCDReWriteFlash();
return ERROR_FLASH_INVALID_KEY;
}
}


int LCDReWriteFlash(void){
char cDummy = 0xFF;
char *cDummy_ptr;
char *cMemory_ptr;
int i;

DisableInterrupts;

//Erase Flash
cMemory_ptr = (char*) LCD_FLASH_START;
*cMemory_ptr = 0xFF;
EraseFlash();

//Write Flash
cDummy_ptr = &(sLCDDataActive);
cMemory_ptr = (char*) LCD_FLASH_START;
for(i=0;i
*cMemory_ptr = *cDummy_ptr;
WriteFlash();
cMemory_ptr++;
cDummy_ptr++;
}

EnableInterrupts;
}

Now when the device is freshly flashed the memory location in question is obviously all 0xFF. The routine works as expected and all the "default" data is stored into FLASH. Now any other write attempts will fail and just not work. When I step through the code at this point

//Erase Flash
cMemory_ptr = (char*) LCD_FLASH_START;
*cMemory_ptr = 0xFF;
EraseFlash();


cMemory_ptr will correctly be addressed at 0x1600. However the next piece of code

*cMemory_ptr = 0xFF;

appears to be "skipped" and because the value at cMemory pointer never changes, the EraseFlash() routine does not correctly erase the page, and of course without the erase there is no write...

Any Ideas?

Outcomes