I am building an application for AT91SAM7X256 using mostly Atmel standard peripheral libraries but also some other methods and headers I have added to them. When compiling for the flash (choosing “flash-SAM-ICE” from the drop down list) the application is built and linked without a single error and warning:
linking... Program Size: Code=24336 RO-data=51312 RW-data=116 ZI-data=8920 FromELF: creating hex file... ".\at91sam7x256-flash\at91sam7x256-flash.axf" - 0 Error(s), 0 Warning(s).
It is linked using a scatter file provided by Atmel (I have just added some comments to the file): ; *------------------------------------------------------------------------------ ; * Linker scatter for running in internal FLASH on the AT91SAM7X256 ; *------------------------------------------------------------------------------
Load_region 0x100000 0x40000
;baseAddress=0x100000(1MB) maxSize=0x40000(256KB) {
;baseAddress=0x100000 maxSize=0x40000(256KB)
Fixed_region 0x100000 0x40000 {*(cstartup +First).ANY (+RO)}
;baseAddress=0x200000(2MB)
Relocate_region 0x200000 {*.o (VECTOR, +First) .ANY (+RW +ZI)}
ARM_LIB_HEAP 0x20E000 EMPTY 0x1000 {};heap area
ARM_LIB_STACK 0x210000 EMPTY -0x1000 {}
;Stack region growing down from the base address of 2MB + 64KB (bottom of sram)
}
/*================================================== However when I choose “sram-SAM-ICE” and attempt to compile and link the application for SARM a bunch of linker errors start to show up:
.\at91sam7x256-sram\at91sam7x256-sram.axf: Error: L6220E: Load region Load_region size (75692 bytes) exceeds limit (65536 bytes). Region contains 13 bytes of padding and 40 bytes of veneers (total 53 bytes of linker generated content). .\at91sam7x256-sram\at91sam7x256-sram.axf: Error: L6221E: Execution region Fixed_region with Execution range [0x00200000,0x002126a4) overlaps with Execution region ARM_LIB_HEAP with Execution range [0x0020e000,0x0020f000). .\at91sam7x256-sram\at91sam7x256-sram.axf: Error: L6221E: Execution region Fixed_region with Execution range [0x00200000,0x002126a4) overlaps with Execution region ARM_LIB_STACK with Execution range [0x0020f000,0x00210000).
The sram is supposed to link using an Atmel scatter file: ; *------------------------------------------------------------------------------ ; * Linker scatter for running in internal SRAM on the AT91SAM7X256 ; *----------------------------------------------------------------------------*/
Load_region 0x200000 0x10000 ;basedAdress=2MB maxSize=256KB {
;baseAddress=2MB
Fixed_region 0x200000 {*.o (VECTOR, +First).ANY (+RO)}
;second execution area with assembly startup code at the start and then all RW and ZI
Relocate_region +0 {*(cstartup +First).ANY (+RW +ZI)}
ScatterAssert((ImageLength(Fixed_region) + ImageLength(Relocate_region)) < 0xE000)
;Stack region growing down from the base address of 2MB + 64KB (bottom of sram) } /*================================================== It seems the SRAM scatter file is healthy as it has allocated all 64KB of SRAM available in AT91SAMX256 to the application with the exception of a small area allocated to heap and stack. But my application keeps failing during linking. I have noticed there are two header files each containing an enormous parameter which is supposed to be implemented in flash as a constant:
const unsigned short picture1[] = {0x0000,0x0000,……}; //about 30KB in size const unsigned short picture1[] = {0x0000,0x0000,……}; //about 20KB in size
When I clip the size of these variables or eliminate them altogether, the sram file is successfully linked (albeit the resulting hex file is substantially smaller as the RO data is reduced to 1460): linking... Program Size: Code=24296 RO-data=1460 RW-data=116 ZI-data=8920 FromELF: creating hex file...
Now I have two questions: 1- Clearly those two constant variables are NOT being implemented in flash as intended (I have imported them from an application for LPC2378 and there was no problem there). What am I doing wrong here? How could I ensure they are allocated in flash and not in sram? Is it not enough “to define” them as “const unsigned short picture1[] =”? 2- I have been going through the 400 page linker manual and I find it somehow weak in terms of examples. I can’t get a single command to work in scatter file no matter what configuration I try. Using attributes and scatter file commands How can force those two variables to be allocated at an absolute address in flash?