HAL UCPD How to Use

group UCPD_How_To_Use

How to use the UCPD HAL module driver

Usage

  1. Declare a hal_ucpd_handle_t handle structure. and initialize the UCPDx driver with an UCPD hardware instance by calling the HAL_UCPD_Init() . The UCPDx clock is enabled inside the HAL_UCPD_Init() if USE_HAL_UCPD_CLK_ENABLE_MODEL > HAL_CLK_ENABLE_NO.

  2. Initialize the UCPD low level resources by implementing the UCPD_MspInit API:

    • Enable the UCPDx interface clock (if not enabled in HAL_UCPD_Init() when UCPD_CLK_ENABLE_MODEL is set to CLK_ENABLE_NO)

    • UCPD pins configuration:

      • Enable the clock for the UCPD GPIOs

        • Configure UCPD pins as alternate function open-drain

      • NVIC configuration if you need to use interrupt process

        • Configure the UCPDx interrupt priority

        • Enable the NVIC UCPD IRQ Channel

      • DMA Configuration

        • Declare a hal_dma_handle_t handle structure for the transmit or receive channel

        • Enable the DMAx interface clock

        • Configure the DMA handle parameters

        • Configure the DMA Tx or Rx channel

        • Associate the initialized DMA handle to the hucpd DMA Tx or Rx handle

        • Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx or Rx channel

  3. Configure the ucpd_clk prescaler, half-bit clock, transition window clock, and inter-frame gap timer division ratios, as well as accepted ordered set types and CC line enabling by calling HAL_UCPD_SetConfig() .

  4. Configure and/or enable advanced static configuration features. For instance, HAL_UCPD_SetRxPreFilterSampling() , HAL_UCPD_EnableRxPreFilter() , HAL_UCPD_EnableWakeupMode() , etc. All these advanced configurations are optional (not mandatory), and can only be set before starting the driver with HAL_UCPD_Start() .

  5. End the static configuration and start the driver with HAL_UCPD_Start() .

  6. Apply any dynamic control and configuration function. For instance, HAL_UCPD_SetRole() , HAL_UCPD_SetRxMode() , HAL_UCPD_SetTxOrderedSet() , HAL_UCPD_ApplyTrimmingRp() , HAL_UCPD_ApplyTrimmingRd() , etc.

  7. For UCPD IO operations, one operation mode is available within this driver:

Callback registration

UCPD bus Acquire/Release