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 AVR128DA48 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 AVR128DA48 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 application image - How to use the
pymdfu
command line interface to update the application firmware.
- AVR128DA48 Family Product Page
- 8-Bit MDFU Client Getting Started
- 8-Bit MDFU Client v1.0.0-beta.1 Release Note
- 8-Bit MDFU Client v1.0.0-beta.1 API Documentation
- MPLAB X IDE 6.15.0
- MPLAB XC8 2.45.0
- MPLAB Code Configurator (MCC) 5.4.1
- MPLAB Code Configurator (MCC) Device Libraries AVR AND ATtiny MCUs
- Python 3.8 or later
- pyfwimagebuilder v1.0.1.14
- pymdfu v1.0.1.5
- AVR128DA48 Curiosity Nano (DM164151)
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.
Clock Control
- Prescaler enable: Disabled
- Internal Oscillator Frequency: 20_MHz
Configuration Bits
On Configuration Bits UI, configure the BOOT FUSE to an acceptable size. For example, if the Program Flash Memory size is 0x20000, then the BOOT FUSE for an AVR device with a page size of 512 would need to be 254 (1 less than the MAX). This will initialize the bootloader partition to be in the address range from 0x00 to 0x1FC00. This will leave one page in the CODE partition.
For AVR128DA48,
- BOOTSIZE: 254
NVM
- Generate Flash APIs: Enabled
- Generate EEPROM APIs: Enabled
- Generate Signature Row APIs: Enabled
UART
- Custom Name: UART2
- Requested Baudrate: 9600
- Calculated Baudrate: 9600
- Baud Rate Error (%): 0.00
- Parity: None
- Data Size: 8
- Stop Bits: 1
- Flow Control Mode: None
- Redirect Printf to UART: Disabled
- Interrupt Driven: Disabled
USART PLIB
- Enable UART Receiver: Enabled
- Enable UART transmitter: Enabled
UART Pins
- UART TX: RB5
- UART RX: RB4
8-Bit MDFU Client
- Communication Protocol: UART
- FUSE-BOOTSIZE: Different for each project based on the verification selected
- FUSE-CODESIZE: Different for each project based on the verification selected
- Device ID: 0x1E9708
- 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: RC6
- BOOT ENTRY: RC7
- BOOT INDICATE: Start High
- BOOT ENTRY: Weak Pullup
8-Bit MDFU Client Project Properties
Set the linker options to restrict the bootloader compilation to the BOOT partition. This step is different depending on the used compiler.
AVR-GCC:
When using the AVR-GCC compiler, open the project properties and apply the below settings avr-ld>Additional options>-Wl,--defsym,TEXT_REGION_LENGTH= Application Start Address
XC8:
When using the XC8 compiler, open the project properties and apply the below settings XC8 Linker>Additional options>Extra Linker Options>-Wl,--defsym,TEXT_REGION_LENGTH= Application Start Address
This value will be the same as it appeared in the MDFU Client UI.
I/O Pins
- GPIO Output: RC6
- Custom Name: LED
Project Properties
Linker Additional Options Linker Setting
This step is different depending on the used compiler.
AVR-GCC
-
When using the AVR-GCC compiler, open the project properties and apply the below settings
- avr-ld>Memory Settings>FLASH segment>{}.text=<{}{}Application Start Address_{}{}in_words>{}
- avr-ld>Additional Options=-Wl,-u,applicationFooter
Note: AVR-gcc accepts word addresses, so if it is set 0x4000 in the bootloader, it must be set to 0x2000 here.
XC8
-
When using the XC8 compiler, open the project properties and apply the below settings
- Linker>Additional Options>Extra Linker Options=-Ttext= -Wl,-u,applicationFooter
This value will be the same as it appeared in the bootloader UI.
- Compiler>Preprocessing and Messages. Check the Use CCI Syntax checkbox
End Application
- Open main.c and add logic inside while loop to toggle the onboard LED with a 200 ms rate:
while(1)
{
LED_Toggle();
DELAY_milliseconds(200);
} {code}
- Include the delay.h header file
- At the top of the main file before the main function, copy and paste the following code:
** Tip: The address presented below in the __at() is PROGMEM_SIZE - 2 since the hash size used is two bytes.
#include <stdint.h>
#ifdef __XC8__
#include <xc.h>
#endif
volatile const uint16_t
#ifdef __XC8__
__at(0x1FFFE)
#endif
applicationFooter __attribute__((used, section("application_footer"))) = 0xFFFF;
{code}
-
Create a new script file called postBuild.bat (for Windows) or postBuild.sh (for Mac or Linux).
-
The postBuild file can be created by right-clicking the project folder in the MPLAB X Projects tab and navigating to: New>Other...> Other>Empty File
-
Enter the name postBuild for File Name and add your required extension (.bat or .sh).
-
Click Finish
-
A new file named "postBuild.bat" or "postBuild.sh" will be displayed.
-
Copy the following lines into the script file: To Fill Unused Space:
hexmate r0-FFFFFFFF,%1 -O%1 -FILL=w1:0xFF@0x10000:0x1FFFF
To perform the calculation and store the result:
hexmate %1 -O%1 +-CK=10000-1FFFD@1FFFEg2w-2
-
Add the path to MPLAB X which contains hexmate application to the environment variable PATH.
Example path(default):
C:\Program Files\Microchip\MPLABX\v6.15\mplab_platform\bin
-
-
Compile the project
-
Running the postBuild script
Copy and paste the following command in command prompt: **postBuild${ShExtension} ${ImagePath}** Example path: ```.\postBuild.bat avr128da48-application-crc32.X.production.hex```
This section is a walkthrough on 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 the initial programming, the LED must be on.
Application Operation
- Open the Application Project that is configured for the 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.
Tip: 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.
Tip: The COM port of the MCU is found 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 AVR128DA48 Curiosity Nano.