x-cube-tcpp
x-cube-tcpp copied to clipboard
The SNK choses the wrong source PDOs for its selection criteria.
Describe the set-up Standard Setup.
Describe the bug The SNK choses the wrong source PDO for its selection criteria. The observed behavior is the following. SRC offers PDOs 5V 3A 9V 2A
SNK has the following capabilities 5V 3A 9V 3A
As it is, given this scenario and the default selection criteria of PDO_SEL_METHOD_MAX_PWR, the SNK should choose the higher power option of 9V 2A and it should set the capability mismatch flag since the SNK can handle up to 3A@9V. What actually happens is 5V 3A is chosen. Additionally, using the STM32CubeMonitor you can't manually select 9V 2A due to the failed criteria causing the PDO to be rejected.
This is caused by mainly USBPD_DPM_SNK_EvaluateMatchWithSRCPDO which is found in the file usbpd_dpm_user.c. As an example lets examine the fixed PDO type evaluation.
case USBPD_CORE_PDO_TYPE_FIXED:
{
snkvoltage50mv = snkpdo.SNKFixedPDO.VoltageIn50mVunits;
snkopcurrent10ma = snkpdo.SNKFixedPDO.OperationalCurrentIn10mAunits;
/* Match if :
SNK Voltage = SRC Voltage
&&
SNK Op Current <= SRC Max Current
Requested Voltage : SNK Voltage
Requested Op Current : SNK Op Current
Requested Max Current : SNK Op Current
*/
if ( (snkvoltage50mv == srcvoltage50mv)
&&(snkopcurrent10ma <= srcmaxcurrent10ma))
{
currentrequestedpower = (snkvoltage50mv * snkopcurrent10ma) / 2; /* to get value in mw */
currentrequestedvoltage = snkvoltage50mv;
}
break;
}
Here a match is allowed only if snkopcurrent10ma <= srcmaxcurrent10ma. This criteria is incorrect for determining if this PDO should be selected. Just because the PDO does not offer the full current capabilities of the particular RDO does not mean it should not be chosen. It just means after it is chosen, the capability mismatch flag should be set. Also, the currentrequestedpower math needs to be updated. As part of this fix the current used in that equation needs to be updated to the minimum of snkopcurrent10ma and srcmaxcurrent10ma.
How To Reproduce Set your SRC PDO and your SNK RDOs as described above. In other words, set your RDOs so that the RDO that offers the higher power also has more current capability than its matching PDO. And the RDO that offers the lower power does not have a higher current capability than its matching PDO.
Additional context One possible solution is instead of rejecting based on the current capability mismatch, you set a flag based on that mismatch and pass it back to the calling function. This flag will be used to indicate a capability mismatch. And as stated above the current used in the power calculation needs to be the lower of the two currents.
Screenshots If applicable, add screenshots to help explain your problem.
Fixed and Variable PDOs should not be rejected based on current capability mismatch. Battery PDOs should not be rejected based on power mismatch. These criteria should only be used to set the capability mismatch flag. Not reject the PDO.