MPLAB® Harmony v2 Live Photoframe Tutorial

 Objective

MPLAB® Harmony is a flexible firmware development platform for PIC32 microcontrollers. This integrated software framework provides driver libraries and APIs that make it easier for you to use PIC32 peripherals (Timers, GPIO, UART, I2C, SPI, etc.). It also includes middleware libraries for USB (Host and Device), TCP/IP (Ethernet and Wi-Fi®), Graphics, Bluetooth, and others.

This tutorial shows you how to create a Live Photoframe from scratch, using MPLAB Harmony and the MPLAB Harmony Configurator (MHC). The project you create will run on the PIC32 Multimedia Expansion Board II (MEB II). This application performs the following tasks:

  • On the press of a button, capture the image which is displayed on the Graphical LCD and store it on the SD Card. You will use MHC to configure the:
    • Onboard camera module,
    • Graphical LCD module
    • SD Card module.
  • Host an onboard web server to display the photos (stored on the SD Card) on your computer's web browser.
    • The MEB II board connects to LAN via Ethernet.
    • You will use MHC to configure the Harmony TCP/IP stack.
  • Enable the board to display its IP address on the console.

Two Ways to Use This Tutorial

  1. Create the project from scratch.
    • Use the provided source files and step-by-step instructions below.
  2. Use the solution project as an example.
    • Just build the solution project and download it to the MEB II board to observe the expected behavior.

Lab Objectives

  1. Create an MPLAB X IDE Harmony project for a PIC32 microcontroller from scratch.
  2. Use the MHC to configure and generate Harmony code.
  3. Create new application states and variables for Harmony projects.
  4. Identify the proper place to add your own application code to the Harmony project.
  5. Demonstrate the use of Harmony peripheral libraries and drivers to control PIC32 peripherals (SPI, I2C, Camera, Timers etc.).

 Materials

Hardware Tools

Tool About Purchase
REALICE-50px.png
MPLAB® REAL ICE™
In-Circuit Emulator
PIC32MZ-EF-50px.png
PIC32MZ Embedded Connectivity with FPU
Starter Kit
PIC32-MEB2v5-50px.png
PIC32 Multimedia Expansion Board II (v5)
For PIC32 Starter Kits

It is not necessary to have an MPLAB Real ICE to program/debug the code. The PIC32MZ EF Starter Kit includes a PICkit on-board (PKOB) debugger. The PKOB debugger can be connected to a host PC through the USB mini-B connector on the PIC32MZ EF Starter Kit for programming/debugging (see the red cable in the Hardware Setup below).

In addition to the hardware shown above, you'll also need an Ethernet cable and two USB (mini-B) cables.

hw_setup.png

Software Tools

This project has been verified to work with the following versions of software tools:
MPLAB X IDE v3.40, MPLAB XC32 Compiler v1.42, MPLAB Harmony v2.01b

Because we regularly update our tools, occasionally you may discover an issue while using newer versions. If you suspect that to be the case, we recommend that you double-check using the same versions that the project was tested with.

Archived versions of our tools can be found on the following Microchip websites:
MPLAB Harmony (see "Archived Downloads" tab)
MPLAB X IDE and XC32 Compiler (see "Downloads Archive" tab)
Note that multiple versions of all these tools can co-exist on the same computer.

Tool About Installers
Installation
Instructions
Windows Linux Mac OSX
MPLAB® X
Integrated Development Environment
MPLAB® XC32
C/C++ Compiler
MPLAB® Harmony 1.xx
Integrated Software Framework

Overview

This lab application allows capturing an image using the camera module on the MEB-II board. The captured image is stored on an external SD Card. The external SD Card hosts a FAT32 file system. The captured image stored on the SD Card can be viewed as a slideshow on a web page hosted by the web server running on the development board.

The application runs a DHCP client on the target. The target board receives its IP address from the DHCP server which runs on the router to which the target is connected. The image format supported is BMP. The application also supports the plug and play feature for SD Card media.



APP_Tasks()

The live photo frame application runs as a single application task in the App_Tasks() function.

task_states.png
Click image to enlarge.

Application States

APP_Tasks handles the application related states and events.
The tasks sequentially progress through the following steps.

  1. Register an application callback with the filesystem service.
  2. Wait for the SD Card to be mounted.
  3. The application state moves to TCP/IP stack initialization once the SD Card is mounted.
  4. The application initializes the TCP/IP stack. Once the TCP/IP stack is ready, the application moves to the next state.
  5. Initialize and start the camera module.
  6. Check periodically for any change in the network. The application remains in this state unless
    • There is a removal of the SD Card or
    • The application switch is pressed to capture the image on the camera module.
  7. Capture image on camera module to SD Card on a "button press" event and get back to step 6.
state_machine.png
Click image to enlarge.

Lab Source Files and Solutions:

This ZIP file contains the completed solution project for this lab. It also contains the source files needed to perform the labs, as per the following step-by-step instructions (see the "Procedure" section on this page).

The contents of this ZIP file need to be placed in this folder:

<Harmony install path>/apps/training/middleware/
(example Harmony install path = c:/microchip/harmony/v2_01b)

If this is not done, MPLAB X IDE will not be able to find all source files for the lab solution and the solution project will not build successfully.


Extracting the ZIP file will create the following folders:

  • live_photoframe contains the lab folder live_photoframe_lab.
  • live_photoframe_lab contains the lab solution (in the firmware folder) and source files (in the dev_files folder).
  • dev_files contains application source files and other support files (if any) required to perform the lab (see "Procedure" section below).
  • firmware contains the completed lab solution project. It can be directly built and downloaded on the hardware to observe the expected behavior.

Procedure

All steps must be completed before you are ready to build, download, and run the application.

Lab Index

Step 1: Create Project and Configure the PIC32

  • Step 1.1 – Create an MPLAB Harmony Project
  • Step 1.2 – Select the Board Support Package (BSP)
  • Step 1.3 – Verify Configuration Bits are correct
  • Step 1.4 – Verify and Change Oscillator settings
  • Step 1.5 – Use the Graphical Pin Manager to manage the mapping of I/O Pins

Step 2: Configure TCP/IP Stack and Related Modules

  • Step 2.1 - Enable and configure the TCP/IP stack
  • Step 2.2 - Configure the Crypto library
  • Step 2.3 - Configure the File System Service
  • Step 2.4 - Enable the Internal Ethernet MAC driver
  • Step 2.5 - Pin Configurations for TCP/IP

Step 3: Configure the SD Card Driver, SPI Driver and File System

  • Step 3.1 - Enable and configure SD Card
  • Step 3.2 - Configure SPI driver
  • Step 3.3 - Verify and configure the SPI I/O pins

Step 4: Configure the Camera and Related Modules

  • Step 4.1 - Enable and configure Camera driver
  • Step 4.2 - Enable and configure OC driver
  • Step 4.3 - Configure I2C driver
  • Step 4.4 - Configure Change Notifications for the Camera module
  • Step 4.5 - Configure the pins used by the Camera module
  • Step 4.6 - Timer driver configuration for the Camera driver
  • Step 4.7 - Configure the peripheral clock for the Camera module
  • Step 4.8 - Configure the priorities for DMA and Change Notification

Step 5: Enable Graphics Library and Configure Graphics Controller

  • Step 5.1 - Enable Graphics library
  • Step 5.2 - Configure the Graphics controller

Step 6: Configure Console System Service and USB Library

  • Step 6.1 - Configure the Console System Service
  • Step 6.2 - Configuring the USB Library to support the Console System Service

Step 7: Generate Harmony Code

  • Step 7.1 - Generate Code from MHC configuration
  • Step 7.2 - Analyzing the files added after generation
  • Step 7.3 - Building the Project

Step 8: Include Application-Specific Source Code and Files

  • Step 8.1 - Adding application files
  • Step 8.2 - Modifying system_config.h
  • Step 8.3 - Configuring the application switch
  • Step 8.4 - Replacing the Camera driver in the Harmony framework
  • Step 8.5 - Adding the header file for I2C driver in static buffer model

Step 9: Review the Application Code

  • Step 9.1 - Analyzing application file app.h
  • Step 9.2 - Analyzing application file app.c

| Step 10: Debug Your Application

  • Step 10.1 - Pre-requisites for debugging the application
  • Step 10.2 - Debugging the application
  • Step 10.3 - Viewing images on a web-browser

 Results

You should be able to view the images that you captured using the camera module on your computer's screen using a web browser.

If the web page is not loading for the acquired IP address, verify that your PC is connected to the same router as the MEB II board.

 Analysis

In this tutorial, you developed a WEB enabled live photo frame that captured and stored the image on the camera module to an SD Card connected over an SPI interface. You used MHC to select the appropriate Board Support Package (BSP) and configured the clock system, TCP/IP stack, timer driver, camera driver, output compare driver, and file system. You configured an application switch to capture an image on a button press event.

 Conclusions

With this tutorial, we demonstrated how easy it is to add a web server and image capture functionality to your application. The lab shows how you can create complex applications that integrate various peripheral drivers, device drivers for Display, TCP/IP, File System, etc., through the use of MHC.

© 2024 Microchip Technology, Inc.
Notice: ARM and Cortex are the registered trademarks of ARM Limited in the EU and other countries.
Information contained on this site regarding device applications and the like is provided only for your convenience and may be superseded by updates. It is your responsibility to ensure that your application meets with your specifications. MICROCHIP MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY KIND WHETHER EXPRESS OR IMPLIED, WRITTEN OR ORAL, STATUTORY OR OTHERWISE, RELATED TO THE INFORMATION, INCLUDING BUT NOT LIMITED TO ITS CONDITION, QUALITY, PERFORMANCE, MERCHANTABILITY OR FITNESS FOR PURPOSE. Microchip disclaims all liability arising from this information and its use. Use of Microchip devices in life support and/or safety applications is entirely at the buyer's risk, and the buyer agrees to defend, indemnify and hold harmless Microchip from any and all damages, claims, suits, or expenses resulting from such use. No licenses are conveyed, implicitly or otherwise, under any Microchip intellectual property rights.