Skip to main content
Visitor II
August 26, 2020
Solved

PDO initialization Problem

  • August 26, 2020
  • 15 replies
  • 6976 views

Hi STteam,

my name is Himavanth, working as an Embedded Engineer at Supralax Electronics Pvt.Ltd. please have a look at the problem.

@brief : We are working PD source solution(i.e. 60Watt (20V @ 3A max)) using STM32G081RBT6. We are taking USB-PD_Provider_1port as an Base reference project.

@Reference : I have gone through each and every line of UM2552 reference manual I found really good information to setup the USBPD stack.

@context:

  1. I am not able to find the PDO initialization Even for provided example (i.e USB-PD_Provider_1port )from the STM.
  2. I found the code template(attached below)regarding PDO definition and initialization of PDO. But I couldn't find any initialization process for PORT0_PDO_ListSRC(As control going to #ifndef __USBPD_PWR_IF_C loop not to else loop)

/* USER CODE BEGIN Header */
/**
 ******************************************************************************
 * @file usbpd_pdo_defs.h
 * @author MCD Application Team
 * @brief Header file for definition of PDO/APDO values for 2 ports(DRP/SNK) configuration
 ******************************************************************************
 *
 * Copyright (c) 2018 STMicroelectronics. All rights reserved.
 *
 * This software component is licensed by ST under Ultimate Liberty license
 * SLA0044, the "License"; You may not use this file except in compliance with
 * the License. You may obtain a copy of the License at:
 * www.st.com/SLA0044
 *
 ******************************************************************************
 */
/* USER CODE END Header */
 
#ifndef __USBPD_PDO_DEF_H_
#define __USBPD_PDO_DEF_H_
 
#ifdef __cplusplus
 extern "C" {
#endif 
 
/* Includes ------------------------------------------------------------------*/
 
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Define ------------------------------------------------------------------*/
 
/* USER CODE BEGIN Define */
 
/* USER CODE END Define */
 
/* Exported typedef ----------------------------------------------------------*/
 
/* USER CODE BEGIN typedef */
 
/**
 * @brief USBPD Port PDO Structure definition
 *
 */
 
/* USER CODE END typedef */
 
/* Exported define -----------------------------------------------------------*/
 
/* USER CODE BEGIN Exported_Define */
 
#define USBPD_CORE_PDO_SRC_FIXED_MAX_CURRENT 3
#define USBPD_CORE_PDO_SNK_FIXED_MAX_CURRENT 1500
 
/* USER CODE END Exported_Define */
 
/* Exported constants --------------------------------------------------------*/
 
/* USER CODE BEGIN constants */
 
/* USER CODE END constants */
 
/* Exported macro ------------------------------------------------------------*/
 
/* USER CODE BEGIN macro */
 
/* USER CODE END macro */
 
/* Exported variables --------------------------------------------------------*/
 
/* USER CODE BEGIN variables */
 
/* USER CODE END variables */
 
#ifndef __USBPD_PWR_IF_C
extern const uint32_t PORT0_PDO_ListSRC[USBPD_MAX_NB_PDO];
extern const uint32_t PORT0_PDO_ListSNK[USBPD_MAX_NB_PDO];
extern const uint32_t PORT1_PDO_ListSRC[USBPD_MAX_NB_PDO];
extern const uint32_t PORT1_PDO_ListSNK[USBPD_MAX_NB_PDO];
#else
/* Definition of Source PDO for Port 0 */
const uint32_t PORT0_PDO_ListSRC[USBPD_MAX_NB_PDO] =
{
 /* PDO 1 */
 (0x0201912CU),
 /* PDO 2 */
 (0x00000000U),
 /* PDO 3 */
 (0x00000000U),
 /* PDO 4 */
 (0x00000000U),
 /* PDO 5 */
 (0x00000000U),
 /* PDO 6 */
 (0x00000000U),
 /* PDO 7 */
 (0x00000000U)
};
 
/* Definition of Sink PDO for Port 0 */
const uint32_t PORT0_PDO_ListSNK[USBPD_MAX_NB_PDO] = 
{
 /* PDO 1 */
 (0x00000000U),
 /* PDO 2 */
 (0x00000000U),
 /* PDO 3 */
 (0x00000000U),
 /* PDO 4 */
 (0x00000000U),
 /* PDO 5 */
 (0x00000000U),
 /* PDO 6 */
 (0x00000000U),
 /* PDO 7 */
 (0x00000000U)
};
 
#endif
 
/* Exported functions --------------------------------------------------------*/
 
/* USER CODE BEGIN functions */
 
/* USER CODE END functions */
 
#ifdef __cplusplus
}
#endif
 
#endif /* __USBPD_PDO_DEF_H_ */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

@Quetions :

  1. I am not able to find the PDO initialization. please let me know How I can initialize the PDO's?
  2. I have gone through the numbered steps stated in UM2552 page No. 14. I compared with code from PD example code(USB-PD_Provider_1port ) I found step 2, 4 and 5 are initialized properly. Even I am done with changes mentioned in the UM2552 reference manual for step 3.
  3. I couldn't under stand how to initialize the USBPD_StatusTypeDef USBPD_PWR_IF_Init(void). please help me out to initialize the function stated above. please help me out to get out of this problem.

Note : I couldn't initialize the PDO's as stated in UM2552 page No. 21

Thanks & Regards

Himavanth

    This topic has been closed for replies.
    Best answer by Yohann M.

    I found 2 missing codes in your environment:

    (usbpd_dpm_user.c)
    USBPD_StatusTypeDef USBPD_DPM_UserInit(void)
    {
    /* USER CODE BEGIN USBPD_DPM_UserInit */
     /* PWR SET UP */
     if(USBPD_OK != USBPD_PWR_IF_Init())
     {
     return USBPD_ERROR;
     }
     return USBPD_OK;
    /* USER CODE END USBPD_DPM_UserInit */
    }
     
    (usbpd_pwr_if.c)
    USBPD_StatusTypeDef USBPD_PWR_IF_SearchRequestedPDO(uint8_t PortNum, uint32_t RdoPosition, uint32_t *Pdo)
    {
    /* USER CODE BEGIN USBPD_PWR_IF_SearchRequestedPDO */
     if((RdoPosition == 0) || (RdoPosition > *PWR_Port_PDO_Storage[PortNum].SourcePDO.NumberOfPDO))
     {
     /* Invalid PDO index */
     return USBPD_FAIL;
     }
     
     *Pdo = PWR_Port_PDO_Storage[PortNum].SourcePDO.ListOfPDO[RdoPosition - 1];
     return USBPD_OK;
    /* USER CODE END USBPD_PWR_IF_SearchRequestedPDO */
    }
     

    15 replies

    HGorl.1Author
    Visitor II
    September 7, 2020

    Yeah. I am able to get 15V properly. No issue at all.

    As I am using different Feed back values(RA and RB values) in currently using board....I suspect I used RA and RB values comes with BSP board...if This is an issue with please confirm with Yes.

    ST Employee
    September 8, 2020

    You can put a breakpoint in BSP_USBPD_PWR_VBUSGetVoltage and check the value of VBUS returned by this function.

    HGorl.1Author
    Visitor II
    September 8, 2020

    Hi Yohann,

    I've done with changes to ADC setting and started ADC conversion.

    I found Voltage is constant(i.e. 22968) throughout the operation and it's independent of the VBUS Voltage. after I digging deep more I found aADCxConvertedValues[1] is constant throughout the operation and is 4095(equal to full scale value, which shouldn't be 4095).

    uint32_t BSP_PWR_VBUSGetVoltage(uint32_t PortId)
    {
    /* USER CODE BEGIN BSP_PWR_VBUSGetVoltage */
    	 uint32_t voltage = 0;
     
    	 if (PortId == TYPE_C_PORT_1)
    	 {
    	 voltage = PWR_ConvertADCDataToVoltage(aADCxConvertedValues[1]);
    	 }
    	 else if (PortId == TYPE_C_PORT_2)
    	 {
    	 voltage = PWR_ConvertADCDataToVoltage(aADCxConvertedValues[0]);
    	 }
    	 return voltage;
    /* USER CODE END BSP_PWR_VBUSGetVoltage */
    }

    After this I've gone through code related to ADC, I couldn't fine anything suspicious. seems to be problem with ADC reading help me out to get out of the issue.

    Thanks & regards

    • Himavanth
    ST Employee
    September 9, 2020

    Dear Himavanth

    you configured only 2 channels in your code (VBUS1 on ADC_CHANNEL_9 then rank 0 of PWR_ConvertADCDataToVoltage and VBUS2 on ADC_CHANNEL_3 on rank2) but you still define a table of 4 elements in aADCxConvertedValues) Could you try to set the size of table at 2? When you start DMA with 2 values only.

    #define ADC_NUMBER_CHANNEL 2
    /* Variable containing ADC conversions results
     aADCxConvertedValues[0]: VSENSE_1
     aADCxConvertedValues[1]: VSENSE_2
    */
    static __IO uint16_t aADCxConvertedValues[ADC_NUMBER_CHANNEL] = {0};
    /**
     * @brief Start I/V sense on both Type-C ports.
     * @retval 0 success else fail
     */
    static uint8_t PWR_StartVBusSensing(void)
    {
     uint8_t ret = 0;
     
     /* Start ADCx conversions */
     if (HAL_ADC_Start_DMA(&hadc1, (uint32_t *)aADCxConvertedValues, ADC_NUMBER_CHANNEL) != HAL_OK) ret++;
     
     return ret;
    }

    Yohann

    HGorl.1Author
    Visitor II
    September 9, 2020

    Hi Yohann,

    I am able to get 15V across VBUS after I connect my Disco board to Source device, but the ADC reading value is 16125mV. I found ADC reading Error while reading High voltages(i.e. greater than 10V).

    please have a look at the fallowing USBPD log:

    0693W000003RBomQAG.png

    After some period of time(typically 10S) PD is Resetting automatically. I suspect that is because of ADC Error only, please suggest some changes to us so that we can get better accuracy.

    Note : after 10 seconds BSP_PWR_VBUSOff() automatically getting called.

    0693W000003RBuBQAW.png

    I have couple of questions for you, please don't hesitate to answer this.

    1. what is the VBUS voltage without cable connection(or before cable connection)?
    2. I am connected Vref+ to VDDA. if I use Vref+ externally, is that going to be reduce my ADC Error?

    Thanks & Regards

    -himavanth

    ST Employee
    September 9, 2020

    1- what is the VBUS voltage without cable connection(or before cable connection)?

    VBUS should be at 0V of course... SRC path should be disabled.

    2- I am connected Vref+ to VDDA. if I use Vref+ externally, is that going to be reduce my ADC Error?

    Internal VREF should be enough for the VBUS measurement. Voltage divider is it correct? What the resistors you put on your board (RA/RB)?

    For your test, you can keep the SRC PDO set to 5V and check that you are able to measure correctly 5V on your ADC channel.

    In the attached screenshot you put, I don't have a success of the negociation. SRC did not sent a PS_RDY, there is a detach before.

    Question: did you change the content of the function 'USBPD_PWR_IF_SetProfile'. Do you set correctly the VBUS value? The code I have is the default the 1st PDO set to 5V.

    Note: instead of doing a copy of our cubeMX, you can deliver a file automatically saved on your laptop (.cpd file) under c:\Users\your_login\AppData\Local\Temp\STM32CubeMonitor-UCPD\Acquisition\. (https://wiki.st.com/stm32mcu/wiki/USB_Power_Delivery_overview#Specific_tools)

    HGorl.1Author
    Visitor II
    September 9, 2020

    After changes to RA (RA 36000)and RB (RB 6040)values I can able read the some what accurate value. i.e. 15V VBUS as 14908mV. seems to be allowable.

    Even after this setting USBPD control getting to BSP_PWR_VBUSOff() each time after Power profile setting.

    I didn't made any changes to USBPD_PWR_IF_SetProfile.

    still the SRC did not sent a PS_RDY, there is a detach before.

    Thank you

    Visitor II
    October 3, 2020

    Hello,

    im trying hard to run the USB PD feature on the STM32L552CCT6 controller.

    So i rebuild the USB-PD_Consumer_1port example for the STM32L5 to my controller.

    All is the same, but when im trying to start and debug the program, the controller stucks after the initalization.

    I figured out that the last called function is the  USBPD_TRACE_Init(); in the usbpd_dpm_core.c file.

    After that the debugger lost the connection to the target and the program stucks. I have to erase the full chip to get the connection again.

    0693W000004Ia1MQAS.png

    I have really no idea whats going on.

    So my question is: Does anybody have an idea where the problem is?

    Thanks!

    ST Employee
    October 5, 2020

    Hello

    Could you please create a new thread for your question?

    Thanks

    Yohann