Difference between revisions of "Programming HID Bootloader on PIC32"
Andrew Long (talk | contribs) |
Andrew Long (talk | contribs) |
||
Line 94: | Line 94: | ||
*Choose Project -> Build All |
*Choose Project -> Build All |
||
This compiles and creates a Hex File in the project folder to be loaded on to the PIC. |
This compiles and creates a Hex File in the project folder to be loaded on to the PIC. |
||
==Loading Bootloader on PIC with ICD2== |
|||
These directions detail how to load a file (in this case a bootloader) on the PIC with [http://www.microchip.com/stellent/idcplg?IdcService=SS_GET_PAGE&nodeId=1406&dDocName=en010046 ICD2] (In Circuit-Debugger) |
|||
= Notes for Loading Bootloader with Own Board = |
= Notes for Loading Bootloader with Own Board = |
Revision as of 14:24, 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.
Starting a New MPLAB Project
- 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.
- Choose Project>Project Wizard to start a new project. Click Next
- Select the PIC from the drop down menu. Click Next
- Select the Microchip PIC32 C-Compiler Toolsuite from the drop down menu. Click Next
- 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
- 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
- Click Finish
Setting up Bootloader
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 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
Since the bootloader uses the USB source files of the Microchip Framework, we need to add the source files and some USB header files to the project. I put these files in sub-folders in the project window as noted below.
- In the project window, right click on 'Source Files' and click 'Create Subfolder'. I called the folder 'USB Framework'
- Right click on the new folder and select 'Add Files'
- Add the following files
- usb_device.c from ... -> Microchip Solutions -> Microchip -> USB
- usb_function_hid.c from ... -> Microchip Solutions -> Microchip -> USB -> HID Device Driver
- In the project window, right click on 'Header Files' and click 'Create Subfolder'. I called the folder 'USB Framework'
- Right click on the new folder and select 'Add Files'
- Add the following files from ... -> Microchip Solutions -> Microchip -> Include -> USB
- usb.h
- usb_ch9.h
- usb_common.h
- usb_device.h
- usb_function_hid.h
- usb_hal.h
- usb_hal_pic32.h
Since we have a generic HardwareProfile we need to tell MPLAB which board we are using. We are essentially going to give MPLAB a constant that indicates which board to use.
- Choose Project -> Build Options and click on the MPLAB PIC32 C Compiler Tab
- The window for preprocessor macros is currently empty. We want to create a variable that is defined for our board. Click Add and type PIC32_NU32 if using the Northwestern PIC32 board.
- Click OK
If you are using the PIC32_NU32, you are ready to compile the project. If you are using a board other than the PIC32_NU32, make sure you follow all the directions in Notes for Loading Bootloader with Own Board.
- Choose Project -> Build All
This compiles and creates a Hex File in the project folder to be loaded on to the PIC.
Loading Bootloader on PIC with ICD2
These directions detail how to load a file (in this case a bootloader) on the PIC with ICD2 (In Circuit-Debugger)
Notes for Loading Bootloader with Own Board
If you are loading a bootloader with a board that is not included in the HardwareProfile header file. You will need to do the following tasks.
- Define a board constant in MPLAB PIC32 C Compiler Tab in Project -> Build options (ex. PIC32_NU32)
- Put the following line in the HardwareProfile under the correct compiler (ex __C32__) and PIC (ex __32MX460F512L__)
#elif defined(YOUR_BOARD_CONSTANT) #include "YOUR_HARDWAREPROFILE.h"
where YOUR_BOARD_CONSTANT is the constant you put in the compiler tab and YOUR_HARDWAREPROFILE.h is the profile header file for your board.
- In main.c, you will need to add a section for the configuration bits for your board as shown below:
#elif defined(YOUR_BOARD_CONSTANT) the configuration...