gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Hardware > ??? Has anyone played with erasing the flash

#3654 - wtuck - Tue Mar 04, 2003 8:17 am

Hi,

I posted this in "CODE" but this seem to be a better place for the question.

I'm using an X-port board.

I'm trying to modify the flash by downloading some data via the serial port. I have been able to get the device ID and Type from the flash and even program the some of the flash. Eraseing it is my real problem I've tried a few variations of code and can erase a block but my program never returns from the function placed in ram. (Note: my other functions like reading the device id and type, do return). My code is below any ideas?

Code:
#define CODE_IN_IWRAM __attribute__ ((section (".iwram"), long_call))
CODE_IN_IWRAM void WriteFlash (u32 addr, u16 data) { *(vu16 *)addr = data; }
CODE_IN_IWRAM u16 ReadFlash (u32 addr) { return(*(vu16 *)addr); }


// *********************************************************
void test_BlockErase(void)
{
u8 status;

flash_BlockErase(2, &status);
}


//**********************************************************
// * flash_BlockErase
// **********************************************************
CODE_IN_IWRAM void flash_BlockErase(u8 bank, u8 * status)
{
u16 Timeout;
u8 done;

WriteFlash(0x8020000, _CMD_STATUS_CLEAR); //0x50
WriteFlash(0x8020000, _CMD_BLK_ERASE); //0x20
WriteFlash(0x8020000, _CMD_BLK_ERASE_CONF); //0xDO
// the above statement is where the x-port locks up

done = 0;
Timeout = 0xFFFF;
while ((done == 0) && (Timeout != 0)) {
WriteFlash(0x8020000, _CMD_STATUS); //0x70
*status = ReadFlash(0x8020000);
done = (*status & 0x80);
Timeout--;
} // end while


WriteFlash(0x8020000, _CMD_READ); //0xFF
WriteFlash(0x8020000, _CMD_READ); //0xFF
return;
}

Code: