Anda di halaman 1dari 2

This document describes how to use customized linker script for Microchip PIC32

projects developed using Microchip MPLAB IDE and MPLAB C32 development tools.

The linker scripts for PIC32 projects are typically not listed on ‘Project’ pane of the
MPLAB IDE under ‘Linker Script’ section. This emphasizes that by default all the
projects use the built-in linker script provided with the development tools. For almost all
applications, this simplifies development task and needs no further attention. However,
for some specific projects, the developer may want to modify the linker script to suite his
specific needs.

The following text explains how to use your specific linker script.

Assumptions:
1. The MPLAB C32 is installed in following directory:
“C:\Program Files\Microchip\MPLAB C32”

Method:
1. Create project.
2. Copy linker scripts to project directory as under:
a. Copy processor specific linker script file, “procdefs.ld”, for your
particular application from following directory to your project directory
and rename it to “my_procdefs.ld”:

“C:\Program Files\Microchip\MPLAB C32\pic32mx\lib\proc”

Note: The above directory lists all PIC32 variants – from which you’ll
select variant used by your application.

b. Copy “elf32pic32mx.x” file from following directory to your project


directory and rename it in your project directory to “elf32pic32mx.ld”:

“C:\Program Files\Microchip\MPLAB C32\pic32mx\lib\ldscripts”

Note: The above mentioned directory also contains other files with
extensions such as “.xbn”, “.xn”, “.xr”, and “.xu”. For most
applications, you don’t need those files since they contain information that
guides linker to produce specific code that may not be pertinent to you. If
you are curious, open up each file and read the first line of comment in
them, which describe type of code generated by linker if you use them.
3. Add local copies of “elf32pic32mx.ld” and “my_procdefs.ld” to your project
by right-clicking on ‘Linker Script’ section of the ‘Project’ pane in your MPLAB
IDE and choosing ‘Add Files…’. By adding these files to your project, you’re
making sure that every time you change these files, the development tools will
prompt you to re-build the project and also that your local copies of the linker
scripts are used.
Note: Make sure the “elf32pic32mx.ld” file is the first one to be added to the
project. The first file added to the project is the one that the linker will use as its
main linker script.

4. Edit “elf32pic32mx.ld” such that the original line,


INCLUDE procdefs.ld
Gets changed to as follows:
INCLUDE my_procdefs.ld
This ensures that the modifications made to the local “my_procdefs.ld” file are
accounted for when you build your project.

5. Modify the linker scripts as needed to suite your project.

Anda mungkin juga menyukai