Jump to main content

##

# 3.5.1 Live Update Application on PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit

Download

## Description

The Live update application uses the dual bank Flash feature available on the PIC32MZ Microcontrollers (MCUs). The banks on PIC32MZ MCU are named as BANK1 and BANK2. At any point of time, the application considers the bank on which it is currently executing from as active bank while the other bank is marked as inactive bank. The dual bank Flash enables programming the inactive bank with a new version of the firmware while running the current version of the firmware from the active bank. The application updates the new version of the firmware to the inactive bank while the current version of the firmware runs from the active bank.

The application identifies the Flash bank which has the latest version of the firmware (active bank) and toggles a specific LED at a periodic rate. For example, it starts with toggling LED1 and when there is bank swap (active bank changed following successful upgrade), it toggles LED2. Similarly, the process repeats for every successful application firmware update.

## Modules/Technology Used

- Peripheral Modules
  - NVM
  - CORE TIMER
  - UART
  - Harmony Core

## Hardware Used

- PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit

## Software/Tools Used

This project has been verified to work with the following versions of software tools:

Refer Project Manifest present in harmony-manifest-success.yml under the project folder firmware/src/config/pic32mz_ef_sk

- Refer the Release Notes to know the MPLAB X IDE and MCC Plugin version.
- Any Serial Terminal application, such as Tera Term terminal application.
- Windows command prompt
- Python 2.7

Because Microchip regularly updates tools, occasionally issue(s) could be discovered while using the newer versions of the tools. If the project does not seem to work and version incompatibility is suspected. It is recommended to double-check and use the same versions that the project was tested with. To download original version of MPLAB Harmony v3 packages, refer to document How to Use the MPLAB Harmony v3 Project Manifest Feature (DS90003305).

## Setup

- Connect a mini USB cable to the UART-USB port J11.
- For programming, connect a mini USB cable to the USB Debug port J3.

## Programming/Debugging Application Project

- Open the project (pic32mz_uart_live_update/firmware/pic32mz_ef_sk.X) in MPLAB X IDE.
- Ensure Starter Kits (PKOB) is selected as hardware tool to program/debug the application.
- Build the code and program the device by clicking on the Make and Program Device button in MPLAB X IDE tool bar.
- Follow the steps in Running the Demo section below.

## Running the Bootloader Application

For the first time, the Live update application is programmed by using either Harmony basic bootloader or Harmony fail-safe bootloader.

1. Download the MPLAB Harmony Bootloader and Bootloader UART Apps packages.
2. Connect a mini USB cable to the DEBUG port of the PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit.
3. Build and program the UART fail safe bootloader (Dual bank bootloader) which is in (path:

       <Your Harmony Framework download
                 folder>/bootloader_apps_uart/apps/uart_fail_safe_bootloader/bootloader/firmware/pic32mz_ef_sk.X

   ) using the MPLAB X IDE.
4. Build the Live update application (path: `<Live Update application folder>/firmware/pic32mz_ef_sk.X`) using the MPLAB X IDE but do not program.
5. From the command prompt, run the bootloader host script btl_host.py available at `<Your Harmony Framework download folder>/bootloader/tools` to program the application binary.

       python <Your Harmony Framework download folder>/bootloader/tools/btl_host.py -v -s -i <COM
                 PORT> -d pic32mz -a 0x9D100000 -f <Live Update application
                 folder>/hex/pic32mz_ef_sk.X.production.bin

   Note: If the user needs to know more information on the bootloader host script, refer Help for setting up the host script available at

       <Your Harmony Framework download
             folder>/bootloader/doc/help_bootloader.chm

6. Following screenshot shows successful programming of the application binary.
7. The messages Swapping Bank And Rebooting and Reboot Done in below screenshot signifies that bootloading is successful.

## Running the Live Update Application

1. Perform Running the Bootloader application steps mentioned above, if not done already.
2. If the above step is successful, then LED1 or LED2 on the PIC32MZ Embedded Connectivity with FPU (EF) Starter Kit should start blinking which indicates the application is running from BANK 1 or BANK 2 based on from where the program is running.
3. Reset or Power cycle the device.
4. Run the host script live_update.py for live update application from command prompt available at `<Live Update application folder>/scripts` to program the new version of the firmware to an inactive panel while the current version of the application is being run from the active panel.

       python <Live Update application folder>/scripts/live_update.py -v -s -i <COM PORT> -d
                     pic32mz -a 0x9D100000 -f <Live Update application
                     folder>/hex/pic32mz_ef_sk.X.production.bin

   The following screenshot shows the Live update script help.
5. The following screenshot shows the example for output of successful firmware programming.
6. If the Live update is success then LED3 should turn ON.
   - This indicates that the Live update is successful.
7. In case of any error during the Live update i.e. in Step 4, the LED3 turns OFF. Follow the below steps recover from the error:
   - Press and hold the Switch SW1 to reset the system then repeat the step 4 to program the Live update application, or
   - Reset or Power cycle the device and repeat from the step 4 to program the Live update application
8. If the Live update is success then LED1 or LED2 should start blinking which indicates the application is running from BANK 1 or BANK 2 based on from where the program is running.
   - LED1 for BANK 1
   - LED2 for BANK 2
9. Reset or Power Cycle the device for the newly programmed application to run.
   - Observe the change in LED toggling compared to the LED which was toggling in the previous step. This indicates that the newly updated image is running properly.

## Comments

- Reference Application Note: Live Update application on PIC32MZ MCUs using MPLAB Harmony v3 (DS00003703).
- This application demo builds and works out of box by following the instructions above in Running the Demo section. If the user needs to enhance/customize this application demo, should use the MPLAB Harmony v3 Software framework. Refer links below to setup and build the applications using MPLAB Harmony.
  - How to Setup MPLAB Harmony v3 Software Development Framework (DS90003232).
  - How to Build an Application by Adding a New PLIB, Driver, or Middleware to an Existing MPLAB Harmony v3 Project (DS90003253).
  - MPLAB Harmony v3 is configurable through MPLAB Code Configurator (MCC). Refer to the below links for specific instructions to use MPLAB Harmony v3 with MCC.
    - Create a new MPLAB Harmony v3 project using MCC
    - Update and Configure an Existing MHC-based MPLAB Harmony v3 Project to MCC-based Project
    - Getting Started with MPLAB Harmony v3 Using MPLAB Code Configurator
    - MPLAB Code Configurator Content Manager for MPLAB Harmony v3 Projects