frontxc Using MPLAB X IDE and XC32 Compilers with mikroBootloader
Author: J. Bajić 
2019 03 29 172747 

This page contains information how to use MPLAB X IDE and XC32 Compilers from Michrochip with preloaded USB-HID bootloader from Mikroelektronika (i.e. mikroBootloader). More specifically, this page is dedicated to MINI-32 for PIC32MX and MINI-32 for PIC32MZ starter boards from Mikroelektronika. MikroBootloader provides free and simple way of MCU programing, however, downloading code compiled using XC32 onto MCU using mikroBootloader one might experience issues of program not executing or MCU resetting. It should be noted that this issue is not experienced if program is downloaded directly using PicKit3 Programmer. Solution proposed here is to modify MCU startup code provided by XC32 compiler in order to enable proper functionality when using mikroBootloader.

mplab x xc       mikrobootloader      pic32mx     pic32mz

The issue of program not executing or MCU resetting manifest when using XC32 compiler version v1.30 or newer which coincides with introduction of MPLAB harmony framework and particularly PIC32MZ family support (this family introduces the microMIPS compressed instruction-set architecture or ISA). Using XC32 compiler version v1.22 or earlier with mikroBootloader works fine and produces no issues. However, switching to newer compiler versions (v1.30 or newer) produces aforementioned issue. Hint of this problem can be found in XC32 release notes and it’s related to ISA mode switching and jal instruction.

Based on the way issue manifest, XC32 release notes and taking into account that using older versions of XC32 complier works fine indicated that problem was in MCU assembly startup code (crt0.S). By examining startup code in different compiler version a new startup code is produces (startup.S) which solves this issue.

Therefore, in order to successfully use MPLAB X IDE and XC32 Compilers with mikroBootloader following steps should be performed:

  1. Exclude linking of default startup code (crt0.S): In project properties under MPLAB XC32 Object Linker (xc32-ld) in Option categories dropdown select field “Libraries” and check option “Do not link crt0.S startup code”
  2. Add and link new startup code (startup.S): Copy new startup code startup.S provided here to your project directory and add this modified startup code to the MPLAB® X IDE project under Source Files.

Notice: In new startup.S macro USE_MIKROE_BOOTLOADER is defined. This macro activates skipping of assembly ISA switching code and modification of jump to startup section of the code. It will cause warning message (“Startup set for MIKROE bootloader”) to be emitted during project build. This warning can be safely ignored (it just represents a feedback info). If this macro is omitted or commented startup.S reduces to default crt0.S startup code.

Demo project (simple blink LED example) provided below is built using following ecosystem:

  1. MINI-32 For PIC32MX and MINI-32 For PIC32MZ starter boards by Mikroelektronika with a preloaded USB-HID bootloader.
  2. MPLAB X IDE v5.15 Integrated Development Environment by Microchip.
  3. XC32 v2.15 free compiler version for 32-bit MCUs by Microchip.
  4. mikroBootloader v2.8.0.0 free and simple application by Mikroelektronika for programing MCUs with a preloaded USB-HID bootloader.

Notice: For PIC32MX demo project is successfully tested using XC32 compiler version v1.1, v1.22, v1.40, v2.15 and v3.01.
For PIC32MZ demo project is successfully tested using XC32 compiler version v2.15 and v3.01.


 - PIC32 Assebmly startup code for use with mikroBootloader: startup.S
 - Demo project for PIC32MX (MINI-32 for PIC32MX) on githubsource
 - Demo project for PIC32MZ (MINI-32 for PIC32MX) on githubsource



  • step2step2
  • step1step1


Joomla Extensions
© - Faculty of Technical Sciences, Novi Sad, 2016