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.

Flash memory and erase segment

Other Parts Discussed in Thread: MSP430F2618

I'm working with MSP430F2618 and IAR IDE.I've created the parameter on flash memory by compiler word const,for e.g.: const uint8 my_array[30];

In memory view,i saw that the parameter was located on address 0x33f6.After activating write_fl(),i saw that the erased segment was started on 0x3200 and ended on 0x33ff .As you could see,i couldn't update all my_array(30 cells) with the value ,the reset procedure was activated on my target.

My question is why the erased segment was not started from 0x33f6 ?

write_fl(my_array,30,1); ///function calling

void write_fl(char* flashMemory,uint16 lengthValue,char  value) //function prototype
{
  char *Flash_ptr;                          // Flash pointer
  unsigned int i;
  uint16  dataFlashSize = lengthValue;
 
  Flash_ptr = flashMemory;   // Initialize Flash pointer
  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 < dataFlashSize; i++)
  {
    *Flash_ptr++ = value;                // Write value to flash
  }

  FCTL1 = FWKEY;                            // Clear WRT bit
  FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}

  • I'm working with MSP430F2618 and IAR workspace as IDE.I'm trying to write to flash memory by:

    void write_flonechar(char* flashMemory,char  value)
    {
      char *Flash_ptr;                          // Flash pointer
     
      Flash_ptr = flashMemory;                  // Initialize Flash pointer
      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

      *Flash_ptr = value;                // Write value to flash

      FCTL1 = FWKEY;                            // Clear WRT bit
      FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
    }
    where ptr to flash memory is a ptr to parameter in flash,for e.g. const uint8 tmp = 0  and ptr to flash parameter is &ptr and value to write is 1

    I call write_flonechar(&ptr,1) in main().After activating this procedure,the TIUSB emulator was disconnected from my target and doesn't see my target at all like in JTAG secure blown fuse procedure.

    Could you explain this phenomena? Maybe my write to flash function has a problem.

  • Hi renka,

    pls have a look at the user manual (slau144e.pdf) page 7-3, par 7.2 FLASH MEMORY SEGMENTATION. 

    The smallest size of flash memory that can be erased is a segment, which has 512bytes. So, when your write_fl functions starts execution it erases the segment were your variable my_array is located. Because of that some other opcode/const data will also be erased which is resulting in the malfunction of your application.

    To prevent this from happening it is best to store my_array in a seperate segment in flash which can be erases without problems. Have a look at this post were I already answered your question how  to do this: http://e2e.ti.com/forums/t/8918.aspx

     Rgds
    aBUGSworstnightmare 

     

  • Hi renka,

    your write_flonechar will erase a segment in flash --> have a look at this post too: http://e2e.ti.com/forums/t/9267.aspx

    Rgds
    aBUGSworstnightmare 

**Attention** This is a public forum