Monday, December 3, 2012

Load hex into MPLAB

How can I use my HEX files with MPLAB tools to program my target?

MPLAB is the IDE Microchip provides and provides programming support for all Microchip tools (PICSTART Plus, Promate, ICD2, etc). This provides a simple guide on how to import the HEX file into MPLAB so it can be programmed into your target. For more MPLAB documentation please refer to Microchip's documentation.
First, be sure that your HEX file will run stand-alone (doesn't need a debugger). Click here for pointers on creating a stand-alone HEX file.

Follow these steps:
  1. Start MPLAB. All steps in this FAQ that refer to a toolbar means the toolbar of MPLAB.

  2. Make sure no other project/workspace is open by selecting File -> Close Workspace from the toolbar.

  3. Select your target device by selecting Configure -> Select Device. This will bring-up a dialog where you select your target PIC®MCU(PIC16F877A, PIC18F4520, etc). It also will tell you if your programming tool is supported for this device.

  4. Open the Configuration Bits dialog by selecting Configure -> Configuration Bits from the toolbar. This will open a new dialog window, at the very top of this window you will see a checkbox labeled 'Configuration bits set in code', make sure this checkbox is SET. Failure to do this will cause invalid configuration bits to be written to the device.

  5. Select your programming tool by selecting the Programmer item from the toolbar. This will give you a list of selectable programmers.

  6. Import your HEX file by selecting File -> Import from the toolbar. This will load the HEX file into memory. Importing the hex BEFORE you selected programmer or selected target device will cause the HEX file to be cleared from memory, so it is important to do it in the order shown here.

  7. Program your device. This is done via the Programmer item from the toolbar. This process is different for each programming tool. But for the ICD2, you first need to connect to the device withProgrammer -> Connect Device, and the program the device with Programmer -> Program

  8. Repeat the previous step for each target microcontroller that you wish to program with this HEX file.



    The PIC32 chipKit board is designed to use in an Arduino™ style environment called MPIDE (Multi Platform Integrated Development Environment).

    The bootloader is the same bootloader as used in the Arduino™ Mega 2560 board. This bootloader uses STK500V2 protocol. Avrdude is used to talk to it.

    In the normal Arduino™ environment you can use the Arduino™ IDE to burn the bootloader. It uses an ISP (In System Programmer) to do the actuall programming of the bootloader. PIC32 does not support the same style of ISP programmer and therefore cannot be used to burn the pic32 bootloader.

    To program the bootloader on a PIC32 chip, you need to use an ICD or PicKit programmer. I use the ICD-3 but the PicKit-3 also works. This is done from MPLAB, the Microchip development environment. There are several versions. The new MPLAB-X is cross platform and can be downloaded free.

    MPLAB-X on the Mac was used to develop the bootloader. The bootloader source and the MPLAB-X project will be on githup (as of May 22, 2011 it is not there yet).

  2. The bootloader repository.

  3. The step by step procedure of burning chipKIT bootloader.