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;