cancel
Showing results for 
Search instead for 
Did you mean: 

How to Read Data Role on USB C

VH
Associate

Hello,

I am using the NUCLEO-G071RB and the X-NUCLEO-DRP1M1 with the X-CUBE TXPP Software Bundle.

I created my project via the instructions from https://wiki.st.com/stm32mcu/wiki/STM32StepByStep:Getting_started_with_USB-Power_Delivery_Dual_Role.

Everything works fine.

I have a case where my device is always a sink but has to change Data Role. Is there a way to read the data role via the stack? I know that there is a defualt power role, which basically sets the Data Role ( Sink = UFP). And if there is a Data Role Swap Request I could just chnge my variable.Depending ont he Data Role I need to set a ID.

But is there a "nicer" way to read the Data Role from the Stack?

Thanks in advance.

1 ACCEPTED SOLUTION

Accepted Solutions
Adam BERLINGER
ST Employee

Hello,

you should be able to extract the current data role from the variable DPM_Params[PortNum].PE_DataRole. Usually the PortNum is 0, unless you have multiple ports. This value is automatically updated by the stack.
The parent structure array (DPM_Params) is defined in usbpd_dpm_core.c file.

When the requested data role swap is finished (acknowledged by the other side), the USBPD_DPM_Notification (defined in usbpd_dpm_user.c) is called with value USBPD_NOTIFY_DATAROLESWAP_UFP or USBPD_NOTIFY_DATAROLESWAP_DFP, depending on the new role.

Best regards,
Adam Berlinger

View solution in original post

2 REPLIES 2
Roger SHIVELY
ST Employee

Hello @VH ,

There has been a case created to resolve this question and we will be reaching out to you directly.

Regards,
Roger

Adam BERLINGER
ST Employee

Hello,

you should be able to extract the current data role from the variable DPM_Params[PortNum].PE_DataRole. Usually the PortNum is 0, unless you have multiple ports. This value is automatically updated by the stack.
The parent structure array (DPM_Params) is defined in usbpd_dpm_core.c file.

When the requested data role swap is finished (acknowledged by the other side), the USBPD_DPM_Notification (defined in usbpd_dpm_user.c) is called with value USBPD_NOTIFY_DATAROLESWAP_UFP or USBPD_NOTIFY_DATAROLESWAP_DFP, depending on the new role.

Best regards,
Adam Berlinger