2023-02-28 04:15 AM
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;
2023-02-28 09:51 AM
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
2023-02-28 10:42 AM
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.
2023-02-28 10:44 AM
Also my notification function never gives USBPD_NOTIFY_STATE_SNK_READY event or I could not see it. I use normal debug I do not use STM32CubeMonitor-UCPD because my application does not have UART to trace feature.
2023-03-01 05:33 AM
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