6.1.1 Creating Bootloader from Scratch using MCC

This section outlines the process to configure and generate a standalone bootloader for the PIC32WM-BW1 device from scratch using MCC. The user can find the bootloader example code (GPIO trigger) generated using MCC in the wireless_apps_pic32_bw1\apps\bootloader\bootloader_GPIO path.

The generated bootloader example has the following configurations:
  • Enabled UART DFU.
  • Enabled console to display messages.
  • Enabled GPIO trigger.
  • PIC32WM-BW1 Curiosity Board. The DFU mode is triggered by pressing SW2 (GPIO PA2) on the board.
  • Automatically reboot firmware after completing the DFU.
The user needs the PIC32WM-BW1 Curiosity Board hardware to run this bootloader example. The following figure illustrates the top view of the PIC32WM-BW1 Curiosity Board.
Figure 6-1. PIC32WM-BW1 Curiosity Board (EV60G68A) – Top View
The user must follow these steps to create the bootloader example (GPIO trigger) from scratch.
Note: The recommendation for the new users of MPLAB Code Configurator is to go through the MPLAB® Code Configurator (MCC) User’s Guide. For more details, refer to the MPLAB® Code Configurator (MCC) User’s Guide in the Reference Documentation from Related Links.
  1. Create a new MCC Harmony Project.
    1. From the “Device”: drop-down list, select PIC32WM_BW1 as target device. For more details on how to create a new MCC Harmony Project, refer to Creating a New MCC Harmony Project from Related Links.
    2. Launch MCC.
  2. After launching MCC, in the Device Resource window, perform the following steps:
    1. Expand Harmony>Wireless>Driver.
    2. Click the green (+) symbol next to the “Bootloader” component. This action adds the Bootloader to the Project Graph.
    3. Click Yes to accept and auto-activate any required dependencies. The MCC automatically adds and connects any additional components needed for the Bootloader to function.
    Figure 6-2. Device Resources Window – Bootloader Component
    Figure 6-3. Confirmation for Components Auto-Activation
  3. In the Project Graph window, click Bootloader component to show its configuration options.
    Figure 6-4. Bootloader Project Graph Window
    1. In the Configuration Options tab, expand “Bootloader” pane and perform the following steps:
      1. Check Enable Bootloader UART DFU.
      2. From “DFU Mode” drop-down list, select GPIO Trigger.
      3. From “GPIO Port” drop-down list, select PORT_B.
      4. From “GPIO Pin” drop-down list, increase the value to 4.
        Note: Ensure the PB2 pin is connect to SW2 on the PIC32WM-BW1 Curiosity Board.
      5. Check Enable Console.
      6. Leave “ECC Public Key” and “Supported Authentication Methods” at default.
      Figure 6-5. Bootloader Options for GPIO Trigger
    2. GPIO trigger is the option to trigger DFU mode, where the user needs to hold the GPIO button during reset to put the bootloader into DFU mode. Use the “GPIO Port” and “GPIO Pin” options to change the port and pin based on the user’s hardware.
      Note: Other than GPIO trigger, there is also another trigger option, Timer Based Trigger, where the bootloader stays in the DFU mode for a specified amount of time before jumping to the user application. The user can change the DFU Wait Time in Milliseconds to adjust the duration.
      1. From the “DFU Mode” drop-down list, select Timer Based Trigger. By doing this, the system requests activation of a 32-bit timer component TC0.
      2. Click Yes to accept adding TC0 and its connection. The following figures illustrate the timer based trigger options and the message prompt for adding TC0.
        Figure 6-6. Bootloader Options for Timer Based Trigger
        Figure 6-7. Confirmation for Components Auto-activation
    Note: For “Supported Authentication Methods”, there are three methods:
    • None
    • SHA256
    • ECDSA256
    Authentication methods with “ECC Public Key” are used to configure firmware authentication methods, including verifying firmware completion status and authenticating firmware vendor. For more details about these configurations, refer to the MPLAB Harmony PIC32CX-BZ System Services in the Reference Documentation from Related Links.
  4. In the project graph window, select Bootloader component and perform the following steps:
    Figure 6-8. SERCOM0 Project Graph Window
    1. Right click UART dependency.
    2. From the “Satisfiers” list, select SERCOM0 (sercom0). This action adds the SERCOM0 (sercom0) component to the project graph.
      Figure 6-9. Dependency of UART
  5. In the Project Graph window, click SERCOM0 component to show its configuration options.
    1. Set the “Receive Pinout” and “Transmit Pinout” options according to the PIC32WM-BW1 Curiosity Board.
    2. Leave other settings to default.
    Figure 6-10. SERCOM0 Options
  6. Expand “Peripherals” tree to add RCON component.
    1. Click the green (+) symbol next to the “RCON” component. This action adds the RCON component to the Project Graph.
    2. Leave RCON options as default.
    Figure 6-11. RCON Device Resources Window
    Figure 6-12. RCON Project Graph Window
    Note: RCON provides a software reset function. Adding the RCON component enables an automatic firmware reboot after the completion of DFU.
  7. Click Generate to create the bootloader code.
    Figure 6-13. Generate Bootloader Code
  8. To ensure the bootloader code fits within the 24-KB boot memory of the PIC32WM-BW1, perform the following steps:
    1. Replace ecc.c and crypt_ecc_pukcl.c with optimized files from wireless_pic32cxbz_wbz\utilities\pic32cx-bz\tempBtl.
  9. To enable firmware auto reboot after the completion of DFU, the host needs to send a new command to bootloader. This new command is device Reset command, defined to 0x12.
    1. In progexec.h file, add the following command:
      #define DEVICE_RESET_CMD 0x12
      Figure 6-14. Code Change in File progexec.h
    2. Then, in the progexec.c file, within the program_exec_main() function, add code to handle the device reset (RESET_CMD) command. Call RCON_SoftwareReset() to initiate a software reset. The following figure illustrates the added code.
      Figure 6-15. Code Change in File progexec.c
    Note: After completing the DFU process, the firmware auto-reboot requires a modification on the host side to send the 0x12 command to reset the device. The Python scripts, which offer an alternative method, have not yet been modified to include this support.
  10. On the MPLAB® X IDE toolbar, click Clean and Build Main Project to build the code and generate the bootloader.X.production.hex file. The precompiled hex files are available at wireless_apps_pic32_bw1\apps\bootloader\bootloader_GPIO\precompiled_hex.
    Figure 6-16. Build Bootloader Code
  11. The user must add the generated bootloader hex file to the user application as a loadable file, but the application does not use it on its own. The following are a few simple steps that the user needs to handle on the application side. For more details, see Configure User Application to Use Bootloader from Related Links.