EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

Problems in writing into Flash Memory using IAR Embedded Workbench 3.2A

Started by vanni_ellul September 30, 2005
Hi all,

I have a problem in writing into Flash Memory using IAR Embedded 
Workbench 3.2A.

The piece of code I am using was functioning perfectly when using 
the previous editions of IAR Embedded Workbench i.e. V1.26B.  The 
code I am using is very much similiar to example code supplied by TI 
i.e. fet120_flash_write.  Thankyou in advance for any suggestions.  
A copy of the code I am using can be found at the end of this note.

Thank you in advance.

Vanni

The code I am using:

// To stop interrupts
_DINT();

// To disable watchdog
 WDTCTL = WDTPW + WDTHOLD;        // Stop WDT

void Write2flash(void)
{ 
  char *Flash_ptrA;               // Segment A pointer
  char *Flash_ptrB;               // Segment B pointer
  char *Flash_ptr;                // Flash pointer
  unsigned int i;

  FCTL2 = FWKEY + FSSEL0 + FN0;   // MCLK/2 for Flash Timing 
                                  // Generator

//------------------------copy of segment A to B---------------------

  Flash_ptrA = (char *) 0x1000;   // Initialize Flash segment A 
                                  // pointer
  Flash_ptrB = (char *) 0x1080;   // Initialize Flash segment B 
                                  // pointer  
  FCTL1 = FWKEY + ERASE;          // Set Erase bit
  FCTL3 = FWKEY;                  // Clear Lock bit
  *Flash_ptrB = 0;                // Dummy write to erase Flash 
                                  // segment B
  FCTL1 = FWKEY + WRT;            // Set WRT bit for write operation 

  for (i=0; i<128;i++)
  {
    *Flash_ptrB++ = *Flash_ptrA++; // copy value segment A to 
                                   // segment B
  }
  
//------------------------------write to flash---------------------

  Flash_ptr = (char *) 0x1000;    // Initialize Flash pointer  
  FCTL1 = FWKEY + ERASE;          // Set Erase bit
  FCTL3 = FWKEY;                  // Clear Lock bit
  *Flash_ptr = 0;                 // Dummy write to erase Flash  
                                  // segment
  
  FCTL1 = FWKEY + WRT;            // Set WRT bit for write operation

  for (i=0; i<7;i++)
  {
    
    *Flash_ptr++ = flash_parameter[i];   // Write value to flash
  }

  Flash_ptrB = (char *) 0x1087;   // Init Flash segment B pointer  

  for (i=7; i<128;i++)
  {
    *Flash_ptr++ = *Flash_ptrB++; // copy val segment B to segment A
  }


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

// to enable interrupts
_EINT();



Beginning Microcontrollers with the MSP430


The 2024 Embedded Online Conference