CCS v5.3
MSP430F5515
I am trying to save modified configuration parameters in an INFO segment of flash while my app is running. It appears that you must disable global interrupts during the flash erase cycle (according to the example code flashwrite_01 and flashwrite_02). However, when I _disable_interrupts() my USB connection crashes. I have tried USB_suspend() and USB_resume before and after the flash erase cycle, but it disconnects the USB connection (not acceptable). I have tried all combinations and variations of disabling and enabling interrupts to no avail.
Can someone suggest a way to temporarily suspend USB activity while erasing an info segment in flash?
Here is my code:
void SaveFlashParameters()
{
config_block_t * Flash_ptr; // Initialize Flash pointer
Flash_ptr = (config_block_t *) ".infoD";USB_suspend(); //We must suspend the USB process since disabling interrupts during flash erase interferes with USB event interrupts
WORD bGIE = __get_SR_register() &GIE; //save interrupt status
__disable_interrupt(); // 5xx Workaround: Disable global
// interrupt while erasing.
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+ERASE; // Set Erase bit
*(unsigned int *)Flash_ptr = 0; // Dummy write to erase Flash segFCTL1 = FWKEY+WRT; // Set WRT bit for write operation
*Flash_ptr = config_block; //write config_block to flash
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY+LOCK; // Set LOCK bit
__bis_SR_register(bGIE); //restore interrupt status
// __enable_interrupt();USB_resume();
}