This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/MSP430G2553: Memory storing at run time

Part Number: MSP430G2553


Tool/software: Code Composer Studio

Hi Everybody,

I want to save parameters into main memory and/or info memory.

i tried both memories

in main memory:, in debug mode, i've managed to write and read into the memory.

but, at runtime the data isn't change or isn't correct (can't write and can't read)

in info memory, in both debug and runtime i can't write and read.

maybe it's configuration problem?

for now, i'm saving one char, but i'll need to save more chars and shorts parameters.

here's the code for this problem (with information memory):

void LoadParameters()
{
    short m1,m2;
    ReadFromFlash((char*)0x1040,(char*)&cnt_by_idx);// Count_By
    if( cnt_by_idx < 0 || cnt_by_idx > COUNT_BY_ARR_LEN - 1)
        cnt_by_idx = 3;
}

void SaveParameters()
{
    WriteToFlash((char*)0x1040,(char)cnt_by_idx);// Count_By
}

void WriteToFlash(char* address, char val)
{
    char* flash_ptr;
    FCTL3 = FWKEY;
    flash_ptr = address;              // Initialize Flash pointer
    while(FCTL3 & BUSY);
    FCTL1 = FWKEY + WRT;
    *flash_ptr = val;
    while(FCTL3 & BUSY);
    FCTL1 = FWKEY;                            // Clear WRT bit
    FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}

void ReadFromFlash(char* address, char* val)
{
    char* flash_ptr;
    flash_ptr = address;
    while(FCTL3 & BUSY);
    *val = *flash_ptr;
}

  • Joe Shoshana said:
    in main memory:, in debug mode, i've managed to write and read into the memory.

    but, at runtime the data isn't change or isn't correct (can't write and can't read)

    in info memory, in both debug and runtime i can't write and read.

    The way flash works is that an Erase operation changes all bits in a flash sector to ones, and a Write operation can change bits in a word to zeros.

    The posted code only performs Write operations, and thus unless the flash is already erased won't be able to write the correct data.

    Prior to CCS downloading a program at the start of debug session the default behavior is to erase all of the main flash memory but leave the information flash memory unchanged. That probably explains the observed behavior of the code only writing the correct data to main memory in debug mode.

    See msp430g2xx3_flashwrite_01.c Flash In-System Programming, Copy SegC to SegD for example code which performs flash Erase and Write operations.

  • Hi, thank you for the reply

    i added another function calls clearflash which take an address of a segement and erase it.

    that does the trick.

    i know that i can only erase segment (smallest size)

    however, at run time i don't want to erase the all segment but only change one parameter.

    i tried only to write it but it didn't work. if i erase and write all parameters than it works.

    is there a way not to erase all parameters and write only one parameter?