/same51j20a-mdfu-host-i2c-mplab

MDFU host with I2C transport example on SAM E51 Curiosity Nano

Primary LanguageC

MDFU host with I2C transport example on SAM E51 Curiosity Nano

Description

This demo contains a MDFU host with I2C transport running on SAM E51 Curiosity Nano that updates the FW through a MDFU client running on AVR128DA48 Curiosity Nano. In addition, the documentation shows how to adapt this demo to work with MDFU clients running on other hardware or on the PC for testing.

Hardware

Software

  • MDFU client, either
    • MDFU client on AVR128DA48 Curiosity Nano
    • or as the pre-built artifacts avr128da48-mdfu-client-crc32.X.production.uf2for the MDFU client and avr128da48-application-image-crc32.imgas application image
  • IDE to build the MDFU host application. The project is set up for MPLABx and can also be imported in VS Code through the MPLAB Extensions
  • XC32 toolchain (tested with version 4.40)
  • Terminal application to see debug output or control the update (e.g. putty, minicom, Tera Term ...)

Setup

MDFU client running on AVR128DA48 Curiosity Nano

  1. Program MDFU Client:

    • Build the MDFU client and application update image following the procedure as described here or take a shortcut and use the pre-built files in the artifacts folder. These have been built as MDFU client and application with CRC32 checksum verification. To program the client drag and drop the avr128da48-mdfu-client-crc32.X.production.uf2 file from the artifacts folder to the Curiosity Nano disk drive.
  2. Connect SAM E51 Curiosity Nano to Host PC:

    • Use a USB cable to connect the SAM E51 Curiosity Nano Evaluation Kit to the Host PC. This connection is used for programming the MDFU host, receiving log messages, and controlling the MDFU host.
  3. Build MDFU Host Application:

    • Build the MDFU host application using MPLABx or use the pre-built sam_e51_cnano.X.production.hex file from the artifact folder.
  4. Program MDFU Host:

    • Program the MDFU host using MPLABx or MPLAB IPE with the pre-built artifact.
  5. Connect I2C and Power Pins:

    • Connect the I2C SDA and SCL pins between the SAM E51 Curiosity Nano and the AVR128DA48 Curiosity Nano.
    • Ensure pull-up resistors (e.g., 4.7 kOhm) are used on both SDA and SCL lines that are strong enough for 100 kHz bus clock speed. These must be added since both Curiosity Nano boards do not have these and internal pull-ups are too weak. One way to provide the pull ups is to use a Curiosity Nano base for Click boards and plug the SAME51 Curiosity Nano board in the socket.
    • Connect the GND and VCC pins between the two boards.
    • Disable the on-board power supply of the AVR128DA48 by connecting Pin 55 (VOFF) to Pin 52 (GND).
    • Ensure both boards are powered by the same power supply, with the SAM E51 Curiosity Nano providing power.

With the following configuration the two boards are connected through I2C, GND and VCC. The power supply on the AVR128DA48 Curiosity Nano is disabled and is powered by the SAM E51 Curiosity Nano. A USB cable connection to the SAM E51 Curiosity Nano is necessary for supplying power and controlling the demo.

SAM E51 Curiosity Nano AVR128DA48 Curiosity Nano Description
Pin 9 (PA12) Pin 9 (PC2) I2C SDA
Pin 10 (PA13) Pin 10 (PC3) I2C SCL
Pin 15 Pin 15 GND
Pin 55 (VOFF) to Pin 52 (GND) Disables on-board power supply
Pin 51 (VCC) Pin 51 (VCC) VCC

Running the Demo

  1. Make sure the LED on AVR128DA48 Curiosity Nano is steady on which indicates that it is in MDFU client mode. If the LED is blinking, the application is running and MDFU client mode needs to be activated. The activation can be done by pressing and holding the button on the board until the LED enters a steady on state. This procedure instructs the application to reset and then to activate the MDFU client during the boot process.
  2. Connect with a terminal program to the serial port of the SAM E51 Curiosity Nano (baudrate 115200) to start and observe the upgrade process. Type help command to get a list of commands. Use mdfu clientinfo to get the MDFU client information printed in the terminal. Start FW update by issuing mdfu update command. Alternatively push the button to start the upgrade process.

By default the debug output through the terminal is configured to be most verbose and can be changed by using the mdfu dlevel command e.g. to set info level send mdfu dlevel=info. Available verbosity settings are error, warning, info, debug.

Modifying the demo

Adding new FW update images

Place a FW update image into the src/fwimage folder and rename the file to appimage.img. If the image file name should be kept, update the file name in the src/fwimage/incbin.S file.

In this example the assembler directive incbin is used to include the FW update image file content into the MDFU host application. This directive may not be available in all compilers but should at least be present in GNU GCC based compilers like XC32, AVR XC8 etc.

Configure logging verbosity

In the main function the verbosity level is configured by calling the set_debug_level function. The default level is DEBUGLEVEL, which is the most verbose level, but this can be changed to any of the other levels that are defined in logging.h.

Porting to other platforms

For each new platform the following must be adjusted or re-implemented:

  • serial MAC layer (sercom_mac.c). This is the API for accessing a UART peripheral.
  • a timer (timeout.c and timeout.h). Implements a timer based on available timer peripheral. The timer should be able to support maximum MDFU timeouts while maintaining a short enough timebased to not affect performance.

These implementations should be checked if they match the requirements for a new platform

  • logging (logging.c, logging.h). Logging is configured to be active and print to stdout but other options might be more suitable on other platforms.
  • FW update image reader (image_reader.c). Reads FW image that is included through incbin assembler directive. On other platforms the image file might be added through other means or are located e.g. in external flash etc.

Revision:

  • 1.0.1
    • MDFU-13: On command retry do not re-use command package size for response size
    • MDFU-16: Write chunk command should not send empty data
    • MDFU-18: Project update to latest MCC components
    • MDFU-19: Do not report success for failed update when initiated through button
    • MDFU-15: UF2 artifact for MDFU host and updated artifacts for MDFU client (version 1.3.0 of the Github project)
  • 1.0.0 - Initial release