MPLAB X and Pinguino PIC32 DIY

In this article I will show you how to use the Microchip MPLAB_X Integrated Development Environment for implement an application and upload it to the Pinguino PIC32 DIY board through the bootloader.

This procedure has been tested on this board but with minor changes it can be used with any kind of Pinguino Board supported by the Pinguino IDE. I will assume that you are already confident with the MPLAB_X usage so I will focus only about the changes that have to be carried out to allows direct uploading through the bootloader.

First in the MPLAB-X I picked a template with "New Project - Samples - Microchip Embedded and I choose PIC32 C Template. Then in File - Project Properties I've selected the right processor and compiler XC32. In my case it was the PIC32MX250F128B but I guess the same procedure apply for all processor. Only pay attention to use the specific file tailored for your Pic. At this point the template wizard has inserted in the program tree many .c and .h that are the skeleton for the application.



From the skeleton files you now can delete any file you dont need. A good programming practice is to use separate file to implement different function in the code so for very large programs will be easy to find the part you need to edit. If you choose to clean and build when you finish to write the code the compiler should complete without errors. The .hex file generated at this point is not suitable to be uploaded through the bootloader because the absolute address of the program code and other memory areas does not take into account the structure the bootloader expect.

In order to make the application loadable with the bootloader you need to add a file in the program tree structure in MPLAB under the tab linker-files

1. Step: Copy the file /opt/microchip/xc32/v1.31/pic32mx/lib/ldscripts/elf32pic32mx.x in the root directory of your project, usually in the directory MPLABXProjects/

2. Step: Rename the file elf32pic32mx.x to elf32pic32mx.ld then in MPLAB add this existing file in the Linker Files tree structure

3. Step: Open in MPLAB editor this file elf32PIC32MX.ld and comment out the line that say

Now we have to add here the procdefs.ld file that came with the Pinguino IDE that have all the reference to the memory address areas used with the bootloader. For my processor this file is x.4/p32/lkr/PINGUINO32MX250/procdefs.ld under the directory where you installed the IDE.

4. Step Copy this file and insert it where it was INCLUDE procdefs.ld in the elf32pic32mx.ld file

5. Step Since the template include the peripheral lib that has been excluded in the pinguino ide procdefs.ld you need to add this two lines

after the line

in the elf32PIC32MX.ld modified. Now you can clean and rebuild everything that should be error free. To upload the hex file which is located in /MPLABXProjects/ /dist/XC32_PIC32MX250F128B/production #

I used pic32prog that you can download at https://code.google.com/p/pic32prog/

The upload command is

If you want to perform and automatic upload to the board after compiling and build you can add this line

in the MPLAB-X project properties under the section building at the voice "Execute this line after building"

Enjoy Pinguino. Fabio.