Skip to content

GitHub Example for the 8bit MDFU Client Library using PIC18F56Q24 with a CNANO board.

License

Notifications You must be signed in to change notification settings

microchip-pic-avr-examples/pic18f56q24-cnano-8bit-mdfu-client-mplab-mcc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCHP

Getting Started With the 8-bit MDFU Client for PIC18F56Q24 using MPLAB® X

This is an example on how to use the MPLAB Code Configurator (MCC) generated code for configuring several basic Microchip Device Firmware Update (MDFU) bootloader solutions for the PIC18F56Q24 Curiosity Nano Evaluation Board.

The Microchip Device Firmware Update (MDFU) is a device firmware update ecosystem that uses a device agnostic host application to update the application firmware. The application image that is loaded into the host follows a custom file format that includes the device and application-specific parameters needed to perform the update. This repository provides the basic starting point to configure and customize the MCC Melody 8-Bit MDFU Client library on the PIC18F56Q24 Curiosity Nano Base for Click boards™ and also provides instructions for running the examples.

This example will demonstrate:

  • How to configure the 8-Bit MDFU Client library in MCC Melody for different verification schemes
  • How to create a simple Blinky LED application
  • How to use the pyfwimagebuilder command line interface to convert application hex file into the application image
  • How to use the pymdfu command line interface to update the application firmware

Related Documentation


Software Used


Hardware Used

PIC18F56Q24_CNano


Setup

MDFU Client and Application projects have to be configured according to Client Setup and Application Setup. The following project setup is the same for all the example project pairs. If something goes wrong while running these examples, confirm that the settings in the respective projects are consistent with the options seen in the following sections.

mdfu-builder

Configuration Bits

  • External Oscillator Selection bits: Oscillator not enabled
  • Reset Oscillator Selection bits: HFINTOSC with HFFRQ = 64 MHz and CDIV = 1:1

CFG

Clock Control

  • Clock Source: HFINTOSC
  • HF Internal Clock: 8_MHz
  • Clock Divider: 1

CLK

NVM

  • Generate Flash APIs: Enabled
  • Generate EEPROM APIs: Enabled
  • Generate Device ID APIs: Enabled

NVM

UART

  • Custom Name: UART2
  • Requested Baudrate: 9600
  • Parity: None
  • Data Size: 8
  • Stop Bits: 1
  • Flow Control Mode: None
  • Redirect Printf to UART: Disabled
  • Interrupt Driven: Disabled

UART

UART PLIB

  • Actual Baud Rate: 9615.385
  • Enable Receive: Enabled
  • Receive/Transmit Polarity: Non-Inverted
  • Enable UART: Enable
  • Enable Transmit: Enabled

UART_PLIB

UART Pins

  • UART TX: RB5
  • UART RX: RB4

UART_Pins

8-Bit MDFU Client

  • Communication Protocol: UART
  • Application Start Address: Different for each project based on the verification selected
  • Device ID: 0x7920
  • I/O Pin Indicator: Enabled
  • I/O Pin Entry: Enabled
  • Memory Verification: Assigned Based on Example Project Naming Convention

Tip: The easiest way to get the correct device ID is to connect your device and use the Refresh Debug Tool Status button on the Dashboard left panel in MPLAB X IDE. Upon clicking the button and selecting the correct PKOB Nano, in the Output window it prints out the device ID and other information.

Refresh Debug Tool Status

Example for CRC32 Verification

8-Bit MDFU Client I/O

  • BOOT INDICATE: RF2
  • BOOT ENTRY: RF3

IO-Pins

  • BOOT INDICATE: Start High
  • BOOT ENTRY: Weak Pullup

IO-Settings

Updating Application Start Address

This is an important step to ensure that the bootloader and application FLASH sections are configured to provide maximum space for the application while decreasing the bootloader section to be as close to the memory consumed by the bootloader code as possible.

  • At this point, as mentioned in the 8-Bit MDFU Client section, this depends on the verification method used in the project. Initially, configure the application start address to be closer to the MAXSIZE to allow sufficient memory for flashing the bootloader code. Do not exceed (MAXSIZE - 4) Max Boot Size

  • After a clean and build, the bytes of memory consumed by bootloader can be observed under the Memory Summary section in the Output window

Build Memory Consumption

  • Update the application start address to the start address of the next page in FLASH, following the memory allocation utilized by the bootloader code

  • Since in this example, the bootloader code consumes 0x168B bytes, the application start address can be configured to 0x2000

Updated Boot Size

  • After updating the application start address, final configurations must be as mentioned below

MDFU

8-Bit MDFU Client Project Properties

  • ROM Ranges: This option is configured based on the start address of the application
  • For example, if the application starts at 0x2000 then this value will reflect as 0-1FFF

IO-Settings


app-builder

I/O Pins

  • GPIO Output: RF2

app_io

  • Custom Name: LED

app_io_settings

Project Properties

Linker Additional Options

  • Codeoffset: 0x<APP_START> = 0x2000
  • Checksum: Dependant on the verification scheme

app_offset

Note:Check the table below to understand how the CRC32 option must be configured in the application projects

Verification Scheme Checksum Setting
Reset Vector N/A
Status Byte N/A
Checksum C00-3FFD@3FFE,width=-2,algorithm=2,code=3F
CRC-16 C00-3FFD@3FFE,width=-2,algorithm=5,offset=FFFF,polynomial=1021,code=3F
CRC-32 C00-3FFB@3FFC,width=-4,algorithm=-5,offset=FFFFFFFF,polynomial=04C11DB7,code=3F

Fill Flash Memory

  • Which area to fill: Provide Range to fill
  • How to fill it: Constant or incremental value
  • Sequence: 0xFFFF
  • Increment/Decrement: No Incrementing
  • Memory address range: 0x<APP_START>:0x<FLASH_END> = 0x2000:0xFFFF

app_fill

Operation

In this section, we will walkthrough how to run the examples in this repository. This example shows how to execute the CRC32 verification example and update the device Flash memory with the CRC32 application image to demonstrate a successful device firmware update (DFU).

8-Bit MDFU Client Operation

  1. Open the MDFU Client Project.

OpenMDFUProject

  1. Set MDFU Client Project as Main Project.

OpenMDFUProject

  1. Right click, then select Clean and Build.

CleanBuild

  1. Program the MDFU Client Project

ProgramMDFU

Bootloader Operation After Initial Programming

After the initial programming, the LED must be on.

MDFU_BootMode

Application Operation

  1. Open the Application Project that is configured for your selected verification scheme.

OpenAppProject

  1. Set the application project as the Main Project.

MainAppProject

  1. Build the required Application project.

Right click, then select Clean and Build

CleanBuild_App

  1. Build the Application Image File using pyfwimagebuilder.

Hint: The configuration TOML file is generated by the MDFU Client project under \mcc_generated_files\bootloader\configurations

Example Command:

pyfwimagebuilder build -i "application_hex_file.hex" -c "bootloader_configuration.toml" -o output.img

build_img

  1. Use the pymdfu host tool to transfer the application image file to the bootloader.

Hint: You can find the COM port of the MCU using the MPLAB Data Visualizer.

Example Command:

pymdfu update serial ./crc32.img --baudrate 9600 --port COM##

transfer_img

Application Has Been Updated Successfully

MDFU_AppMode

Summary

This repository demonstrates how to configure the 8-Bit MDFU Client library in MCC to enable device firmware updates over UART on a PIC18F56Q24 Curiosity Nano.

Contents