Difference between revisions of "Programming HID Bootloader on PIC32"

From Mech
Jump to navigationJump to search
Line 65: Line 65:


After clicking finish, MPLAB should appear as below. On the right is the project window which contains all of the files you have added to the project. The procdefs.ld file is located under the linker file folder. This file is not the only linker file, so it needs to be moved (dragged) to the 'Other Files' folder. The procdefs.ld file tells the programmer or bootloader where to put the files. The bootloader will have a different procdefs file than the files you will load with the bootloader because you want the new programs to be put in a different spot than the bootloader on the PIC. If you use the same procdefs file as the bootloader procdefs, the bootloader will try to put the new program where the bootloader code is stored, essentially erasing the bootloader and not installing the new program. If you accidently use the bootloader procdefs file, you will have to reinstall the bootloader on the PIC.
After clicking finish, MPLAB should appear as below. On the right is the project window which contains all of the files you have added to the project. The procdefs.ld file is located under the linker file folder. This file is not the only linker file, so it needs to be moved (dragged) to the 'Other Files' folder. The procdefs.ld file tells the programmer or bootloader where to put the files. The bootloader will have a different procdefs file than the files you will load with the bootloader because you want the new programs to be put in a different spot than the bootloader on the PIC. If you use the same procdefs file as the bootloader procdefs, the bootloader will try to put the new program where the bootloader code is stored, essentially erasing the bootloader and not installing the new program. If you accidently use the bootloader procdefs file, you will have to reinstall the bootloader on the PIC.
[[Image:MPLAB_StartWindow.jpg|thumb|300 px|left]]
[[Image:MPLAB_StartWindow.jpg|thumb|500 px|left]]
<br clear=all>
<br clear=all>



Revision as of 14:54, 21 August 2009

The HID (Human Interface Device) bootloader is used to install programs on the PIC32 without using an external programmer like ICD2 and does not require any drivers on the computer. The HID bootloader for the PC is supplied with the Microchip Applications Library.

Software

PIC software

You can download the PIC32 hex file and source files here. I recommend placing these files in a new folder. This will become your project folder.

PC software

If you downloaded the Microchip Applications Library, the PC HID Bootloader program is located under the start menu Programs -> Microchip -> MCHPFSUSB v2.5 -> Tools -> HIDBootLoader You can also download the executable here. Running this requires a sufficiently recent version of the .NET Framework, which you may not have if you are running XP or earlier versions of Windows. You can download a sufficiently recent version here (the install takes a while): .NET Framework download.

Required circuitry

For the UBW32 and NU32 board, this circuitry is already on the board. This information is for people who are interested in making their own board.

A button must be wired to a pin that has been initialized as a digital input (similar to the RESET button). This PROGRAM button is used to put the PIC in Bootloading Mode. The UBW32 and NU32 board has the button wired to PIN E7 and PIN E5, respectively. The button can be put on any pin that supports digital input, but the bootloading program will have to be modified accordingly.

The PIC goes into Bootloading Mode when the PROGRAM button is held down when a RESET is called (ie hold down both PROGRAM and RESET and then release RESET). LEDS on the boards will flash to indicate that the PIC is in Bootloading Mode.

Installing a Bootloader on the PIC32

These directions detail how to start a new MPLAB project and program the HID Bootloader on the PIC32 with the Microchip MPLAB ICD 2 (In-Circuit Debugger). Before starting, Microchip MPLAB, Microchip C32 Compiler and the Microchip Applications Library must be installed.


Under Construction (ignore what's below)

Notes - Create New Project - Add files - Include Search Path - Add Device Name - Add Source Files USB


  • Open MPLAB IDE.


  • Choose Configure>Select Device to select the PIC you are working with. In the Device dialog, select the PIC you are using from the list if it’s not already selected. The lights show which software is supported for that PIC.
MPLAB DeviceConfigure.jpg


  • Choose Project>Project Wizard to start a new project. Click Next
MPLAB ProjectWizardStart.jpg


  • Select the PIC from the drop down menu. Click Next
MPLAB ProjectWizardDevice.jpg


  • Select the Microchip PIC32 C-Compiler Toolsuite from the drop down menu. Click Next
MPLAB ProjectWizardToolsuite.jpg


  • Create a new project (I called it HIDBoot) in the folder where you want the project to be stored. I recommend creating a folder that contains the source code for each project. Click Next
MPLAB ProjectWizardNewProject.jpg


  • Add the following the c files to the project.
    • HardwareProfile.h (generic header file for many different boards)
    • HardwareProfile_NU32.h (hardware profile for the NU32, if you have your own hardware profile you will need to add it to the generic HardwareProfile.h)
    • main.c (the main source file)
    • main.h
    • procdefs.ld (a linker file read here for more discussion of why this linker file is important)
    • usb_config.h (header file to configure usb communication)
    • usb_descriptors.c (source file for usb communication)

Click Next

MPLAB ProjectWizardAddFiles.jpg


  • Click Finish
MPLAB ProjectWizardFinish.jpg


After clicking finish, MPLAB should appear as below. On the right is the project window which contains all of the files you have added to the project. The procdefs.ld file is located under the linker file folder. This file is not the only linker file, so it needs to be moved (dragged) to the 'Other Files' folder. The procdefs.ld file tells the programmer or bootloader where to put the files. The bootloader will have a different procdefs file than the files you will load with the bootloader because you want the new programs to be put in a different spot than the bootloader on the PIC. If you use the same procdefs file as the bootloader procdefs, the bootloader will try to put the new program where the bootloader code is stored, essentially erasing the bootloader and not installing the new program. If you accidently use the bootloader procdefs file, you will have to reinstall the bootloader on the PIC.

MPLAB StartWindow.jpg


MPLAB needs to be pointed to the location of the header files of the Microchip Framework.

  • Choose Project>Build Options>Project.
  • In the directories tab, choose the Include Search Path.
  • Add a New path - Browse to find the include folder (<Installation Folder> \Microchip Solutions\Microchip\Include)
  • Add a New path - Browse to find the folder where you have the project
  • Click OK
MPLAB IncludeSearchPath.jpg