I think I understand now, I will try do it as you described.
Are you running with interrupts? Do you have the interrupt vectors in FLASH or do you copy them to(or construct them in) RAM?
I'm running with interrupts in flash. InterruptVectorTable is in the first sector.
Now I have problem with copy function which changes ARRAYSEL to RAM. I'm working with AN4329 application note. I wrote code from application note by myself, not copy/paste because I heard that it might couse problems. I changed optimization (speed) and code model (Far 32bit) in Properties of project.
After done point 5.2 from application note everything is ok and I can see .my_ram section and my funcInRAM() in .xMAP file.
Problem starts when I add copyToMyRAM() function. After compilation there are few problems:
Illegal 16-bit small data area relative reference to symbol '___CodeSize' from address 0x00001602 in section '.text' of file 'main_c.obj '. This type of reference has a range from 4294934528 to 32767 bytes.
Illegal 16-bit small data area relative reference to symbol '___CodeStart' from address 0x000015F2 in section '.text' of file 'main_c.obj '. This type of reference has a range from 4294934528 to 32767 bytes.
Link failed.
mingw32-make: *** [bowlcw10tst.elf] Error 1
There are my .lcf, .xMAP, source code:
# Memory ranges
MEMORY {
code (RX) : ORIGIN = 0x00000414, LENGTH = 0x0001FFE8
code_00020410 (RX) : ORIGIN = 0x00020410, LENGTH = 0x0001FBF0
userram (RWX) : ORIGIN = 0x00800000, LENGTH = 0x00007000
myram (RWX) : ORIGIN = 0x00807000, LENGTH = 0x00001000
}
SECTIONS {
# Heap and Stack sizes definition
___heap_size = 0x0400;
___stack_size = 0x0400;
# MCF51MM256 Derivative Memory map definitions from linker command files:
# ___RAM_ADDRESS, ___RAM_SIZE, ___FLASH_ADDRESS, ___FLASH_SIZE linker
# symbols must be defined in the linker command file.
# 32 Kbytes Internal SRAM
___RAM_ADDRESS = 0x00800000;
___RAM_SIZE = 0x00008000;
# 256 KByte Internal Flash Memory
___FLASH_ADDRESS = 0x00000000;
___FLASH_SIZE = 0x00040000;
.userram : {} > userram
.code : {} > code
.code1 : {} > code_00020410
.text :
{
*(.text)
. = ALIGN (0x4);
*(.rodata)
. = ALIGN (0x4);
___ROM_AT = .;
___DATA_ROM = .;
} >> code
.data : AT(___ROM_AT)
{
___DATA_RAM = .;
. = ALIGN(0x4);
*(.exception)
. = ALIGN(0x4);
__exception_table_start__ = .;
EXCEPTION
__exception_table_end__ = .;
___sinit__ = .;
STATICINIT
__START_DATA = .;
*(.data)
. = ALIGN (0x4);
__END_DATA = .;
__START_SDATA = .;
*(.sdata)
. = ALIGN (0x4);
__END_SDATA = .;
___DATA_END = .;
__SDA_BASE = .;
. = ALIGN (0x4);
} >> userram
___CodeStart = ___ROM_AT + SIZEOF(.data);
.my_ram : AT(___CodeStart)
{
. = ALIGN (0x4);
___myRAMStart = .;
*(.myCodeInRAM)
___myRAMEnd = .;
. = ALIGN (0x4);
} > myram
___CodeSize = ___myRAMEnd - ___myRAMStart;
.bss :
{
___BSS_START = .;
__START_SBSS = .;
*(.sbss)
. = ALIGN (0x4);
*(SCOMMON)
__END_SBSS = .;
__START_BSS = .;
*(.bss)
. = ALIGN (0x4);
*(COMMON)
__END_BSS = .;
___BSS_END = .;
. = ALIGN(0x4);
} >> userram
.custom :
{
___HEAP_START = .;
___heap_addr = ___HEAP_START;
___HEAP_END = ___HEAP_START + ___heap_size;
___SP_END = ___HEAP_END;
___SP_INIT = ___SP_END + ___stack_size;
___mem_limit = ___HEAP_END;
___stack_safety = 16;
. = ALIGN (0x4);
} >> userram
__SP_INIT = ___SP_INIT;
___SP_AFTER_RESET = __SP_INIT;
_romp_at = ___ROM_AT + SIZEOF(.data) + SIZEOF(.my_ram);
.romp : AT(_romp_at)
{
__S_romp = _romp_at;
WRITEW(___ROM_AT);
WRITEW(ADDR(.data));
WRITEW(SIZEOF(.data));
WRITEW(0);
WRITEW(0);
WRITEW(0);
}
}
/*********************/
extern unsigned long __CodeStart[];
#define CodeStart (unsigned long)__CodeStart;
extern unsigned long __CodeSize[];
#define CodeSize (unsigned long)__CodeSize;
extern unsigned long __myRAMStart[];
#define StartAddr (unsigned long)__myRAMStart;
/*********************/
uint8_t *Source;
uint8_t *Destiny;
uint32_t MemorySize;
/*********************/
void copyToMyRAM();
void copyToMyRAM(){
Source = (unsigned char*)CodeStart;
Destiny = (unsigned char*)StartAddr;
MemorySize = (unsigned long)CodeSize;
while(MemorySize--){
*Destiny++ = *Source++;
}
}
#pragma define_section mySectionInRAM ".myCodeInRAM" far_absolute RX
#pragma section mySectionInRAM begin
void funcInRAM();
void funcInRAM(){
}
#pragma section mySectionInRAM end
In function main() at the begining I call copyToMyRam() function and next funcInRAM() few times.
Do you have any idea what may couse this error?