Skip to main content
Cagatay
Associate II
February 28, 2023
Question

STM32G071 USB PD dual role port data disconnects when changing from sink to source

I am using STM32G071 for my USB PD application. I have one dual role port(default sink) and one sink port for charger. When I attach charger I change the role of drp from sink to source. But hub chip in the application gets disconnected when I change the role. It seems like when it changes to source mode it changes the data role from ufp do dfp as well. What should I do to prevent that?

void USBPD_DPM_UserCableDetection(uint8_t PortNum, USBPD_CAD_EVENT State)
{
/* USER CODE BEGIN USBPD_DPM_UserCableDetection */
	 switch(State)
	 {
	 case USBPD_CAD_EVENT_ATTACHED:
		 if(PortNum == 0){
			 HAL_GPIO_WritePin(CHG_EN_GPIO_Port, CHG_EN_Pin, 0);
		 }
		 if(PortNum == 1){
			 HAL_GPIO_WritePin(CHG_EN_GPIO_Port, CHG_EN_Pin, 1);
			 Ports[0].params->PE_PowerRole = USBPD_PORTPOWERROLE_SRC;
			 Ports[0].params->PE_DataRole = USBPD_PORTDATAROLE_UFP;
			 USBPDM1_AssertRp(0);
 
		 }
		 break;

This topic has been closed for replies.

4 replies

Nicolas P.
ST Employee
February 28, 2023

Hello @Çağatay Ertürk​ 

Have a look at this code on github here.

The first USB role depends on the power role at the attach. But then theses roles are independent later on.

You can do a power role switch without impacting the data role, using the USBPD_DPM_Notification function. Have a look at out wiki example.

To change the power role, you can use the function USBPD_DPM_RequestPowerRoleSwap.

And to change the data role, you can use the function USBPD_DPM_RequestDataRoleSwap.

Are you using the STM32CubeMonitor-UCPD, to get correspondance to the user manual of the stack like described here in the wiki ?

Regards,

Nicolas

Cagatay
CagatayAuthor
Associate II
February 28, 2023

When I use the functions you have mentioned, it gives me USBPD_ERROR status. Sometimes it gives USBPD_OK status but nothing changes for USBPD_DPM_RequestDataRoleSwap after asserting Rp with USBPDM1_AssertRp(0); function. If I try to use USBPD_DPM_RequestPowerRoleSwap function in user cable detection it gives USBPD_ERROR status as well.

HFISTM
ST Employee
March 1, 2023

Hello @Çağatay Ertürk​,

I understand that you don't have an UART set-up to output the trace, but I'm afraid we wont be able to provide a lot of help without a trace to understand what is happening inside the stack in your application.

Some remarks/questions:

Ports[0].params->PE_PowerRole is only a setup variable. Don't change it at runtime. If you change it from DRP to Source that mean you want to change your DRP application to be only a Source at runtime, which is not possible. It will stay a DRP, but can take the role of a source by calling USBPD_DPM_RequestPowerRoleSwap function, as Nicolas said.

Why are you calling USBPDM1_AssertRp before the power role swap request ? This wont work, this function is not meant to be called by the user code there. This is why you never see USBPD_NOTIFY_STATE_SNK_READY.

Could you try to just call USBPD_DPM_RequestPowerRoleSwap without changing some params structure or calling assertRp before ?

Please refer to the very end of the wiki, as stated by previous messages, for an example on how to request a power role swap.

Best regards