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 a UCPD hardware instance by calling 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 processing

        • 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(), etc.

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

Callback registration

  • When the compilation flag USE_HAL_UCPD_REGISTER_CALLBACKS is set to 1, it allows the user to configure dynamically the driver callbacks instead of weak functions. Functions allow registering callbacks:

UCPD bus Acquire/Release

  • When the compilation flag USE_HAL_MUTEX is set to 1, it allows the user to acquire/reserve the UCPD bus for a transaction. The HAL Acquire/Release are based on the HAL OS abstraction layer:

  • When the compilation flag USE_HAL_MUTEX is set to 0 or not defined, HAL_UCPD_AcquireBus() / HAL_UCPD_ReleaseBus() are not available.