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.

Need help Storing Arrays in Flash

Other Parts Discussed in Thread: MSP-TS430PM64, MSP430F2618, MSP430FG4619, MSP430F6736

Hi All,

My setup at the moment is the MSP430f2618 and the 64 pin evaluation board that matches it (MSP-TS430PM64).

I am trying to store data that I have gathered (from ADC) into flash so I can look at it later and possibly upload it to excel/matlab/etc..  My data is gathered in an array of 120 values.  I understand how to store one point of data into flash, but when it comes to storing this array and more like it, I have really hit a brick wall.  Also I would like to save around 10 of these arrays, so is it better to make a matrix (aka 2 dimensional array) and than dump this  flash, or to dump a 1 dimensional array 10 times?

 

I am hoping this community can give me a nudge in the right direction on how to do this.  Thanks for any and all help

 

Jake G.

  • Hi Jake,

    look at the code examples for MSP430F2618 (http://www.ti.com/litv/zip/slac151d ); msp430x261x_flashwrite_01.c gives some some basics for accessing the flash (erase a segment, write data to flash).

    If I should do the job, I would define 10 segments in flash (each is 512 bytes large because this is the smallest segemnt you can erase; see flash memory controller in the users manual and memory map for details), each one holding 120 ADC values (240bytes). Yes, your right when saying that you will waste some memory. But, since the device has 116kB of flash I would prefer to waste some memoy rather than having two arrays in one flash segment (if you need to earse one you will loose both in this case).

    Since you didn't mention which IDE you're using I can't point you out how to define the memory segments.

    Rgds
    aBUGSworstnightmare

     

  • Sorry I forgot to put the IDE I was using.  By IDE I assume you mean the compiler and program I am using to program the chip.  I am using the latest CCS provided by TI, with the JTAG from TI connecting to the board.

     

    Also to store the array I should run through the memory addresses as a pointer to the first one that simply increment that pointer 120 times, Storing data at each address in a sense the same way arrays are normally stored within memory?  This might be a dumb question but do I have to store the data in flash as chars (like all example codes I have seen) or can I store it as an int?  I know I can simply convert between the two but the less steps you have in a code the better.

     

    Thanks for all the help!

    Jake G.

     

     

  • Hi Jake G.,

    IDE means Integrated Development Environment.

    For specifying your custom memory may, you need to modify your .cmd file. Find an example below:

    /****************************************************************************/
    /* SPECIFY THE SYSTEM MEMORY MAP                                            */
    /****************************************************************************/

    MEMORY
    {
    ...
    // add your segment definitions below INFOD segment definition
        CHANNEL0                : origin = 0x8000, length = 0x0200
    ...
        CHANNEL7                : origin = 0x8E00, length = 0x0200
        FLASH                   : origin = 0x9000, length = 0x6FDF // you need to modify the flash start address and the flash lengths according to your new segments
    ...

    /****************************************************************************/
    /* SPECIFY THE SECTIONS ALLOCATION INTO MEMORY                              */
    /****************************************************************************/

    SECTIONS
    {

    // add new segments below .infoD segment
       
        .channel0    : {} > CHANNEL0
    ...
        .channel7    : {} > CHANNEL7


    Now, you can define your arrays and have them placed in your new segments, like:

    #pragma DATA_SECTION (move0, ".channel0")
    const unsigned int move0[10] =
              {
        0, 0, 0  0, 0, 0, 0, 0, 0, 0
              };

    Look at the assemblers users guide for details on the above.

    There's no need for converting your data to char; simply write a function that writes your integer values to flash, like i.e. (all datas were of type unsigned int):

            // write new limit data to INFOB flash segment
            __disable_interrupt();
            Flash_ptr = (unsigned int *) 0x1000;
                                                    // Initialize Flash pointer to INFOB
              FCTL3 = FWKEY;                            // Clear Lock bit
              FCTL1 = FWKEY + ERASE;                    // Set Erase bit
             
              *Flash_ptr = 0;                            // Dummy write to erase Flash segment
              while (FCTL3 & BUSY );                    // wait until erasing is finished

              FCTL1 = FWKEY + WRT;                    // Set WRT bit for write operation

            *Flash_ptr++ = uiout1lowerLOCAL;
            *Flash_ptr++ = uiout1upperLOCAL;
            *Flash_ptr++ = uiout2lowerLOCAL;
            *Flash_ptr++ = uiout2upperLOCAL;
            *Flash_ptr++ = uiout3lowerLOCAL;
            *Flash_ptr++ = uiout3upperLOCAL;
            *Flash_ptr++ = uiout4lowerLOCAL;
            *Flash_ptr++ = uiout4upperLOCAL;
            *Flash_ptr++ = uiout5lowerLOCAL;
            *Flash_ptr++ = uiout5upperLOCAL;
            *Flash_ptr++ = uiout6lowerLOCAL;
            *Flash_ptr++ = uiout6upperLOCAL;


            FCTL1 = FWKEY;                            // Clear WRT bit
              FCTL3 = FWKEY + LOCK;                    // Set LOCK bit --> writing INFOB finished
              __enable_interrupt();                    // enable all interrupts

    Rgds
    aBUGSworstnightmare

  • Thanks for all the help the program is working great now.

     

    Jake G.

     

    P.S. If anyone wants to see the final solution I came up with just ask and I will post it.

  • Hello Jake. Could you please post your solution, I would like to take a look at it.

    I have a similar task. I need to store an audio signal sampled from ADC12 in flash, and I need to output it through DAC later. My micro-controller is MSP430FG4619 which has a 120k flash memory. I am also not sure whether I need to modify the .cmd file and reconfigure the flash memory. Could you please tell me how to do it in a little bit more in details, I will really appreciate your help.

    Yicheng G.

  • aBUGSworstnightmare,

    I am new to TI MSP430. And now I have the task to sample audio signals from ADC12, and store them in flash for later use. I am using MSP430FG4619 which has 120 KB flash memory. I am sampling the audio signal at 4 kHz and I need to sample four different audio signals, and each one last approximately 10 secs. So as a result each audio signal takes about 5 KB size of flash. Later in my task I need to output the audio stored in flash through DAC12, one at a time. So how should I configure the flash memory in .cmd file and how to store the audio signals? This is my first time dealing with flash memory so could you please explain it to me a little bit more in details. I will really appreciate your help.

    Rgds

    Yicheng

  • Hi,

    I have similar task to accomplish i.e. I have to store some sensor values and occasionally update it as well to later process it. I have 10 such arrays of sensors values of fixed length and the sensor data is in float. I go through the directed procedure as discussed in this thread but in my cmd file there are two flash definition i.e. FLASH and FLASH2.

    my cmd file looks like following

    MEMORY
    {
        SFR                     : origin = 0x0000, length = 0x0010
        PERIPHERALS_8BIT        : origin = 0x0010, length = 0x00F0
        PERIPHERALS_16BIT       : origin = 0x0100, length = 0x0100
        RAM                     : origin = 0x2400, length = 0x2000
        INFOA                   : origin = 0x1980, length = 0x0080
        INFOB                   : origin = 0x1900, length = 0x0080
        INFOC                   : origin = 0x1880, length = 0x0080
        INFOD                   : origin = 0x1800, length = 0x0080
        FLASH                   : origin = 0x4400, length = 0xBB80
        FLASH2                  : origin = 0x10000,length = 0x14400

    I modified it to look like following i.e. 512 * 10 = 5120 bytes so I descended the address of FLASH2 and also shorten its length to 5120 bytes i.e. and adding this space into channels0, channels 1 and so on.

    MEMORY
    {
        SFR                     : origin = 0x0000, length = 0x0010
        PERIPHERALS_8BIT        : origin = 0x0010, length = 0x00F0
        PERIPHERALS_16BIT       : origin = 0x0100, length = 0x0100
        RAM                     : origin = 0x2400, length = 0x2000
        INFOA                   : origin = 0x1980, length = 0x0080
        INFOB                   : origin = 0x1900, length = 0x0080
        INFOC                   : origin = 0x1880, length = 0x0080
        INFOD                   : origin = 0x1800, length = 0x0080
        CHANNEL0                : origin = 0x10000,length = 0x200
        CHANNEL1                : origin = 0x10200,length = 0x200
        CHANNEL2                : origin = 0x10400,length = 0x200
        CHANNEL3                : origin = 0x10600,length = 0x200
        CHANNEL4                : origin = 0x10800,length = 0x200
        CHANNEL5                : origin = 0x10A00,length = 0x200
        CHANNEL6                : origin = 0x10C00,length = 0x200
        CHANNEL7                : origin = 0x10E00,length = 0x200
        CHANNEL8                : origin = 0x11000,length = 0x200
        CHANNEL9                : origin = 0x11200,length = 0x200
        FLASH                   : origin = 0x4400, length = 0xBB80
        FLASH2                  : origin = 0x11400,length = 0x13000

    I am not pretty sure about it and want some guidance about it.

  • Hello Jake

    I have to store a data array 10 x 10 max into the flash.

    Based on the array I have to do some manipulations and then write the results into a new array in the flash which I can later read into the PC.

    I am using msp430f6736 which has 120kb flash. I am using ccs.



    please help me out



    thanks
  • hi
    the link is not working

**Attention** This is a public forum