2020-08-26 03:01 AM
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:
/* 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 :
Note : I couldn't initialize the PDO's as stated in UM2552 page No. 21
Thanks & Regards
Himavanth
Solved! Go to Solution.
2020-09-02 05:45 AM
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 */
}
2020-09-02 06:23 AM
Thank you very much for your reply..... your reply helps us a lot.
please have a look at the sink trace when connected to source... seams to be everything proper(only need few changes to manage Power management part.).
Thanks & Regards
2020-09-07 05:58 AM
Hi Yohann,
please have a look at the fallowing.
if((_PowerProfileSelected >= *PWR_Port_PDO_Storage[PortNum].SourcePDO.NumberOfPDO))
{
return _ret;
}
if((0 == *PWR_Port_PDO_Storage[PortNum].SourcePDO.NumberOfPDO)){
return _ret;
}
after a lot of time spending in Debugging device I found _PowerProfileSelected initialized with DPM_Ports[PortNum].DPM_RDOPosition is always 0(which shouldn't be).
I feel DPM_Ports[PortNum].DPM_RDOPosition should be updated after each negotiation... please suggest me some code changes so that RDO position update each time after negotiation.
Thanks for your support in building and Initializing PDO's.
Thanks & regards
-Himavanth
2020-09-07 06:46 AM
Hello
You are right, as written in the demonstration, you should save the RDO position in the 'USBPD_DPM_EvaluateRequest' function like this:
USBPD_StatusTypeDef USBPD_DPM_EvaluateRequest(uint8_t PortNum, USBPD_CORE_PDO_Type_TypeDef *PtrPowerObject)
{
/* USER CODE BEGIN USBPD_DPM_EvaluateRequest */
USBPD_StatusTypeDef _retr = USBPD_REJECT;
USBPD_PDO_TypeDef pdo;
USBPD_SNKRDO_TypeDef rdo;
/* read the request value received */
rdo.d32 = DPM_Ports[PortNum].DPM_RcvRequestDOMsg;
/* Search PDO in Port Source PDO list, that corresponds to Position provided in Request RDO */
if (USBPD_PWR_IF_SearchRequestedPDO(PortNum, rdo.GenericRDO.ObjectPosition, &pdo.d32) == USBPD_OK)
{
/* Evaluate the request */
if(pdo.GenericPDO.PowerObject == USBPD_CORE_PDO_TYPE_FIXED)
{
if((rdo.FixedVariableRDO.OperatingCurrentIn10mAunits > pdo.SRCFixedPDO.MaxCurrentIn10mAunits)
|| (rdo.FixedVariableRDO.MaxOperatingCurrent10mAunits > pdo.SRCFixedPDO.MaxCurrentIn10mAunits))
{
/* Sink requests too much maximum operating current */
/* USBPD_DPM_EvaluateRequest: Sink requests too much maximum operating current */
_retr = USBPD_REJECT;
}
else
{
/* Save the power object */
*PtrPowerObject = pdo.GenericPDO.PowerObject;
/* Set RDO position in DPM port structure */
DPM_Ports[PortNum].DPM_RDOPosition = rdo.GenericRDO.ObjectPosition;
_retr = USBPD_ACCEPT;
}
}
}
return _retr;
/* USER CODE END USBPD_DPM_EvaluateRequest */
}
Yohann
2020-09-07 07:49 AM
Thank you Yohann!. that solves my issue with finding an appropriate position of PDO after negotiation.
After negotiation I found system Hard Resetting every time and finally I found Route cause is from the function attached below.
I found Status variable is USBPD_HR_STATUS_START_REQ which cause to Hard Reset. please tell us reasons to get system Hard Reset.
/**
* @brief Callback function called by PE layer when HardReset message received from PRL
* @param PortNum The current port number
* @param CurrentRole the current role
* @param Status status on hard reset event
* @retval None
*/
void USBPD_DPM_HardReset(uint8_t PortNum, USBPD_PortPowerRole_TypeDef CurrentRole, USBPD_HR_Status_TypeDef Status)
{
/* USER CODE BEGIN USBPD_DPM_HardReset */
switch (Status)
{
case USBPD_HR_STATUS_START_ACK:
case USBPD_HR_STATUS_START_REQ:
{
/* Reset the power supply */
USBPD_PWR_IF_VBUSDisable(PortNum);
break;
}
case USBPD_HR_STATUS_COMPLETED:
{
/* Reset the power supply */
USBPD_PWR_IF_VBUSEnable(PortNum);
break;
}
default:
break;
}
/* USER CODE END USBPD_DPM_HardReset */
}
Note: I couldn't find Hard Reset message from attached device.
2020-09-07 08:20 AM
Could you please provide a PD log? With DISCO?
2020-09-07 08:39 AM
Here is my PD log after I connect Disco board.
2020-09-07 09:03 AM
PDO4 is requested (15V) but after transition to this voltage, we should received a PS_RDY message but a detach is detected by the device.
Could you confirm that you are able to switch correctly to 15V?
2020-09-07 10:58 AM
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.
2020-09-07 11:10 PM
You can put a breakpoint in BSP_USBPD_PWR_VBUSGetVoltage and check the value of VBUS returned by this function.