Skip to main content
Graduate
July 8, 2024
Question

USBPD with TCPP Package

  • July 8, 2024
  • 1 reply
  • 1185 views

Hi,

I´m using the TCPP package (inside CubeMX). For my application I also need an ADC channel on the same ADC1 as used by TCPP to measure the Bus voltage. But it seems, that I don´t get any result in my application (configured as DMA). Investigating the problem I was wondering, that the channel configured is not used by USBPD, because only the ADCx->DR is read. The channel defined in usbpd_ADC_SNK.h (#define TCPP01_PORT0_VSENSE_ADC_CHANNEL ADC_CHANNEL_2) is nowhere used in the code... ?

Any idea?

Best regards,

Achim

 

    This topic has been closed for replies.

    1 reply

    ST Employee
    July 9, 2024

    Hi AWack

    The Vbus voltage monitoring is already implemented and in the code and used for USBPD.

    You can re-use the function for your own needs.

    It is in the BSP_USBPD_PWR_VBUSGetVoltage function in the usbpd_pwr_user.c source. I copy it below.

    In this case (without BSP) we are not using DMA because we monitor only one channel in this application. So we only reference to TCPP01_PORT0_VSENSE_ADC_INSTANCE.

     

    __weak int32_t BSP_USBPD_PWR_VBUSGetVoltage(uint32_t Instance, uint32_t *pVoltage)
    {
      /* USER CODE BEGIN BSP_USBPD_PWR_VBUSGetVoltage */
     
      /* Check if instance is valid */
      int32_t ret = BSP_ERROR_NONE;
      if ((Instance >= USBPD_PWR_INSTANCES_NBR) || (NULL == pVoltage))
      {
        ret = BSP_ERROR_WRONG_PARAM;
        *pVoltage = 0;
      }
      else
      {
        uint32_t value;
    uint32_t vadc;
    uint32_t voltage;
        value = LL_ADC_REG_ReadConversionData12(TCPP01_PORT0_VSENSE_ADC_INSTANCE);
    vadc = (value * VDDA_APPLI) / ADC_FULL_SCALE;
        voltage = vadc * (USBPD_PWR_VSENSE_RA + USBPD_PWR_VSENSE_RB ) / USBPD_PWR_VSENSE_RB ;
        *pVoltage = voltage;
      }
      return ret;
      /* USER CODE END BSP_USBPD_PWR_VBUSGetVoltage */
    }
     
    I hope I answered your question,
    Best regards
    Pascal
     
    AWackAuthor
    Graduate
    July 9, 2024

    Hi Pascal,

    ok, I understand. But this means if I want to use DMA with my application i can just replace LL_ADC_REG_ReadConversionData12(TCPP01_PORT0_VSENSE_ADC_INSTANCE); with the DMA variable?

    Best regards,

    Achim

    ST Employee
    July 10, 2024

    Hi AWack

    I agree, this should work,

    Best regards

    Pascal