I have been able to successfully write and erase to Segment C of the Flash Information Memory. The problem I have is that the CPU hangs long after the erase has seemed to complete. I am using the WDT and disabling it during my erase routine and re-enabling it after it has completed. Then some time after it has moved on to other code, I get a WDT reset. If the CPU hung right after the dummy write that should be triggering the erase it wouldn't reset because I've disabled my WDT. Because it seems to be happening after, there is no way for me to know when to enable my WDT again.
Here is my code:
void erase_FLASH(unsigned int *Flash_ptr)
{
unsigned int *erase_ptr;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
FCTL2 = FWKEY + FSSEL0 + FN5 + FN4; // MCLK/48 for Flash Timing Generator
FCTL3 = FWKEY; // Clear Lock bit.
FCTL1 = FWKEY + ERASE; // Set Erase bit
erase_ptr = (unsigned int *)Flash_ptr; // copy Flash pointer into erase pointer
*erase_ptr = 0; // dummy write to erase Flash segment.
FCTL3 = FWKEY + LOCK;
CLRWDT(); // Setup and clear WDT
return;
}
Thank you for your help,