Hello Everybody:
I have a bit of a problem, I hope somebody can enlighten me.
I already checked previous posts but couldn't find one that could explain what is happening.
I am using a TI demo code to write to the flash memory (MSP430F552x Demo - Single-Byte Flash In-System Programming, Copy SegC to SegD). See included file.
Everything seems to work fine. I look at the flash memory using the Memory Browser tool in CCS, and the contents is there. See image:
Except when I reset the power on the Launchpad and check again, the data is lost and only shows FF in every byte. If I am writing to the FLASH memory, why is the data lost?
Does reseting the power on the Launchpad cause some kind of memory erase when it is replugged? Is something missing in the code?
Or am I interpreting it wrong?
I would really appreciate any comment.
Thanks for your time.
Ralf.
//
// MSP430F552x Demo - Single-Byte Flash In-System Programming, Copy SegC to SegD
//
// Description: This program first erases flash seg C, then it increments all
// values in seg C, then it erases seg D, then copies seg C to seg D. Starting
// addresses of segments defined in this code: Seg C-0x1880, Seg D-0x1800.
// ACLK = REFO = 32kHz, MCLK = SMCLK = default DCO 1048576Hz
// Set Breakpoint on NOP in the Mainloop to avoid Stressing Flash
//
// MSP430F552x
// -----------------
// /|\| XIN|-
// | | |
// --|RST XOUT|-
// | |
//
// Bhargavi Nisarga
// Texas Instruments Inc.
// April 2009
// Built with CCSv4 and IAR Embedded Workbench Version: 4.21
// ******************************************************************************
#include <msp430.h>
char value; // 8-bit value to write to seg C
// Function prototypes
void write_SegC(char value);
void copy_C2D(void);
int main(void)
{
WDTCTL = WDTPW+WDTHOLD; // Stop WDT
value = 0; // initialize value
while(1)
{
write_SegC(value++); // Write segment C, increment value
copy_C2D(); // Copy segment C to D
__no_operation(); // Loop forever, SET BREAKPOINT HERE
}
}
//------------------------------------------------------------------------------
// Input = value, holds value to write to Seg C
//------------------------------------------------------------------------------
void write_SegC(char value)
{
unsigned int i;
char * Flash_ptr; // Initialize Flash pointer
Flash_ptr = (char *) 0x1880;
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+ERASE; // Set Erase bit
*Flash_ptr = 0; // Dummy write to erase Flash seg
FCTL1 = FWKEY+WRT; // Set WRT bit for write operation
for (i = 0; i < 128; i++)
{
*Flash_ptr++ = value; // Write value to flash
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY+LOCK; // Set LOCK bit
}
//------------------------------------------------------------------------------
// Copy Seg C to Seg D
//------------------------------------------------------------------------------
void copy_C2D(void)
{
unsigned int i;
char *Flash_ptrC;
char *Flash_ptrD;
Flash_ptrC = (char *) 0x1880; // Initialize Flash segment C ptr
Flash_ptrD = (char *) 0x1800; // Initialize Flash segment D ptr
__disable_interrupt(); // 5xx Workaround: Disable global
// interrupt while erasing. Re-Enable
// GIE if needed
FCTL3 = FWKEY; // Clear Lock bit
FCTL1 = FWKEY+ERASE; // Set Erase bit
*Flash_ptrD = 0; // Dummy write to erase Flash seg D
FCTL1 = FWKEY+WRT; // Set WRT bit for write operation
for (i = 0; i < 128; i++)
{
*Flash_ptrD++ = *Flash_ptrC++; // copy value segment C to seg D
}
FCTL1 = FWKEY; // Clear WRT bit
FCTL3 = FWKEY+LOCK; // Set LOCK bit
}

