cancel
Showing results for 
Search instead for 
Did you mean: 

USB-PD: CubeMX missing code for SRC PDOs

DDeba.1
Associate III

Hi, 

I am using the STM32ubeMX v6.14.0 to generate a USB-PD DRP following the link below:

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

I noticed that when I set the CubeMX to have more than 1 PDO, say 7, the macros USBPD_MAX_NB_PDO and PORT0_NB_SOURCEPDO are correctly set to 7 but the USBPD_NbPDO[1] has a value of 1 and I see that only the first element of the PORT0_PDO_ListSRC array is populated. Moreover, I also noticed that the USBPD_PWR_IF_SetProfile function is fixed to get only the first PDO due to explicitly choosing PORT0_PDO_ListSRC[0]. 

Is this an issue in the cubeMX code generation? Also, I couldn't find anywhere where the PORT0_PDO_ListSRC (and the same way, PORT0_PDO_ListSNK) are iniitialized as in the usbpd_pdo_defs.h file, the externs are enabled and the initialization code is disabled through the #ifndef __USBPD_PWR_IF_C instruction. 

NB. Attached is the ioc file

3 REPLIES 3
FBL
ST Employee

Hi @DDeba.1 

>first element of the PORT0_PDO_ListSRC array is populated.

I'm not sure I get your point, checking usbpd_pdo_defs.h, I can find all PORT0_PDO_ListSNK and PORT0_PDO_ListSRC after configuring them in PDO source port0 in CubeMX.

FBL_0-1744133987313.png

 

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.


DDeba.1
Associate III

Hi @FBL

This might be an issue related to the same post in here:

https://community.st.com/t5/stm32-mcus-embedded-software/issue-with-macros-after-generating-code-using-stm32cubemx/m-p/790419#M61953

When I define the PDOs in the CubeMX, the PORT0_PDO_ListSNK and PORT0_PDO_ListSRC are present in the usbpd_pdo_defs.h but are disabled through the #ifndef __USBPD_PWR_IF_C as you can see in the image below (even though __USBPD_PWR_IF_C is defined in usbpd_pwr_if.c). 

 

DDeba1_0-1744182509913.png

 

 

Hi  @DDeba.1 

It is more likely some user implementation is missing while setting the required power profile:

Adding the following in usbpd_pwr_if.c private variables fixed the issue on my end.

extern USBPD_HandleTypeDef DPM_Ports[USBPD_PORT_COUNT];

Some examples using usb for data communication simply use it in usbpd_usb_if.c to start USB device and host stack. So, I'd rather say it depends on user implementation.

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.