You can easily modify your linker script.
Or per se, use an external linker script.
How do you do it?
Read on.
Mplab X generates its Makefile upon those files, which are added to the project view.
You don't have to add them to the project by hand, like in eclipse:
This is indeed plain and simple, but as a side mark, it is very annoying that the actual file location gets out of sync with it's project location.
But let's get to the linker part.
To modify your linker, first you have to find, which is actually used. Build your project, and look for this output message:
"C:\Program Files (x86)\Microchip\xc16\v1.20\bin\xc16-gcc.exe" -o dist/C30_dsPIC33FJ256GP710A/production/dspic33_c_template_1.X.production.elf build/C30_dsPIC33FJ256GP710A/production/configuration_bits.o build/C30_dsPIC33FJ256GP710A/production/interrupts.o build/C30_dsPIC33FJ256GP710A/production/main.o build/C30_dsPIC33FJ256GP710A/production/system.o build/C30_dsPIC33FJ256GP710A/production/traps.o build/C30_dsPIC33FJ256GP710A/production/user.o build/C30_dsPIC33FJ256GP710A/production/userinit.o -mcpu=33FJ256GP710A -omf=elf -Wl,--defsym=__MPLAB_BUILD=1,,--script="lkr\p33FJ256GP710A.gld",--check-sections,--data-init,--pack-data,--handles,--isr,--gc-sections,--fill-upper=0,--stackguard=16,--no-force-link,--smart-io,-Map="dist/C30_dsPIC33FJ256GP710A/production/dspic33_c_template_1.X.production.map"
Keep a lookout for this part: --script="lkr\p33FJ256GP710A.gld"
Now locate that file. Mine is here:
c:\Program Files (x86)\Microchip\xc16\v1.20\support\dsPIC33F\gld\
Copy that to your project, for example in a /lkr folder. Then add it to your Linker Files directory in the Project view. From the on, this linker script will be used by the linker.
See the demonstration video.
But what if you want to have multiple configurations, which require different linker scripts?
You just add every linker file to the Linker Files directory, right click on the one you don't want to be active with a specific build, and then tell it to exclude it from the build.
I liked very much your video aand explanation here, helped me start. But, I want to change the linker script to reserv parts of the Flash memory for non-volatile data and to prevent writing to Program MEMORY regions and not corrupt any executing code. How can I do that ? Any tips ?
ReplyDelete