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.

MSP430FG6626: Using the FLASH2 region as writable memory

Part Number: MSP430FG6626
Other Parts Discussed in Thread: MSP430WARE

The part MSP430FG6626 says that it supports 128 kb of flash memory and we are trying to utilize this region of memory for writing data. Is this possible?

The FLASH2 region seems to be writable only at program time using the programmer to store code. We tried to declare global arrays like so: int data[50000] and we get a compiler error saying not enough memory for it.

We can use readonly global memory (static const int array[50000] however).

Is there a way to use this region at runtime in code?

  • You cannot use flash memory as though it were RAM. Writing requires specific setup and possibly an erase cycle as well. This can of course be done by your application but not with named variables and such that C understands. Assuming you compile in small mode so that there is no chance that the compiler/liniker will put anything into that upper block of flash, you can deal with it any way you like.

  • Is there an example of how to do this in the application? I knew about needing to erase the data before doing a write, but I was wondering if it is a matter of ptr = flashaddr; *ptr = 0; *ptr = val; or something like that, or do you need something more elaborate?

  • The documentation is pretty clear on the process but if you need an example, TI provides a package of code examples for most parts. Linked from the product page. Try there.

  • I saw the example of a flash write in the msp430ware library and it does it for the INFO segments, would this apply to the code/memory segments (FLASH2)?

    Main: code memory

    Bank 3 32KB 0243FFh to 01C400h

    Bank 2 32KB 01C3FFh to 014400h 

    Bank 1 32KB 0143FFh to 00C400h 3

    Bank 0 32KB 00C3FFh to 004400h 

    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

    Will this work if I change say Flash_ptrC to the location of FLASH2?

    Flash_ptrC = (char*)0x243FF (bank 3);

  • You can try this code and modify the flash pointer to FLASH2 area.

    dev.ti.com/.../node

  • This seems to work, when I reprogram the board, all of the flash memory is set to 0xff on startup. Then when I use the code above to write to a region in FLASH2, and read it back, I was able to read back what I wrote. I looked at the .out file and it doesn't seem to have a .end symbol for the code section so we will have to be careful on what location we write to so we don't overwrite code. But this works, thanks.

**Attention** This is a public forum