PDStack Middleware Library 1.20
PDStack Middleware Library

The PDStack middleware implements state machines defined in the Universal Serial Bus Type-C Cable and Connector Specification and the Universal Serial Bus Power Delivery Specification. The middleware provides a set of Device Policy Manager (DPM) APIs through which the application can initialize, monitor and configure the middleware operation.

The PDStack middleware operates on the top of the USBPD driver included in the MTB PDL CAT2(mtb-pdl-cat2) Peripheral Driver Library

Features:

  1. Support Type-C port configuration and connection detection in the Sink, Source and Dual Role
  2. Support Extended Power Range (EPR) in Sink role.
  3. Support USBPD Communication with the following features:
    • USB PD revision 3.1 compliance
    • USB PD revision 2.0 compliance (backward compatibility)
    • Power contract negotiation in Sink Role
    • Ability to respond to SOP and SOP' messages to support designs with a Captive USB-C cable.
  4. Support configuration of the port roles and responses through the EZ-PD Configurator.
  5. Support Device Policy Manager APIs to initialize, configure, monitor and control the port operation; as well as to send/receive USBPD messages associated with Alternate Mode discovery, Authentication, Firmware update etc.

General Description

Include cy_pdstack_common.h, cy_pdstack_dpm.h, cy_pdstack_port_config.h to get access to all functions and other declarations in this library. See the Quick Start Guide to start using the PDStack.

Refer to the Supported Software and Tools section for compatibility information.

Refer to the Changelog section for change history.

PDStack operates on the top of the usbpd driver. The usbpd driver has some prerequisites for proper operation. Refer to the "USBPD (USB Power Delivery)" section of the MTB PDL CAT2(mtb-pdl-cat2) Peripheral Driver Library API Reference Manual. Also, refer to the Limitations and Restrictions section for the different PDStack middleware restrictions and limitations.

The PDStack Middleware is released in the form of pre-compiled libraries. The following library variants with different feature set to help limit the memory footprint of the stack in applications are released.

  1. pmg1_pd3_snk_lite - Library with support for USB Type-C sink operation and USB-PD Revision 3.1 messaging.
  2. pmg1_pd2_snk_lite - Library with support for USB Type-C sink operation and USB-PD Revision 2.0 messaging. Using this library will reduce the flash (code) memory usage by the application.
  3. pmg1_pd3_drp - Library with support for USB Type-C dual role operation and USB-PD Revision 3.1 messaging. This library can be used in any Power-Delivery application.
  4. pmg1_pd3_snk_epr - Library with support for USB Type-C sink Extended Power Range(EPR) operation and USB-PD Revision 3.1 messaging.

Quick Start Guide

PDStack middleware can be used in various Development Environments such as ModusToolbox, MBED, etc. Refer to the Supported Software and Tools section.

The below steps describe the simplest way of enabling the PDStack middleware in the application.

  1. Open/Create an application where to add PDStack function
  2. Add the PDStack middleware to your project. This quick start guide assumes that the environment is configured to use the MTB CAT2 Peripheral Driver Library(PDL) for development and the PDL is included in the project. If you are using the ModusToolbox development environment select the application in the Project Explorer window and select the PDStack Middleware in the Library Manager.
  3. Include cy_pdstack_common.h, cy_pdstack_dpm.h to get access to all functions and other declarations in this library.
    #include "cy_pdstack_common.h"
    #include "cy_pdstack_dpm.h"
  4. Define the following data structures required by the PDStack Middleware:
    • USB-C port configuration
      /*******************************************************************************
      * PD Port Configuration Structure Initialization
      *******************************************************************************/
      const cy_stc_pdstack_port_cfg_t mtb_usbpd_port0_pdstack_config =
      {
      .signature = 0x50445343, /* PDSC */
      .version = 0x0100, /* Configuration table version */
      .mfgLenInfo = 0x0D, /* Length of Manufacturer Information */
      .mfgVid = 0x04B4, /* Manufacturer Vendor ID */
      .mfgPid = 0xF501, /* Manufacturer Product ID */
      .mfgName = "Infineon", /* Manufacturer Name */
      .scedbEn = 0, /* SCEDB enable */
      .skedbEn = 1, /* SKEDB enable */
      .extSrcCap = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, /* SCEDB Configuration */
      .extSnkCap = {0xB4,0x04,0x01,0xF5,0x00,0x00,0x00,0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x0A,0x05,0x05,0x14,0x00,0x00,0x00}, /* SKEDB Configuration */
      .portRole = 0, /* Port role */
      .defPortRole = 0, /* Default port role */
      .curLevel = 2, /* Current level */
      .cableDiscCount = 0x14, /* Cable Discover count */
      .srcPdoFlags = {0x00,0x00}, /* Source PDO flags */
      .snkPdoFlags = {0x00,0x00}, /* Sink PDO flags */
      .drpToggleEn = 0, /* DRP toggle enable */
      .rpSupported = 0, /* Rp supported */
      .pdOpEn = 1, /* PD operation enable */
      .prefPwrRole = 0, /* Preferred Power role */
      .portDis = 0, /* Port disable */
      .cableDiscEn = 0, /* Cable Discovery Enable */
      .deadBatSupp = 1, /* Dead battery support */
      .errorRecoveryEn = 1, /* Error recovery enable */
      .accessoryEn = 1, /* Accessory mode enable */
      .rpDetachEn = 1, /* Rp detach enable */
      .vconnRetain = 0, /* VCONN retain */
      .frsConfig = 0, /* FRS configuration */
      .srcPdoCount = 0x00, /* Source PDO count */
      .defSrcPdoMask = 0x00, /* Default Source PDO mask */
      .snkPdoCount = 0x02, /* Sink PDO count */
      .defSnkPdoMask = 0x03, /* Default Sink PDO mask */
      .srcPdo = {}, /* Source PDO */
      .snkPdo = {0x0001905A,0x9A42305A}, /* Sink PDO */
      .snkPdoMinMaxCur = {0x005A,0x005A}, /* Sink PDO min/max current */
      .pdRevision = 0x00000002, /* PD Revision */
      };
    • Device Policy Manager parameters
      const cy_stc_pdstack_dpm_params_t pdstack_port0_dpm_params =
      {
      .dpmRpAudioAcc = CY_PD_RP_TERM_RP_CUR_DEF,
      .dpmDefCableCap = 300,
      .muxEnableDelayPeriod = 0,
      .typeCSnkWaitCapPeriod = 0,
      .defCur = 90
      };
    • Register application callback functions
      /*
      * Application callback functions for the DPM.
      */
      const cy_stc_pdstack_app_cbk_t appCallback =
      {
      app_event_handler,
      vconn_enable,
      vconn_disable,
      vconn_is_present,
      vbus_is_present,
      vbus_discharge_on,
      vbus_discharge_off,
      psnk_set_voltage,
      psnk_set_current,
      psnk_enable,
      psnk_disable,
      eval_src_cap,
      eval_dr_swap,
      eval_pr_swap,
      eval_vconn_swap,
      eval_vdm,
      vbus_get_value,
      };
      The PDStack library uses these set of callbacks registered by the application to perform board specific tasks such as turning the consumer power path ON/OFF, identifying the optimal source power profile to be used for charging etc. The library also provides notification of various connection and PD policy state changes, so that the rest of the system can be configured as required.
  5. Initialize the PDStack middleware once at the start:
    Cy_PdStack_Dpm_Init (&pdStackContext,
    &usbPdContext,
    &mtb_usbpd_port0_pdstack_config,
    (cy_stc_pdstack_app_cbk_t *)&appCallback,
    &pdstack_port0_dpm_params,
    &timerContext);
  6. Start the device policy manager operation.
    Cy_PdStack_Dpm_Start(&pdStackContext);
    This initializes the USB-PD block to detect Type-C connection state changes and USB-PD messages and notify the application through callback functions.
  7. Invoke Cy_PdStack_Dpm_Task function from the main processing loop of the application to handle the device policy tasks for each PD Port.
    Cy_PdStack_Dpm_Task(&pdStackContext);

Configuration Considerations

This section consists of instructions of how to configure, and use the PDStack Middleware in a design.

  1. After selecting the PDStack middleware through the library manager, the user can select the library variant by editing the Code Example Makefile:
    • Add 'PMG1_PD3_SNK_LITE' to the COMPONENTS for using the pmg1_pd3_snk_lite library
    • Add 'PMG1_PD2_SNK_LITE' to the COMPONENTS for using the pmg1_pd2_snk_lite library
    • Add 'PMG1_PD3_DRP' to the COMPONENTS for using the pmg1_pd3_drp library
    • Add 'PMG1_PD3_SNK_EPR' to the COMPONENTS for using the pmg1_pd3_snk_epr library
  2. Configure the USB-C port properties
    • The USB-C port properties are controlled with the cy_stc_pdstack_port_cfg_t structure. Please see its description to learn about the parameters and values.
    • Use the EZ-PD Configurator to configure the properties of the USB-C port including port role and the default response to various USB-PD messages. Refer to step 4 of the Quick Start Guide guide for the reference configuration data.

Refer to the Limitations and Restrictions for the existing restrictions.

Limitations and Restrictions

  1. The Extended Power Range (EPR) feature is supported only in the sink role.

Supported Software and Tools

This version of the PDStack Middleware was validated for the compatibility with the following software and tools:

Software and Tools Version
ModusToolbox Software Environment 2.4
mtb-pdl-cat2 1.5.0
GCC Compiler 9.3.1
IAR Compiler 8.42.2
Arm Compiler 6 6.13

Changelog

VersionChangesReason for Change
1.20 Added libraries for USB Type-C dual role and sink Extended Power Range (EPR) operation New feature Addition
Updated the library to work with RTOS New feature addition
Added APIs for changing source/sink pdo capabilities Feature Addition.
1.10 Updated Type-C Error Recovery period to 250 ms. PD compliance specification updates.
Updated the size of the status extended message to 7 bytes. PD compliance specification updates.
USBPD wakeup interrupt was incorrectly getting disabled as part of the Software timer operation. This has been corrected. Defect Fixes.
API description updated. Documentation update and clarification.
1.0 Initial Version

More Information

For more information, refer to the following documents:

Note
The links to the other software component's documentation (middleware and PDL) point to GitHub to the latest available version of the software. To get documentation of the specified version, download from GitHub and unzip the component archive. The documentation is available in the docs folder.