The bootloader facilitates program installation on the PIC32, eliminating the need for an external programmer such as an ICD2 and eliminating the requirement for computer drivers. The PC software necessary for the bootloader is pre-installed alongside the Microchip Applications Library.
Software
PIC Source Code
To set up each new program, youâll need to establish a dedicated folder that contains both the source code files and the project file, which houses additional program details not found in the source code. Hereâs a step-by-step guide:
1. I suggest creating a folder named âPIC32_Codeâ to act as a repository for all your project folders.
2. Inside your âPIC32_Codeâ directory, generate a new folder and name it âBootloader.â
3. Download the PIC32 bootloader zip file from this location.
4. Unzip the downloaded file into the âBootloaderâ folder. Ensure you copy and paste the files from within the unzipped folder into the âBootloaderâ directory. After completing this step, the âBootloaderâ folder should contain seven additional files in addition to the original zip file and folder.
Please note that these files were tested with the Applications Library as of November 18, 2009. If you are using a different library, be aware that these files may not function as intended.
PC software
To load files using the bootloader, you need to utilize an application on your PC known as the HID Bootloader. This bootloader should be included in the application library.
â Ensure that you can find the HID Bootloader in the Start menu under Programs -> Microchip -> MCHPFSUSB v2.6 -> Tools -> HIDBootLoader. Donât run the program at this point; just confirm its presence.
Running the HIDBootLoader necessitates a fairly recent .NET Framework version, which may not be available if youâre using Windows XP or earlier versions. This concern should have been addressed during the installation of the Applications Library. You can obtain a suitably recent version by downloading it here (please note that the installation may take some time): .NET Framework download.
Installing a Bootloader on the PIC32 with ICD2
These instructions provide a step-by-step guide for initiating a fresh MPLAB project and implementing the HID Bootloader on the PIC32 using the Microchip MPLAB ICD 2, an In-Circuit Debugger.
Our objective is to establish a project for embedding the bootloader into the PIC32. This code must be loaded onto the PIC32 only once. Subsequently, you wonât require the ICD2 for PIC programming.
Starting a New MPLAB Project
- Launch MPLAB IDE.
- Navigate to the âConfigureâ menu and then select âSelect Deviceâ to choose the PIC32MX460F512L (the specific PIC model you are currently working with). Within the Device dialog, ensure that the appropriate PIC model is selected from the provided list, and take note of the illuminated indicators that indicate the compatible software for that particular PIC.
- Choose Project>Project Wizard to start a new project. Click Next
- Select the PIC32MX460F512L from the drop down menu. (It might already be selected) Click Next
- Select the Microchip PIC32 C-Compiler Toolsuite from the drop down menu. Click Next
- Create a new project (I called it Bootloader) in the Bootloader folder. Click Next
Please include the following C files in the project. These files should already exist within the Bootloader folder:
1. HardwareProfile.h (a universal header file for various boards)
2. HardwareProfile_NU32.h (hardware configuration specific to NU32; if you have a custom hardware profile, it should be appended to the general HardwareProfile.h)
3. main.c (the primary source file)
4. main.h
5. procdefs.ld (a linker file)
6. usb_config.h (header file for configuring USB communication)
7. usb_descriptors.c (source file for USB communication)
Please proceed by clicking âNext.â
- Click Finish
Creating Bootloader Hex File
Upon completing the setup, MPLAB should display the following interface. The project window showcases all the files youâve integrated into the project. Specifically, the âprocdefs.ldâ file can be found within the linker file folder. Itâs important to note that this file isnât the sole linker file, so you should relocate it by dragging it into the âOther Filesâ folder.
The purpose of the âprocdefs.ldâ file is to instruct the programmer or bootloader on where to place files. Itâs crucial to have a distinct âprocdefsâ file for the bootloader and the files you intend to load with the bootloader. This separation ensures that new programs are stored in a different location than the bootloader on the PIC. If you mistakenly use the same âprocdefsâ file as the one used for the bootloader, the bootloader will attempt to overwrite itself, effectively erasing it and failing to install the new program. In such a scenario, youâll need to re-install the bootloader on the PIC.
To set up MPLAB to locate the header files from the Microchip Applications Library, follow these steps:
1. Navigate to Project>Build Options>Project in MPLAB.
2. Within the âDirectoriesâ tab, select âInclude Search Pathâ from the dropdown menu.
3. Add a new path by browsing to the location of the âincludeâ folder (e.g., C:\Microchip Solutions\Microchip\Include).
4. Add another new path by browsing to the folder where your project is located.
5. Click the âOKâ button to confirm and save your changes.
As the bootloader relies on the USB source files from the Microchip Framework, we need to incorporate these source files and specific USB header files into the project. Iâve organized these files into sub-folders in the project window as outlined below.
1. Within the project window, right-click on âSource Filesâ and select âCreate Subfolder.â Iâve named this new folder âUSB Framework.â
2. Right-click on the newly created folder and choose âAdd Files.â Incorporate the following files:
â usb_device.c from ⌠-> Microchip Solutions -> Microchip -> USB
â usb_function_hid.c from ⌠-> Microchip Solutions -> Microchip -> USB -> HID Device Driver
3. In the project window, right-click on âHeader Filesâ and select âCreate Subfolder.â Name this folder âUSB Framework.â
4. Right-click on the newly created folder and choose âAdd Files.â Integrate 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âre using a generic HardwareProfile, itâs important to specify the board to MPLAB. Essentially, we are providing MPLAB with a constant that indicates the board to use.
1. Navigate to Project -> Build Options -> Project and click on the MPLAB PIC32 C Compiler Tab.
2. Currently, the preprocessor macros window is empty. We need to create a variable defined for our board. Click âAddâ and enter âPIC32_NU32â if youâre working with the Northwestern PIC32 board.
3. Click âOK.â
4. Click âOKâ again.
To minimize the size of the Bootloader Hex file and ensure it occupies minimal space on the PIC, itâs important to optimize the compiler for the smallest code size. Failure to do so may result in the bootloader not functioning properly.
1. Navigate to Project -> Build Options and click on the MPLAB PIC32 C Compiler Tab as previously.
2. Click on the âOptimizationâ category.
3. Select the âsâ option for the smallest size, as depicted below. If this option is unavailable, choose the smallest code size available.