Skip to content

microchip-pic-avr-solutions/samd21-pdid-library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCHP

Getting Started With the SAMD21 PDID Library

Project Overview

The Program and Debug Interface Disable (PDID) is a security feature used in microcontrollers to prevent unauthorized access to the device's memory. Once activated, PDID restricts access to the reprogrammable Flash memory, making it only writable by coding, executing on the device itself. Attempts to read or reprogram the device through external interfaces, such as the debug port, will fail. This feature is designed to protect the microcontroller from external threats and unauthorized access to its memory and proprietary application firmware. This feature is leveraged to enhance security, particularly for boot processes.

Related Documentation

Software Used

Hardware Used

Devices Supported by the PDID Library

This feature is available only on select SAMD21 family devices and silicon revisions. Contact a local Microchip sales office for additional information on silicon availability.

Folder Structure and Contents

The following items are provided in the ATSAMD21 PDID library release:

  • pdid-example
    • atsamd21_cnano_sys_cmd_pdid.X
    • src
  • pdid-lib
    • samd21_pdid_lib.X.a
    • pdid_api.h
  • images
  • readme.md

How to Use the PDID Library in a User Application

The PDID script is available as a library (.a) to the user along with a header (.h) file. These are the steps to use this library in a user application:

  1. From the user application Project settings, navigate to Config:[user config name]>Libraries.

    Project Settings Button
    Project Settings 'Libraries' Option
  2. Select Add Library/Object File…

    'Add Library/Object File...' Button
  3. Locate the library (.a) file and select it. This example uses the ATSAMD21G17D and the library files have been moved to the src folder, so we will be selecting the file named samd21_pdid_lib.X.a.

    'samd21_pdid_lib.X.a' File Explorer
  4. Select Apply and OK to close out the project settings window.

  5. In the Projects window, right click Header Files folder and select the Add Existing Item… menu option.

    'Add Existing Item...' Button Option
  6. Locate the pdid_api.h file provided with the library and select it. In this example, the header file has been moved into the src folder.

    'pdid_api.h' File Explorer
  7. In the user application, include the header file using #include "pdid_api.h.

    Include library header
  8. Now add the PDID_Enable(); function call to the user application to enable PDID.

    Enable PDID

NOTE
If the user application uses the Watchdog Timer (WDT), ensure the period is greater than 16 ms to give it enough time to complete the PDID enabling process.

How to Run the Provided PDID Example Application

Example projects are provided to show how the PDID can be enabled from a command line using a simple Harmony system command project. Typing help will display the different commands available, including the pdid command which is used to enable the PDID.

Steps for running the PDID example application for the ATSAMD21G17D:

  1. Open a serial terminal connected to the device serial communication port with the following settings:

    • Speed: 115200
    • Data: 8 bits
    • Parity: none
    • Stop bits: 1 bit
  2. Download the PDID example application atsamd21_cnano_sys_cmd_pdid.

  3. Open the example application project in MPLAB® X.

  4. Program the device with the example application.

  5. Press 'Enter' when prompted to begin a command line session.

    Prompt: Sys_Cmd for PDID Test! Press 'Enter' to start command interaction...
  6. Enter help to see all the available commands or help pdid to see all the PDID test commands.

    Command list: pdid, status, reset, q, help
  7. Enter status to check the PDID status of the device. In this case, the status is 0x0 because PDID has not been enabled yet. This command has three possible outputs:

    • 0x0: PDID is NOT enabled
    • 0xa5: PDID is enabled
    • 0xbaad0003: PDID is not supported on this device
    PDID Status: 0x0
  8. Enter pdid to execute the PDID process.

  9. On successful PDID execution, the output will show PDID enabling succeeds, return: 0xa5. The status command will also return 0xa5, indicating that PDID is enabled.

    PDID enabling succeeds, return: 0xa5
    PDID Status: 0xa5
  10. Software reset or power cycle the device.

  11. The device can no longer be reprogrammed or debugged.

    TransferFault
    Failed to program the target device. Debugger coult not be started. Terminating debug session.

About

This repository contains the MPLAB® X project designed to showcase the PDID lib usage on the SAMD21 family.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages