5.4.5 Startup and Initialization

Note: Some PIC32 target devices allow you to select to boot in either the MIPS32® or microMIPS™ ISA mode via a device configuration bit (BOOTISA). On these devices, if your BOOTISA bit is set to microMIPS mode, pass the -mmicromips mode to the xc32-gcc/g++ compilation driver to tell it to link with the microMIPS variant of the runtime start-up code. If your BOOTISA bit is set to MIPS32 mode, pass the -mno-micromips option to the compilation driver so that the MIPS32 variant of the runtime start-up code is linked.

The runtime startup code performs initialization tasks that must be executed before the main() function in the C/C++ program is executed. For information on the tasks performed by this code, see 18 Main, Runtime Start-up and Reset.

The compiler will select the appropriate runtime startup code, based on the selected target device and other compiler options.

  • The startup code initializes the L1 cache when available.
  • It enables the DSPr2 engine when available.
  • It also initializes the Translation Lookaside Buffer (TLB) of the Memory Management Unit (MMU) for the External Bus Interface (EBI) or Serial Quad Interface (SQI) when available. The device-specific linker script creates a table of TLB initialization values that the startup code uses to initialize the TLB at startup.
Important: When your target MCU is configured to use the microMIPS compressed ISA at startup (and for interrupts/exceptions), be sure to pass the -mmicromips option to xc32-gcc when linking, and use the micromips function attribute on all of your Interrupt Service Routines (ISRs). Using the -mmicromips option and the micromips attribute ensures that your startup code and ISR code are compiled for the microMIPS ISA when the BOOTISA Configuration bit is set to micromips. Likewise, be sure that you linkwith the MIPS32 startup code, and your ISRs are not micromips attributed when the BOOTISA bit is set to MIPS32.

For C:

There is only one start-up module, which initializes the C runtime environment.

The source code for this is found in the pic32m-libs.zip file located at:

<install-directory>/pic32-libs/

Once the file is unzipped, the source code can be found at:

pic32m-libs/libpic32/startup/crt0.S.

It is precompiled into the following library location:

<install-directory>/pic32mx/lib/crt0.o.

Multilib versions of these modules exist in order to support architectural differences between device families.

For C++:

Code from five object files link sequentially to create a single initialization routine, which initializes the C++ runtime environment.

The PIC32M precompiled startup objects are located in the following location:

<install-directory>/pic32mx/lib/.

The files have the following names: cpprt0.o, crti.o, and crtn.o.

The GCC precompiled startup objects are located in the following location:

<install-directory>/lib/gcc/pic32mx/<gcc-version>/.

The files have the following names: crtbegin.o and crtend.o.

Multilib variations of these modules exist in order to support architectural differences between device families and also optimization settings.

For more information about what the code in these start-up modules actual does, see 18.2 Runtime Start-Up Code.