Jump to content

been struggling to get flash segment to erase / write for a week :(

Recommended Posts

I do have a developer working with me, but he is away for a while, and I have been trying to resolved a flash issue we have been having. I am completely stumped.


Any thoughts would be welcomed.  All values being stored are integers. 


Using a 430g2553;


I can read flash just fine (we had loaded flash data onto the mcu much much earlier in the development path) - here is an example:



 int *pflash = ( int *) 0x1000; // pointer into data flash
settings.checkPumpTurnedOnDelay = *pflash++;
settings.pumpOnTestDelay = *pflash++;
settings.longSleepDelay = *pflash++;
settings.pressurePumpOn = *pflash++;
settings.minimumOperationalPressure = *pflash++;
settings.mode_led_sound = *pflash++; // BIT0 = single_mode, BIT1 = led, BIT2 = sound
settings.failed = *pflash++;
Of course I want to be able to store updated settings into flash......
We had been using a buffer arrangement, but had troubles with that. So I have reverted code back to very basic levels.
Firstly: erasing the segment: This should at least work, however it does not erase back to 1's. Each time the program runs it still retrieves the stored values from the load along time ago.
void prepareToWrite_Seg (int pointer)
volatile char *Flash_ptr; // Flash pointer
FCTL2 = FWKEY + FSSEL0 + FN3+ FN4; // MCLK/16 for Flash Timing Generator
Flash_ptr = (char *) pointer; // Initialize Flash pointer
FCTL1 = FWKEY + ERASE; // Set Erase bit
FCTL3 = FWKEY; // Clear Lock bit
*Flash_ptr = 0; // Dummy write to erase Flash segment
while((FCTL3 & BUSY));
Then the operation to write values:
#define mFlashWriteEnable {while (FCTL3 & BUSY);FCTL1 = FWKEY;FCTL1 = FWKEY + WRT;}
// Set WRT bit for write operation
#define mFlashWriteDisable {while (FCTL3 & BUSY);FCTL1 = FWKEY +LOCK;}
// disable write operation



int *Flash_ptr;
prepareToWrite_Seg (0xFC00);
Flash_ptr=(int *)0xFC00;
*Flash_ptr++ = settings.checkPumpTurnedOnDelay;
*Flash_ptr++ = settings.pumpOnTestDelay;
*Flash_ptr++ = settings.longSleepDelay;
*Flash_ptr++ = settings.pressurePumpOn;
*Flash_ptr++ = settings.minimumOperationalPressure;
*Flash_ptr++ = settings.mode_led_sound; // BIT0 = single_mode, BIT1 = led, BIT2 = sound
*Flash_ptr++ = settings.failed;







Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...