DEPRECTION NOTICE:This repo and associated examples are deprecated.

Please refer to the latest examples at:
https://github.com/microchip-pic-avr-examples/dspic33_dsc_bootloader_code_examples

Bootloader Example Using the CAN Physical Layer and TA100 ECDSA Verify

Introduction

This example shows how to use the pre-configured CAN demo on the dsPIC33CK256MP508 processor module for the Explorer 16/32 board with TA100 ECDSA signature verification to bootload an application via CAN. This demo uses the ISO 15765-2 CAN Transport Protocol layer to transport custom bootloader commands over the CAN bus as seen in the diagram below:

Tools

Software

  1. THIS PROJECT REQUIRES A NON PUBLIC COPY OF THE CRYPTOGRAPHIC AUTHENTICATION LIBRARY(CAL) FOR TA100 SUPPORT! CONTACT MICROCHIP TO OBTAIN A COPY. YOU MUST REQUEST VERSION CryptoAuthLib 3.3.2 or later
  2. The unzipped example project files, boot.X and app.X
  3. Microchip MPLAB® X version 5.50 or later
  4. Microchip MPLAB® XC16 C compiler version 1.70 or later
  5. Unified Bootloader Host Application v1.17.0 or later
  6. Microchip MPLAB® Code Configurator version v4.0.1 or later (optional – for code configuration)
  7. 16-bit Bootloader MCC module version 1.18.3 or later (optional – for code configuration)
  8. The drivers for the selected Peak CAN-FD protocol analyzer/protocol generator (available at https://www.peak-system.com/Home.59.0.html?&L=1)

Hardware

  1. Explorer 16/32 Demo board
  2. dsPIC33CK256MP508 Processor module
  3. A programmer/debugger of choice
  4. A Peak CAN protocol analyzer/protocol generator. A PCAN-USB FD was used for development of this demo (https://www.peak-system.com/PCAN-USB-FD.365.0.html?&L=1).
  5. A CAN cable
  6. A CAN-FD bus terminator (or modify the Peak analyzer per their user's guide for proper CAN-FD termination).
  7. An MCP2542 click board (https://www.mikroe.com/mcp2542-click) or another appropriate CAN-FD transceiver click board. It is important that this is just a transceiver and not a CAN-to-SPI/UART converter chip.
  8. A micro USB cable, a USB-Type C cable, or a 9v power adapter for the Explorer 16/32 (for powering the board).
  9. TA100 Trust Anchor external HSM 14-pin SOIC
  10. TA100 14-Pin SOIC CryptoAutomotive™ Socket Board

Running the Demo

Hardware Configuration

  1. With the Explorer 16/32 detached from any power source, programmer, or USB connection:
    1. Connect the dsPIC33CK256MP508 processor module into the socket on the Explorer 16/32 such that the notched edge is in the top left corner matching the silk screen on the Explorer 16/32
    2. Connect the TA100 14-Pin SOIC CryptoAutomotive™ Socket board into the mikroBUS™ A slot.
    3. Connect the MCP2542 daughter board into the mikroBUS™ B slot.
  2. Connect the programmer to the Explorer 16/32
  3. Connect the Peak analyzer/generator to your computer.
  4. Connect the Peak analyzer/generator to the MCP2543 daughter board with the CAN cable.
  5. Power the board using either USB cable or the 9 volt adapter plug.


Programming the Bootloader

  1. Open the boot.x project in MPLAB® X
  2. Copy and paste the TA100 support Cryptographic Authentication Llibrary(CAL) into the mcc_generated_files folder replacing all placeholder files within.


  3. Press the “Make and Program” button on the top bar.


  4. Select the appropriate programmer if prompted.
  5. The project should compile and program successfully.
  6. Verify the D3 LED is solid on the Explorer 16/32. This indicates the bootloader is running.

Building the Application

  1. Open the app.X project in MPLAB® X
  2. Press the “Clean and Build Project” button on the top bar. NOTE: Make sure not to hit the program button. This will program the application code over the bootloader that was just programmed.


  3. The project should compile cleanly. app.X/dist/default/production/app.X.production.hex should be generated.
  4. Verify that the D3 LED is still solid.
    1. If the D3 LED is blinking instead of D3 solid, then the application code was programmed instead of only compiled. Go back to the “Programming the Bootloader” stage and re-program the bootloader.

Loading the Application

  1. Open the Universal Bootloader Host Application tool (UBHA)


  2. Select the “PIC24/dsPIC” option from the “Device Architecture” selection drop down


  3. Select “CAN” from the protocol drop down selection box:


  4. Select the “Settings->CAN” option from the top menu


  5. Select the Peak protocol analyzer being used and the appropriate CAN configuration settings for this demo (listed below). When complete, press “Apply”:
    1. Nominal bit rate: 500 kbits/sec
    2. CAN-FD: enabled
    3. CAN-FD Data Length: 64 bytes
    4. Flexible Data Rate: Enabled
    5. Flexible Data Rate: 2Mbit/sec
    6. Message ID Format: Standard
    7. Host to device ID: 0xA1
    8. Device to host ID: 0xA2


  6. Press the “Read Device Settings” button.
    1. The Application start address and Application end address fields should have updated. If it did not or if you get a communication error, please go back to the “Programming the Bootloader” stage to make sure the bootloader was programmed correctly.


  7. Load the application hex file by selecting “File->Open/Load File (*.hex)”
    1. Select the file generated in the previous section: app.X/dist/default/production/app.X.production.hex


  8. Check the "Enable Self Verification After Program" checkbox


  9. Press “Program Device”. The application should program erase, program and perform a self verify using the TA100 for an ECDSA verify then read back verify correctly.
    1. After a few seconds, D3 should be blinking.


Known Limitations

Terminology

ISO 15765-2 / CAN-TP / ISO-TP

ISO 15765-2 is a transport protocol layer designed for usage with the CAN bus. The original CAN bus specification allows for up to 8 bytes of data to be in a single frame. Larger messages need to be fragmented into smaller frames for transmission on the CAN bus. ISO 15765-2 defines a protocol for fragmenting larger messages and sending them over the CAN bus. It also incorporates flexibility in handling the data transmission through the use of flow control packets to control the frequency of when packets arrive as well allowing to pause the transmission of a message until the receiver is ready to receive the message.

MCC

Microchip’s MPLAB® Code Configurator tool. This tool helps configure and generate source code for peripherals and libraries.

UBHA - Unified Bootloader Host Application

The PC application used to send the firmware update and verification commands from the PC to the board to complete the firmware update.

Trademarks

MPLAB® is a registered trademark of Microchip Technology Inc. All other trademarks are the property of their respective owner.