AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel
AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel
AVR32795: Using the GNU Linker Scripts on AVR UC3 ... - Atmel
- TAGS
- linker
- scripts
- atmel
- www.atmel.com
Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
8 Frequently asked questi<strong>on</strong>s<br />
32158A-<strong>AVR</strong>-01/11<br />
<str<strong>on</strong>g><strong>AVR</strong>32795</str<strong>on</strong>g><br />
Q: How can I use my own linker script instead of <str<strong>on</strong>g>the</str<strong>on</strong>g> default <strong>on</strong>e inside a 32-bit<br />
<strong>AVR</strong> project?<br />
A: By default, avr32-gcc uses <str<strong>on</strong>g>the</str<strong>on</strong>g> default linker script from <str<strong>on</strong>g>the</str<strong>on</strong>g> <strong>AVR</strong> <str<strong>on</strong>g>GNU</str<strong>on</strong>g> toolchain.<br />
To use your own linker script in a 32-bit <strong>Atmel</strong> <strong>AVR</strong>32 Studio ® project, use <str<strong>on</strong>g>the</str<strong>on</strong>g><br />
following procedure:<br />
• Copy your linker script in <str<strong>on</strong>g>the</str<strong>on</strong>g> root of your project (use <str<strong>on</strong>g>the</str<strong>on</strong>g> import<br />
command, or simply copy/paste)<br />
• Open <str<strong>on</strong>g>the</str<strong>on</strong>g> Project Properties view (Properties item from <str<strong>on</strong>g>the</str<strong>on</strong>g> c<strong>on</strong>textual<br />
menu)<br />
• Select <str<strong>on</strong>g>the</str<strong>on</strong>g> Tool Settings tab<br />
• Select <str<strong>on</strong>g>the</str<strong>on</strong>g> <strong>AVR</strong>32/<str<strong>on</strong>g>GNU</str<strong>on</strong>g> C <str<strong>on</strong>g>Linker</str<strong>on</strong>g> -> Miscellaneous item<br />
• Add -T../my_linker_script.lds to <str<strong>on</strong>g>the</str<strong>on</strong>g> linker flags command line<br />
Your project is now ready to link with your own linker script.<br />
Q: How can I declare a variable at a specific locati<strong>on</strong> of <str<strong>on</strong>g>the</str<strong>on</strong>g> flash memory?<br />
A: To do so with GCC, a specific secti<strong>on</strong> must be created at link time.<br />
Here is an example of how to place a string variable at address 0x80010000:<br />
1. Declare <str<strong>on</strong>g>the</str<strong>on</strong>g> variable, specifying locati<strong>on</strong> in <str<strong>on</strong>g>the</str<strong>on</strong>g> .testloc secti<strong>on</strong>:<br />
c<strong>on</strong>st char string[] __attribute__ ((secti<strong>on</strong> (".testloc"))) = "String at<br />
fixed address";<br />
2. Create <str<strong>on</strong>g>the</str<strong>on</strong>g> secti<strong>on</strong> in <str<strong>on</strong>g>the</str<strong>on</strong>g> linker opti<strong>on</strong>s:<br />
• Open <str<strong>on</strong>g>the</str<strong>on</strong>g> Project Properties: highlight <str<strong>on</strong>g>the</str<strong>on</strong>g> project name and press<br />
Alt+Enter<br />
• Select <str<strong>on</strong>g>the</str<strong>on</strong>g> C/C++ Build / Settings category<br />
• Select <str<strong>on</strong>g>the</str<strong>on</strong>g> Tool Settings tab<br />
• Expand <str<strong>on</strong>g>the</str<strong>on</strong>g> <strong>AVR</strong>32/<str<strong>on</strong>g>GNU</str<strong>on</strong>g> <str<strong>on</strong>g>Linker</str<strong>on</strong>g> and highlight <str<strong>on</strong>g>the</str<strong>on</strong>g> miscellaneous item<br />
• In <str<strong>on</strong>g>the</str<strong>on</strong>g> <str<strong>on</strong>g>Linker</str<strong>on</strong>g> Flags field, add <str<strong>on</strong>g>the</str<strong>on</strong>g> -Wl,-secti<strong>on</strong>-start=.testloc=0x80010000<br />
opti<strong>on</strong><br />
Refer also to <str<strong>on</strong>g>the</str<strong>on</strong>g> screen shot below.<br />
17