This is an example on how to use the MPLAB Code Configurator (MCC) generated code for configuring some basic Microchip Device Firmware Update (MDFU) bootloader solutions for PIC16F18446 Curiosity Nano Evaluation board.
The 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 PIC16F18446 Curiosity Nano development board 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
pyfwimagebuilder
command line interface to convert application hex file into application image - How to use
pymdfu
command line interface to update the application firmware
- PIC16F18446 Family Product Page
- 8-Bit MDFU Client v1.0.0 Release Note
- Getting Started Document, API Reference and Update Image Specification
- MPLAB® X IDE 6.20.0
- MPLAB® XC8 2.46.0
- MPLAB® Code Configurator (MCC) 5.5.1
- MPLAB® Code Configurator (MCC) Device Libraries PIC10 / PIC12 / PIC16 / PIC18 MCUs
- Python 3.8 or later
- pyfwimagebuilder v1.0.1.14
- pymdfu v1.0.1.5
- PIC16F18446 Curiosity Nano (DM164144)
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 projects are consistent with the options seen in this section.
Configuration Bits
- External Oscillator Selection bits: Oscillator not enabled
- Reset Oscillator Selection bits: HFINTOSC (1MHz)
Clock Control
- Clock Source: HFINTOSC
- HF Internal Clock: 4_MHz
For CRC16 and CRC32 the Clock is set to 32_MHz
- Clock Divider: 1
NVM
- Generate Flash APIs: Enabled
- Generate Device ID APIs: Enabled
UART
- Custom Name: UART1
- Requested Baudrate: 9600
- Calculated Baudrate: 9615
- Baud Rate Error (%): 0.16
- Parity: None
- Data Size: 8
- Stop Bits: 1
- Flow Control Mode: None
- Redirect Printf to UART: Disabled
- Interrupt Driven: Disabled
EUSART PLIB
- Actual Baud Rate: 9615.385
- Baud Rate Error (%): 0.16
- Receive Enable: Enabled
- Clock/Transmit Polarity: Non-Inverted
- Serial Port Enable: Enabled
- Transmit Enable: Enabled
UART Pins
- EUSART TX: RB4
- EUSART RX: RB6
8-Bit MDFU Client
- Communication Protocol: UART
- Application Start Address: Different for each project based on the verification selected
- Device ID: 0x30D4
- I/O Pin Indicator: Enabled
- I/O Pin Entry: Enabled
- Memory Verification: Assigned Based on Example Project Naming Convention
Example for Checksum Verification
8-Bit MDFU Client I/O
- BOOT INDICATE: RA2
- BOOT ENTRY: RC2
- BOOT INDICATE: Start High
- BOOT ENTRY: Weak Pullup
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 0xD00 then this value will reflect as
00-7FF,800-CFF
Clock And Configuration
- Set the clock and configuration bits to the same values that were set in the MDFU Client
IO Pins
- GPIO Output: RA2
- Custom Name: LED
Project Properties
Linker Additional Options
- Codeoffset: 0x<APP_START> = 0xD00
- Checksum: Dependant on the verification scheme
Check the table below to understand how the Checksum option must be configured in the application projects
Verification Scheme | Checksum Setting |
---|---|
Reset Vector | N/A |
Status Byte | N/A |
Checksum | D00-3FFD@3FFE,width=-2,algorithm=2,code=3F |
CRC-16 | D00-3FFD@3FFE,width=-2,algorithm=5,offset=FFFF,polynomial=1021,code=3F |
CRC-32 | E00-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
- Constant: 0x3FFF
- Increment/Decrement: No Incrementing
- Memory address range: 0x<APP_START>:0x<FLASH_END> = 0xD00:0x3FFF
In this section, we will walkthrough how to run the examples in this repository. This example shows how to execute the Checksum verification example and update the device Flash memory with the checksum application image to demonstrate a successful device firmware update (DFU).
8-Bit MDFU Client Operation
- Open the MDFU Client Project.
- Set MDFU Client Project as Main Project.
- Right click, then select Clean and Build.
- Program the MDFU Client Project.
Bootloader Operation after initial programming
After initial programming, the LED must be on.
Application Operation
- Open the Application Project that is configured for your selected verification scheme.
- Set the application project as the Main Project.
- Build the required Application project.
Right click, then select Clean and Build
- Build the Application Image File using pyfwimagebuilder.
Hint: The configuration TOML file is generated by the MDFU Client project.
Example Command:
pyfwimagebuilder build -i "application_hex_file.hex" -c "mdfu_config_file.toml" -o output.img
- 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 ./output.img --baudrate 9600 --port COM##
Application Has Been Updated Successfully
This repository demonstrates how to configure the 8-Bit MDFU Client library in MCC to enable device firmware updates over UART on a PIC16F18446 Curiosity Nano.