Link Search Menu Expand Document

Amazon Alexa Connect Kit (ACK) OTA Bootloader Application on SAM D21 Curiosity Nano

Download


Description:

The Application demonstrates the usage OTA upgrade feature on SAMD21 Curiosity Nano evaluation kit using Amazon Alexa connect kit(ACK) SDK. The communication between SAM D21 Curiosity Nano and ACK Module is through UART interface.

This following bullet points provides links to the detailed topics:

Modules/Technology Used:

  • Peripheral Modules
    • SERCOM
    • Systick
    • Port
    • NVMCTRL

Hardware Used:

Software/Tools Used:

This project has been verified to work with the following versions of software tools:

Refer Project Manifest present in harmony-manifest-success.yml under the project folder firmware/src/config/default

Because Microchip regularly update tools, occasionally issue(s) could be discovered while using the newer versions of the tools. If the project doesn’t seem to work and version incompatibility is suspected, It is recommended to double-check and use the same versions that the project was tested with. To download original version of MPLAB Harmony v3 packages, refer to document How to Use the MPLAB Harmony v3 Project Manifest Feature

Hardware Setup:

Hardware connections for Validation

  • Connect Pin “PB02(ACK HOST INTERRUPT Pin)” of SAM D21 Curiosity Nano Evaluation Kit to “INT”(INST) pin of ACK Module
  • Connect Pin “PB03(ACK MODULE RESET Pin)” of SAM D21 Curiosity Nano Evaluation Kit to “RESET”(RES) pin of ACK Module
  • Connect Pin “PA20(Host MCU TX)” of SAM D21 Curiosity Nano Evaluation Kit to “ACK RX” pin of ACK Module
  • Connect Pin “PA21(Host MCU RX)” of SAM D21 Curiosity Nano Evaluation Kit to “ACK TX” pin of ACK Module
  • Connect Pin “VTG(Voltage Target)” of SAM D21 Curiosity Nano Evaluation Kit to “IOREF” pin of ACK Module
  • Connect common ground between SAM D21 Curiosity Nano Evaluation Kit and ACK Module
  • Power the SAM D21 Curiosity Nano Evaluation Kit Evaluation Kit from a Host PC through a Type-A male to Micro-B USB cable connected to Micro-B port (J105)
  • Power the ACK Module from a Host PC through a Type-A male to Micro-B USB cable connected to Micro-B port (DEBUG)

Setting up the build platform

  • Download and extract ACK Device SDK 4.2 from Amazon developer website.
  • Copy and paste extracted SAM D21 ACK port folder “samd21_amazon_ack” into ACK device SDK’s user platform folder
    <Your ACK SDK Downloaded folder>/ACK_Device_SDK_4.2.202201251359/user/platform

Note

  • Make sure you create amazon.com account for downloading the SDK. You would use your Amazon credentials to register your development device (amazon.com account provides an option to register your development device.)
  • “ACK Module with Espressif chipset” is used in these demo’s. make sure you download proper ACK SDK from the Amazon website
  • Create Product and add device capablities to the product once product is created.
  • Download the product configuration file from created product and provision the Ack module using CLI command

Project file structure

  • ACK SDK file/directory structure, refer “Readme.txt” in
    <Your ACK SDK Downloaded folder>\ACK_Device_SDK_4.2.202201251359\
  • SAM D21 ACK port file/directory is as follows
    • user/platform/samd21_amazon_ack/
      • applications : Contains all the ACK host sample applications built on MPLABX Tools and xc32 compiler
      • bootloader : Contains bootloader for over-the-air(OTA) firmware upgrade feature
      • hmcu_port : Contains shared host specific platform and OTA files
      • ota : Contains OTA source, config and header files
      • ack_samd21_cutom_loader.c : Contains bootloader specific code
      • ack_samd21_platform.c : Contains SAMD21 platform specific code

Programming hex file:

The pre-built hex file can be programmed by following the below steps.

Steps to program the hex file

  • Open MPLAB X IDE
  • Close all existing projects in IDE, if any project is opened.
  • Go to File -> Import -> Hex/ELF File
  • In the “Import Image File” window, Step 1 - Create Prebuilt Project, Click the “Browse” button to select the prebuilt hex file.
  • Select Device has “ATSAMD21G17D”
  • Ensure the proper tool is selected under “Hardware Tool”
  • Click on Next button
  • In the “Import Image File” window, Step 2 - Select Project Name and Folder, select appropriate project name and folder
  • Click on Finish button
  • In MPLAB X IDE, click on “Make and Program Device” Button. The device gets programmed in sometime
  • Follow the steps in “Running the Demo” section below

OTA architecture

  • The SAM D21 Curiosity Nano Evaluation Kit has SAMD21G17D microcontroller mounted on it.
  • The SAMD21G17D has 128 KB of flash memory. For the implementation of OTA, the flash memory is divided into 4 sections/regions namely Bootloader, Status , Primary and Staging partition
    • Bootloader : This section starts from the top of the flash and has a size of 3KB. It is used to store the bootloader application. The bootloader checks whether a new version of the application firmware is present or not in the staging region. if present, the bootloader upgrades the application firmware from the staging region to primary memory region and runs the latest application firmware from the primary memory region; if not present, the bootloader runs the existing application firmware in the primary memory region.
    • Status : This section starts from end of the bootloader region and has a size of 1KB. It stores known pattern to indicate that a new version of application firmware is present in staging region.
    • Primary : It starts from end of the status region and has a size of 62KB. The primary region holds the application firmware.
    • Staging: It starts from end of the primary partition and has a size of 62KB. The staging region holds a new version of the application firmware which needs to be upgraded.

Setting up environment for OTA update

  • Open the project (samd21_amazon_ack\bootloader\firmware\sam_d21_cnano.X) in MPLAB X IDE
  • Build the code by clicking on the “Clean and Build project” button in MPLAB X IDE tool bar, but do not program
  • Open the project (samd21_amazon_ack/applications/HelloWorld/firmware/sam_d21_cnano.X) in MPLAB X IDE
  • Open the MPLAB Harmony 3 Configurator (MHC) from Tools > MPLAB Harmony 3 Configurator for HelloWorld project
  • After successful opening of MHC, in Project Graph select System and disable Generate Fuse Settings as shown below and generate the code
  • Change the memory configuration in project properties (Right click on HelloWorld_sam_d21_cnano project > select properties > select xc32-ld > Symbols & Macros)
  • Change the Preprocessor macro definitions as below to place the code in primary region
    ROM_ORIGIN=0x1000; ROM_LENGTH=0xF800
  • Define “ACK_HOST_FIRMWARE_UPDATE” in HelloWorld application file “ack_user_config.h”
  • Increase Memory pool size macro “ACK_MEMORY_POOL_SIZE” value to 684 in ack_user_configh.h
  • Build the code by clicking on the “Clean and Build project” button in MPLAB X IDE tool bar, but do not program.
  • Navigate to ota > utility folder inside ‘Your ACK SDK Downloaded folder’ and run “hexmerge.py” script to merge bootloader and HelloWorld project’s hex file

      python hexmerge.py -o bootloader_helloworld_combined.hex -f your_sdk_folder/user/platform/samd21_amazon_ack/bootloader/firmware/sam_d21_cnano.X/dist/default/production/sam_d21_cnano.X.production.hex your_sdk_folder/user/platform/samd21_amazon_ack/applications/HelloWorld/firmware/sam_d21_cnano.X/dist/default/production/sam_d21_cnano.X.production.hex
    
  • Program “bootloader_helloworld_combined.hex” to SAM D21 Curiosity Nano Evaluation Kit by following steps in Steps to program the hex file section.

Note

  • Output file “bootloader_helloworld_combined.hex” will be present in utility folder if specific path is not specified while running script.
  • The fuse settings are not programmable through firmware and enabling the fuse settings increases the size of the binary when generated through the Hex file, So disabling it.

Building and upgrading the latest application firmware

  • Open the project (samd21_amazon_ack/applications/HelloWorld/firmware/sam_d21_cnano.X) in MPLAB X IDE
  • Change the firmware version from 1 to 2 in “ACKUser_GetFirmwareVersion” function in file ‘ack_user_device.c’
  • Build the code by clicking on the “Clean and Build project” button in MPLAB X IDE tool bar, but do not program
  • Navigate to ota > utility folder inside ‘Your ACK SDK Downloaded folder’ and run “hex2ota.py” script to create a file suitable for uploading as latest application image from a hex file that was created by building the HelloWorld application.

      python hex2ota.py --device-type ACKTESTDEVICE <Your ACK SDK Downloaded folder>/user/platform/samd21_amazon_ack/applications/HelloWorld/firmware/sam_d21_cnano.X/dist/default/production/sam_d21_cnano.X.production.hex SecondOtaFirmware.ota
    
    • ”–device-type” : USER Device Type should be enterted, for example here it is used as “ACKTESTDEVICE”
  • Upgrade the firmware using amazon portal
  • once successfully completed, click on Switch SW0 on SAMD21 Curiosity Nano to reset the device.

Note

  • The Switch SW0 is implemented to reset the device on press.

Comments:

Revision:

  • v1.6.0 Regenerated and tested the application
  • v1.5.0 Updated to support Amazon ACK SDK 4.2 and ACK module with Espressif chipset
  • v1.4.0 Added MCC support, Regenerated and tested application.
  • v1.3.0 Updated to support Amazon ACK SDK 4.1
  • v1.2.0 Updated to support Amazon ACK SDK 3.2
  • v1.1.0 released demo application


Copyright © 2020 Microchip Technology.