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: how to specify SECTIONS in CCS Code

Other Parts Discussed in Thread: MSP430F5529

Tool/software: Code Composer Studio

Hello

I want to copy the function from flash into RAM .For that purpose i am using following code

#include "msp430.h"
#include "string.h"

// Define where the code is located in both Flash and RAM
#define flash_start_add 0x8000              // Flash code starting address
#define flash_code_size 0x01ff              // Function segment size to be copied
#define RAM_start_add   0x0200              // RAM code starting address

// Function prototypes
void write_SegC (char value);
void copy_C2D (void);

char value;                                 // 8-bit value to write to seg C
// This function is in flash to be copied to RAM
//#pragma SET_CODE_SECTION (".FLASHCODE")
#pragma CODE_SECTION(write_SegC,".FLASHCODE")
void write_SegC (char value)
{
  char *Flash_ptr;                          // Flash pointer
  unsigned int i;

  P1OUT ^= 0x02;

  Flash_ptr = (char *) 0x1040;              // Initialize Flash pointer
  while(FCTL3&BUSY);                        // Check BUSY flag; Important if running this code from RAM
  FCTL1 = FWKEY + ERASE;                    // Set Erase bit
  FCTL3 = FWKEY;                            // Clear Lock bit

  *Flash_ptr = 0;                           // Dummy write to erase Flash segment
  while(FCTL3&BUSY);                        // Check BUSY flag; Important if running this code from RAM
  FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation

  for (i=0; i<64; i++)
  {
    while(FCTL3&BUSY);                        // Check BUSY flag; Important if running this code from RAM
    *Flash_ptr++ = value;                   // Write value to flash
  }

  while(FCTL3&BUSY);                        // Check BUSY flag; Important if running this code from RAM
  FCTL1 = FWKEY;                            // Clear WRT bit
  FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}


// This function is in flash to be copied to RAM
#pragma CODE_SECTION(copy_C2D,".FLASHCODE")
void copy_C2D (void)
{
  char *Flash_ptrC;                         // Segment C pointer
  char *Flash_ptrD;                         // Segment D pointer
  unsigned int i;

  Flash_ptrC = (char *) 0x1040;             // Initialize Flash segment C pointer
  Flash_ptrD = (char *) 0x1000;             // Initialize Flash segment D pointer
  while(FCTL3&BUSY);                        // Check BUSY flag; Important if running this code from RAM
  FCTL1 = FWKEY + ERASE;                    // Set Erase bit
  FCTL3 = FWKEY;                            // Clear Lock bit
  *Flash_ptrD = 0;                          // Dummy write to erase Flash segment D
  while(FCTL3&BUSY);                        // Check BUSY flag; Important if running this code from RAM
  FCTL1 = FWKEY + WRT;                      // Set WRT bit for write operation

  for (i=0; i<64; i++)
  {
    while(FCTL3&BUSY);                        // Check BUSY flag; Important if running this code from RAM
    *Flash_ptrD++ = *Flash_ptrC++;          // copy value segment C to segment D
  }

  while(FCTL3&BUSY);                        // Check BUSY flag; Important if running this code from RAM
  FCTL1 = FWKEY;                            // Clear WRT bit
  FCTL3 = FWKEY + LOCK;                     // Set LOCK bit
}


//Copy function from Flash to RAM
void copy_flash_to_RAM(void)
{
  unsigned char *flash_start_ptr;           // Initialize pointers
  unsigned char *RAM_start_ptr;

  flash_start_ptr = (unsigned char *)flash_start_add;
  RAM_start_ptr = (unsigned char *)RAM_start_add;

  // Copy flash function to RAM
  memcpy(RAM_start_ptr,flash_start_ptr,flash_code_size);
}


void main(void)
{
  WDTCTL = WDTPW + WDTHOLD;                 // Stop WatchDog timer
  //if (CALBC1_1MHZ ==0xFF || CALDCO_1MHZ == 0xFF)
  //{
   // while(1);                               // If calibration constants erased
                                            // do not load, trap CPU!!
  //}
  //BCSCTL1 = CALBC1_1MHZ;                    // Set DCO to 1MHz
  //DCOCTL = CALDCO_1MHZ;
  //FCTL2 = FWKEY + FSSEL_1 + FN1;            // MCLK/3 for Flash Timing Generator
  P1DIR |= 0x03;
  P1OUT |= 0x00;
  value = 0;

  copy_flash_to_RAM();                      // call function to copy from flash to RAM

  // Parts of this while loop executes from Flash. The write_SegC and copy_C2D
  // is executed from RAM. The program basically will execute from FLASH until
  // it calls write_SegC function which will jump the program to RAM.
  // After executing write_SegC in RAM, it will jump back to flash to continue
  // executing. When copy_C2D is called, it jumps to RAM and back to Flash when
  // done.
  while(1)
  {
        int i;

      P1OUT ^= 0x01;
      for(i=0;i<20000;i++);                 // This portion executes from FLASH
      write_SegC(value++);                  // This portion of the code is executed from RAM
      copy_C2D();                           // This portion of the code is executed from RAM
      __no_operation();                     // Jumps back to FLASH here. Set breakpoint here
  }
}



But i am getting the warning

Description    Resource    Path    Location    Type
#10247-D creating output section ".FLASHCODE" without a SECTIONS specification                C/C++ Problem
Can you please tell me how to rectify it and download successfully in MSP430F5529 Launchpad