Skip to main content
DDeba.1
Associate III
March 21, 2025
Solved

USBPD possible bug in DPM_USER_Settings initialization from cubeMX

  • March 21, 2025
  • 1 reply
  • 553 views

Hi, 

I'm using the code generated by CubeMX ver 16.14.0 following the following link to develop a USBPD sink. 

https://wiki.stmicroelectronics.cn/stm32mcu/wiki/STM32StepByStep:Getting_started_with_USB-Power_Delivery_Dual_Role

I added an APDO to the PDO list but it is not working. I traced the issue to be coming from the USBPD_DPM_RequestMessageRequest function when it calculates the allowable power. It uses the DPM_SNKRequestedPower.MaxOperatingCurrentInmAunits found in the DPM_USER_Settings structure. The issue is that this value is not initialized. If I use the cubeMonitor-UCPD app, I can see that APDO is defined in the SINK capabilities tab, so the data is there somewhere. Additionally, if I press "SEND TO TARGET", the DPM_SNKRequestedPower.MaxOperatingCurrentInmAunits found in the DPM_USER_Settings is now correct. 

Is this an issue related to missing initialization in the code generated by the cubeMX which is leaving the DPM_USER_Settings to be not correctly initialized?

PS. Attached the IOC

Thanks

 

Edit: I confirmed that initialization is the issue as if I manually call the UpdateSNKPowerPort0 function during firmware initialization, everything works from the start. Is this the correct planned way? Should there be other code generated by the cubeMX?

Best answer by FBL

Hi @DDeba.1 

DPM_USER_Settings structure is intended to be initialized by user code rather than automatically by CubeMX. In the demo provided, MaxOperatingCurrentInmAunits is used in various functions to evaluate and request power capabilities : DPM_FindVoltageIndex, DPM_SNK_BuildRDOfromSelectedPDO and USBPD_DPM_SNK_EvaluateCapabilities. So, you should manually initialize the settings.

1 reply

FBLBest answer
Technical Moderator
April 22, 2025

Hi @DDeba.1 

DPM_USER_Settings structure is intended to be initialized by user code rather than automatically by CubeMX. In the demo provided, MaxOperatingCurrentInmAunits is used in various functions to evaluate and request power capabilities : DPM_FindVoltageIndex, DPM_SNK_BuildRDOfromSelectedPDO and USBPD_DPM_SNK_EvaluateCapabilities. So, you should manually initialize the settings.

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.Best regards,FBL