Relocating Code and Data in Internal RAM

Since it is not possible to write a variable in ROM, data must be relocated in RAM. Code can be also relocated in RAM. Another reason to relocate code in RAM is that it is twice as fast as in Flash.

To relocate code and data in internal RAM, create a new section using section pragma directive and __declspec directives as shown in the listing below.

Listing 1. Using pragma Directives to Define a Section
#pragma section  ".myCodeInRAM" data_mode=far_abs
__declspec(section ".myCodeInRAM")

struct {

unsigned char data0;

unsigned char data1;

unsigned char data2;

unsigned char data3;

unsigned char data4;

unsigned char data5;

unsigned char data6;

unsigned char data7;

} CTMData = { 0x82, 0x65, 0x77, 0x32, 0x84, 0x69, 0x83, 0x84 };

__declspec(section ".myCodeInRAM")  void funcInROM(int flag); 

 void funcInROM(int flag){

if (flag > 0)

{

flag++;

}

}
Related information
Predefined Sections
Additional Small Data Sections
Linker Map File
Deadstripping
CodeWarrior Linker Command File (LCF)
Creating an LCF from Scratch
Relocating Code in ROM
Relocating Code and Data in External MRAM
Unique LCF Examples
Linker Command File Commands