HAL UCPD Overview

Introducing UCPD

group UCPD_Introduction

Overview

The UCPD (USB Type-C Power Delivery) HAL driver provides a high-level interface to configure and control the UCPD peripheral for USB Type-C and USB Power Delivery communication on STM32 microcontrollers.

Key Features

  • USB Type-C Detection: Detects CC line voltage states for role determination (source/sink) and attachment detection

  • USB Power Delivery Protocol: Implements the physical layer for USB PD message transmission and reception using BMC (Biphase Mark Coding) encoding

  • DMA-Based Transfers: Supports DMA mode for efficient non-blocking message transmission and reception with minimal CPU overhead

  • Configurable Clocking: Provides flexible clock prescalers and dividers for ucpd_clk, half-bit clock, transition window, and inter-frame gap timing

  • Hardware CRC: Automatic CRC calculation and verification for USB PD messages

  • GoodCRC Handling: Hardware-assisted fast GoodCRC message transmission within the USB PD timing requirements

  • Ordered Set Detection: Configurable detection of SOP, SOP’, SOP’’, Hard Reset, Cable Reset, and other USB PD ordered sets

  • Callbacks and Interrupts: Event-driven architecture with callbacks for Tx/Rx completion, errors, Type-C events, and Fast Role Swap (FRS) detection

  • Low-Power Support: Wake-up mode for low-power operation with CC event detection

Typical Use Cases

  • USB Type-C source and sink devices (power adapters, battery chargers, laptops)

  • USB Power Delivery controllers for negotiating power contracts

  • USB Type-C Dual-Role Port (DRP) implementations

  • USB Type-C alternate mode support (DisplayPort, Thunderbolt, etc.)

  • Cable plug (VCONN-powered) USB PD communication

Module and files

The following diagram illustrates the UCPD module and its associated files.

Module and files diagram

Component diagram

The following diagram illustrates the software components involved in the UCPD module. It shows the interactions between the user application, HAL drivers, low-level drivers, and the hardware components.

@startuml
<style>
componentDiagram {
   arrow {
      FontSize 8
   }
}
</style>

title UCPD Software Component Diagram

package "HAL" {
    [HAL_SERVICE]
    [HAL_UCPD]
    [HAL_DMA]
}

package "Low Layer" {
    [LL_UCPD]
    [CMSIS]
    [UCPD Interrupt routine service]
    [DMA Interrupt routine service]
}

package "HW" {
    [STM32_HW]
}

[Appli] --> [HAL_UCPD] : HAL UCPD API
[Appli] <-- [HAL_UCPD] : UCPD callback
[HAL_UCPD] --> [LL_UCPD] : LL UCPD API
[HAL_UCPD] -r-> [HAL_DMA] : HAL HAL_DMA_StartPeriphXfer_Opt\nHAL_DMA_Abort_IT
[HAL_UCPD] -l-> [HAL_SERVICE] : HAL_GetTick
[HAL_UCPD] <-- [UCPD Interrupt routine service]
[HAL_UCPD] <-r- [HAL_DMA]:Half transfer complete\nTransfer complete\nError
[LL_UCPD] --> [CMSIS]:UCPD register def
[HAL_DMA] <-d- [DMA Interrupt routine service]
[STM32_HW] -u--> [UCPD Interrupt routine service]: UCPDx Irq
[STM32_HW] -u--> [DMA Interrupt routine service] : DMA Channel Irq
[STM32_HW] <-u-- [LL_UCPD] : UCPD registers R/W
@enduml

Configuration table

The following table lists the configuration defines for the HAL UCPD module, specifying their locations, default values, and descriptions:

group UCPD_Configuration_Table

UCPD driver configuration

Config defines

Where

Default value

Note

USE_HAL_UCPD_MODULE

hal_conf.h

1U

Enable HAL UCPD module

USE_HAL_UCPD_POWER_DELIVERY

hal_conf.h

1U

Enable the PD related functions in the driver

USE_HAL_UCPD_REGISTER_CALLBACKS

hal_conf.h

0U

Enable the register callbacks assert

USE_HAL_UCPD_CLK_ENABLE_MODEL

hal_conf.h

HAL_CLK_ENABLE_NO

Enable peripheral clock in the HAL_UCPD_Init

USE_HAL_UCPD_USER_DATA

hal_conf.h

0U

Add a user data inside HAL UCPD handle

USE_HAL_UCPD_GET_LAST_ERRORS

hal_conf.h

0U

Add error member inside HAL UCPD handle

USE_HAL_CHECK_PARAM

hal_conf.h

0U

Enable checking of vital parameters at runtime

USE_HAL_MUTEX

hal_conf.h

0U

Enable the use of semaphore in the HAL driver

USE_ASSERT_DBG_PARAM

PreProcessor env

NA

Enable the params assert

USE_ASSERT_DBG_STATE

PreProcessor env

NA

Enable the state assert